开发者

Writing uncompressed AVI video

Is there any simple开发者_如何学运维 and small library or code sample to write uncompressed avi video files in c++?

Every resource I find uses video for windows, and I need this to be portable.

I tried looking at the AVI container documentation but it looks really cumbersome.


I haven't done it myself but I suggest using libavformat, part of ffmpeg (LGPLv2.1/GPLv2+).


If you want something that is super easy, then write the BMPs to disk as a numbered sequence, then invoke ffmpeg via system() or something similar like this:

ffmpeg -i picture_%04d.bmp -r 15 -vcodec rawvideo -y output.avi

Note: the -r argument indicates the frame rate you want the final movie to be.

You could achieve the same result by calling into the libavformat/libavcodec libs that ffmpeg is based on, but that may not fit the "small" and "simple" requirement you have.


There is always OpenCV, which is multiplatform and relatively easy to push data into.

OR - you can always pipe the video data to another executable.

For instance, in unix you can do:

In your program:

char myimage[640*480*4];
// read data into myimage
fputs(myimage,1,640*480*4,stdout);

And in a script that runs your program:

./myprogram | \
mencoder /dev/stdin -demuxer rawvideo -rawvideo w=640:h=480:fps=30:format=rgba \
-ovc lavc -lavcopts vcodec=mpeg4:vbitrate=9000000 \
-oac copy -o output.avi

(Note that this does compress the video - uncompressed is just a matter of changing the mencoder command-line)

I believe you can also use ffmpeg this way, or x264. You can also start the encoder from within your program, and write to a pipe (making the whole process as simple if you were using a library) - and this should work on Windows, Linux or Mac (with minor modifications to the mencoder command-line).

Obviously there are no licensing issues either (apart from distribution of the mencoder executable), as you are not linking to any code or compiling anything in.

While not quite what you want, it does have the advantage that a second processor will automatically be used for the encoding.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜