5 ms·
Render Multimedia in Pure C
- dingdingdang 9y agoReally great visualizations of search algorithms - would love to have brief description of technique used for actual graphics/audio output (only 600LOC but my C is craptastic so..)
- pjc50 9y ago> brief description of technique used for actual graphics/audio output That's most of the article. It can be found in the "frame" and "ppm_*" functions in the program. Nice clean classical C style there in my opinion.
- agumonkey 9y agoHis 2D structure with pipes makes me wanna write transforms in APL
- eggy 9y agoI was thinking of a similar thing, but in J [1]. J's library or routines (j.dll on windows), can be called easily from C. I am trying to establish a synthesis of my love for J programming with my C coding experience. [1] jsoftware.com
- kleiba 9y agoI'm amazed at how slow Quicksort appears in the sorting video.
- mmastrac 9y agoThis was one of the only ways to get video working easily 20 years ago. I remember piping ppm files into the Berkeley MPEG_ENCODE [1] and getting out a poorly encoded but animated raytracer output. [1] http://vis.lbl.gov/NERSC/HowTos/mpeg/help/tools/mpeg_encode.html http://vis.lbl.gov/NERSC/HowTos/mpeg/help/tools/mpeg_encode....
- majewsky 9y agoI did the same for my diploma thesis, where I simulated quantum waveforms on a small compute cluster. Each run would consist of about 30,000 separate simulations with initial conditions, and while they usually only output a few statistics each, there was a debugging switch which dumped the waveform as a PPM after every timestep, so that I could merge them all into a video and assess the quality of the simulation visually.
- pjc50 9y agoAh, raw PPM output. Reminds me of this which I wrote some years ago: #!/usr/bin/perl # Output is a PPM file : try snowflake | xloadimage stdin # see http://cam.pm.org/christmasppc-summary.shtml#Pete_Clay for explanation $w= 100 ;$w*=5; ;$W=$w* $w; q--; $p=atan2(1,0)* 2;3; @P= ("\000"x3)x( $W); BEGIN{$";sub S{$_.='fhoq' }sub K{$_.='s'.(( $n ++)) .(( '' .'' .'{' )) ;}; sub Y{$_ .= $_[0 ]}; S;K ;Y(''. '$k/=2;$'. '' .'l/=2}'); S;K;0; Y( '$k/=3;$l/=3;$k+=$j/4}fhoqh{'. '' .'cevq"P6\a$jq$j\a255\a",q@P}');S;K;Y('$g=$c/3;e}'); S;K; Y(q.$g=$. .'c/-3;' .'e}');S ;K;Y('$'. 'g'. '=' .'$c*2' .'/3}' );;s/v /vag/x; sub p{$P [$x+$w/2+ int($y)* $w+$W/2] ="\377"x3 }sub r{$z=$x*cos($t)+$y*sin($t);$y=$x*sin($t)-$y*cos($t); $x =$z};tr/a-z/n-za-m/;s/d/$"/gx; $x ++;$y= 4;eval$_}; s/ /japh/;sub T{;$a= $_[ 0]; ;$b= (( $a&( ($a |(+ $a <<1) )<< 1) )>> 2)|( $a >>3);if($b){ $_[0 ]=""}else{$_ [0]="f$a;p;" }};; for(1..20000 *10 ){$_ =int(rand(20)) ;T$_ ;0; eval$_} u#byPJC #JA PH# Ironically on the DOS systems (and early home computers) I learnt on it was really easy to display images from programs as the framebuffer was at a known memory address and you could just write to it. Windowing systems make that a bit harder, and very little of this is really portable.
- fb03 9y agoOn MS-DOS the FB was at $A000 and you could address it easily using stuff like mem[] in Pascal. I remember doing lots of animation and random graphics stuff in DOS using mode 13, the usual stuff at the time, plasma etc. 320 x 200 was more than enough for this kind of fun. Good times, simple times!
- userbinator 9y agoThose who find this interesting are recommended to look at the demoscene --- where realtime procedural graphics and music are the norm, and some groups have gotten very very good at it.
- porsupah 9y agoI'm returned to the heyday of Sorenson Video 3, Windows Media Video, and RealVideo. =:D Our application was used by most web video professionals at the time - go to a trailer on Apple's site, and it'd almost certainly have been produced by our work. All C, up to Media Cleaner Pro 4, migrating to C++ with Cleaner 5, with some Altivec (oh, what a joyous SIMD ISA) on the Mac side.
- Asooka 9y agoMight be a bit offtopic, but you can easily output audio and video at once and then mux them later on: ./yourprogram -a >(ffmpeg -f rawaudio ..other audio opts.. -i - ..encoding options.. audio.m4a) -v >(ffmpeg -f rawvideo ..video opts.. -i - ..encoding options.. video.m4v) ffmpeg -i audio.m4a -i video.m4v -c:a copy -c:v copy out.mp4 The >() syntax is a bash extension, supported also by zsh, and replaces the argument with a file path to a pipe that's connected to the process within the ()'s stdin. Similarly you can use <() to replace the arg with a pipe connected to the process's stdout. One thing I use it for sometimes is to compare directory contents: vimdiff <(ls -1 dir1 | cut -d/ -f2-)<(ls -1 dir2 | cut -d/ -f2-) There are better tools for this specific task, but for a quick and dirty compare on a machine where you only have vim and bash, it's hard to beat.