Echo/printf to write images in 5 LoC with zero libraries or headersnetpbm
vidarholen.net
vidarholen.net
fp = popen ("pnmtojpeg > output.jpg", "w");
fprintf (fp, "P3 %d %d 255", width, height);
/* print pixels as R G B triples */
pclose (fp);The other one I really like is Graphviz :)
How to create minimal music with code in any programming language
https://news.ycombinator.com/item?id=24940624
Basically pipe values into mplayer, etc.
These should go in my #shell-the-good-parts series, which is very backlogged...
https://www.oilshell.org/blog/tags.html?tag=shell-the-good-p...
No experience with the netpbm suite of tools, but ImageMagick (which TFA mentioned addition to netpbm) supports reading/writing any supported format on stdin/stdout, the skills of which I dare say are a bit more transferrable. A trivial example:
$ <my_image.ppm convert ppm:- jpeg:- | convert jpeg:- png:- >my_image.png && identify my_image.png
my_image.png PNG 250x250 250x250+0+0 8-bit sRGB 15836B 0.000u 0:00.000Anyway, if you like PPM, you may also like https://tools.suckless.org/farbfeld/ . The guys from suckless picked up the unix philosophy for simple file formats and pipes, cf. the examples https://tools.suckless.org/farbfeld/examples/
https://nullprogram.com/blog/2017/11/03/ https://nullprogram.com/blog/2020/06/29/
My go-to for uncompressed bitmaps is BMP, also trivial to read and write, and is easy to manipulate the image in memory with indexing operations.
Won the bet and promptly got kicked from the MUSH. Fun times.
I recall making pbms for my Data Structures class in the mid-90's. It is definitely a good target for budding programmers.
Is there a similar format for video, which can be generated on the fly without transcoding or invoking ffmpeg?
ffplay -f rawvideo -pixel_format rgb24 -video_size 42x42 -framerate 42 foo.raw
vlc --demux rawvideo --rawvid-fps 42 --rawvid-width 42 --rawvid-height 42 --rawvid-chroma=RV24 --rawvid-aspect-ratio 1:1 foo.raw
I experienced noticeable latency using ffplay so not great for real-time (multiple 100ms, upping the framerate to something like 100-200 reduces the latency but it's stupid). I have much better latency sending the frame data to a browser using websockets and displaying it in a canvas...Sources: https://ffmpeg.org/ffmpeg-formats.html#rawvideo https://forum.videolan.org/viewtopic.php?f=13&t=57938&p=1936... https://wiki.videolan.org/Chroma/
I've created renderers that do this. You can render out data as fast as your hard drive can write the data but yes these files are often ginormous. RGBA at 1000x1000 at 30FPS is about 7.2Gb per min.
There are raw file formats but because the files are so large they are normally thought of as streaming formats that you would pipe to another process like ffmpeg or gstreamer. If you actually want something saved to disk that other things can read your options are normally MJPEG, APNG, WebM or GIF. Some of the older video formats like AVI or MPEG might also work.
Personally I think animated PNG files are the cleanest simplest format internally, there are arrays of RGBA pixels that are gzipped plus the header data. Because the pixel data is compressed the files are smaller but still huge in comparison to a normal video file.
The answer to your question is also pretty complicated because most of these formats have many different formats that they internally allow, for instance MPEG, AVI and other video formats can be saved with pixel data in different formats. The problem is the specs for these things are often not fully supported by all of the players. To get useable files you will need to be specific about what you are trying to target. The formats that I normally target need to work in a web browser but if you just need it to work on your computer VLC can play almost anything.