[Ffmpeg-devel] refactoring ffmpeg.c for shared library compatibility.

Jaime V. inf220
Sun Dec 17 11:48:20 CET 2006

I'd like to refactorize ffmpeg.c in order to write a function to 
initialize and teardown variables in it and need some help for it.
I willing to undertake the deed and maybe it can contribute this way to 
the project. :)

Frustrated by the common beginners difficulty of trying to use ffmpeg in 
a project to transcode some videos i came up with the idea of using the
already implemented ffmpeg.c as a library. This makes it easier for 
beginners to use ffmpeg from within existing projects or foreign 
environments such as MSVC. This also comes in handy when using own 

In order to be able to use it over different revisions i wrote a small
wrapper, that #includes the original ffmpeg.c and compiles a shared
library from it. So far i tested it under MinGW and Ubuntu Linux as its
the only systems i use(still quite new at linux dev though... but liking
it). It uses FFmpegs config.mak. so all you need is to unpack it into
the directory where the ffmpeg sources are and 'make' it. Attached is
also a small executable demo.

The biggest problem came when trying to use the function more than
First i removed the exit() command at the end... would it be possible to 
remove all exits() from ffmpeg? maybe replace with int return values. Id 
gladly take a shot on this. Im kinda new to linux development. It seems 
to me all it is used for is for one atexit() registered function...

Since the second time the variables are of course changed. Ffmpeg just 
crashed the second time i wanted to use it. So i wrote a resetdll()
function to reset the variables to their original state:

-First i tried writing functions, which recursively resets and av_frees
all structures within the variables by crawling into them and resetting 
them. This turned resulted into a 4kb mess of code and some freeing of 
data allocated by register_all().
-As of now i decided to go in steps by just trying to reset all local
variables to their initial state.(i reset most to NULL and free some now 
but want do do it properly later)

Unfortunalely this does not work quite right yet... as of revision 7203 
i was able to reuse the function. But the second time only the audio 
stream was opened and processed... Video stream was completely omitted.

Strangely though: If i ran the library under valgrind (trying to debug) 
it caused the second time to work properly: Video stream was processed 
as well. Running on its own it still has the same behavior... so i can 
not really debug(besides its a recursive hell there).

A few days ago i updated to r7316... which now kinda destroyed all my 
efforts as the second time ffmpeg just crashes and coredumps as soon as 
the file is being opened. I realized i cant do this on my own...
So maybe some of the people involved in ffmpeg.c could give me some 
directions? Like i said maybe i could refactor ffmpeg.c and include my 
reseter function.
If anybody could take a look into the attached ffmpeglib.c to check the 
reseterfunction it would be great.

Anybody just interested in this kind of undertaking is also welcome!

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: Howtouse.txt
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20061217/e88d2fc2/attachment.txt>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sharedffmpeglib.tar.gz
Type: application/gzip
Size: 4284 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20061217/e88d2fc2/attachment.bin>

More information about the ffmpeg-devel mailing list