Basic FFmpeg Hacking

A few more people have expressed interest in writing file demuxers and audio/video decoders for the FFmpeg project. I present herewith a brief guide to creating both demuxers and decoders for that project.

Start with the demuxer:

  • copy one of the simpler formats (libavformat/idcin.c or idroq.c) to a new file and start modifying the key parts
  • edit libavformat/allformats.c and libavformat/avformat.h and add the proper _init() function
  • edit libavformat/Makefile and add the new file to the end of the OBJS list

You should be able to build the new demuxer module into the project now. Check ‘ffmpeg -formats’ to make sure. You can use printf()’s or gdb along with the ffmpeg for debugging.

Next is the video decoder:

  • copy one of the simpler video decoders (libavcodec/msrle.c or msvideo1.c) to a new file and start modifying the key parts
  • edit libavcodec/avcodec.h and add a new CODEC_ID; also add the new data structure declared at the end of the new file
  • edit libavcodec/allcodecs.c and add the new data structure there as well
  • edit libavcodec/Makefile and add the new file to the end of the OBJS list

It helps to recompile the entire project after adding a new CODEC_ID just to make sure it “takes”. ‘ffmpeg -formats’ should now report the new format. Proceed with development and debugging. Note that in libavcodec, printf()s are forbidden. Use av_log(NULL, AV_LOG_INFO, …) instead.

2 thoughts on “Basic FFmpeg Hacking

  1. Kostya

    I’ve wanted to write something similar, but also with tips how to use VLC readers and when use get_buffer() or reget_buffer() and initialize frame info. But I’m lazy too ;)

  2. Multimedia Mike Post author

    I would love to know how to use get_buffer() and reget_buffer(). I have always been too lazy to read up on their proper use. :)

Comments are closed.