Click here to Skip to main content
15,887,404 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm a c programmer using code that calls routines like AVIStreamWrite(...) to output video to disk. It works just fine but is very slow.

On my computer (a surface pro 2) it takes between a third and two thirds of a second to compress and write a 1920 by 1080 32 bit frame, depending on the complexity of the image. That's using the Cinepack Codec by Radius, which is the only codec listed with AVISaveOptions(...) that gives good results, and that's at maximum quality, minimum compression.

At that rate, it's between ten and twenty seconds to output one second of video at 1080p, 30 fps. 10 minutes of video takes two or three hours to create.

So anyway the question is - is there any way to speed this up? For instance, can I add a faster modern codec, and if so how?

I'm sure my computer must have more modern codecs, but if so, AVISaveOptions doesn't seem to list them.
AVISaveOptions[^]

And - some time, I'd like to add a native mp4 save to my program, or .mov, but don't know how to do it. Would those be faster to save to disk than the .avi?

And any good libraries or similar I can use for those compatible with C? I can also add C++ code to my program. I found a library to export mp4s by Google Google Code Archive - Long-term storage for Google Code Project Hosting.[^] but it didn't have any example code to show how to make an mp4, just how to make an empty mp4 which is not much use - and from looking at the source, it didn't seem to have any routines that take bitmap frames as arguments, so not sure if it can do what is needed.

I'm still using MSVC 6.0 which sometimes limits what I can do though usually I find a work arounds, e.g. by dynamically linking to newer dlls. And prefer to write in low level C (which is why I like MSVC 6.0 in preference to newer versions), but I can add C++ if there is good example code to follow.

Just to be clear - since the bottleneck is exporting the video to disk - I don't need code to convert my exported avi to mp4. I can do that with mencoder, or else I use other programs to convert avi to mp4.

Also - I'm not interested in code to convert exported single frames or exported uncompressed avi. They take about as long to export as the compressed avi.

I'm looking for a way to export directly to some compressed format such as mp4 or avi from my program.

Since avi is just a container format, you can use many different encoders inside of it. And I think some of the modern encoders you can use with avi might work well, but for some reason AVISaveOptions doesn't seem to list them.

It's also commercial software so whatever I use has to be under a suitable license to use with commercial software (shareware). The program is [^] and I use it for making videos of the program to upload to youtube, and sometimes users of the program need to make videos of the rhythms also.

Thanks!
Posted

Unfortunately, Microsoft's support of different media containers and codecs has been notoriously poor, despite of relatively successful standards of WMA and WMV, which are still far from top-notch ones. I switched to 3rd-party and open source a long time ago and still think this is the best way.

I would strongly recommend open-source FFmpeg or libavcodec (the codec library FFMpeg is based on):
http://en.wikipedia.org/wiki/Ffmpeg[^],
http://ffmpeg.org/[^],
http://en.wikipedia.org/wiki/Libavcodec[^],
http://libav.org/[^].

AVI is badly obsolete, by the way. I was always happy with FFMpeg performance for most standards. These libraries do not depend on the codecs installed on the system; everything is bundled with the libraries.

—SA
 
Share this answer
 
Comments
Robert Inventor 2-Feb-16 8:02am    
Okay thanks, good thoughts.

I thought about ffmpeg but I can't find good documentation on how to use libavcodec. Plenty about how to use ffmpeg to convert videos from one format to another but that's not what I need.

Just to be clear - since the bottleneck is exporting the video to disk in the first place - I don't need code to convert my exported avi to mp4. I can do that with mencoder, or else I use other programs to convert avi to mp4.

Also - I'm not interested in code to convert exported single frames or exported uncompressed avi. They take about as long to export as the compressed avi.

I'm looking for a way to export directly to some compressed format such as mp4 or avi from my program.

Since avi is just a container format, you can use many different encoders inside of it. And I think some of the modern encoders you can use with avi might work well, but for some reason AVISaveOptions doesn't seem to list them.

It's also commercial software so whatever I use has to be under a suitable license to use with commercial software (shareware). The program is [^] and I use it for making videos of the program to upload to youtube, and sometimes users of the program need to make videos of the rhythms also.

Thanks for your help, any other thoughts (or anyone else got any ideas)?
Sergey Alexandrovich Kryukov 2-Feb-16 9:36am    
Yes, it was just my impression that you want to convert. :-( So, let me understand, from what kind of source and type of data do you need to compose video. You say that it's not even frames. Then what?
—SA
you can use LibVLC and its IMEM module
IMEM module acts like a media source and provides callback functions obtain frames from your app

transcoding requires one or more source media(s) and one or more destination media(s)
so ,in your case you want to encode frames to a media format ,
you will use IMEM as the source and do transcoding to a file with desired encoding

LibVLC has a good C API so its fine for your environment

here is a sample commandline
--sout #transcode{vcodec=h264,acodec=mp3,ab=128,channels=2,samplerate=44100}:std{access=file,mux=ts,dst=PATH_TO_MEDIA_FILE}

you can also specify an audio source during transcode operation , or you can add audio after you completed trancoding
here is a sample to get your started Using LibVLC IMEM[^]

even if that was a C++ sample ,you can easily implement it in C

the idea is basic , create a trancoding process and feed it with the video frames as RGB array or raw image data
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900