FFmpeg demuxer HOWTO
- please make this page more complete if you can, thanks
registering the demuxer
libavformat/allformats.c
Add for a demuxer:
REGISTER_DEMUXER(DEMUXERNAME, demuxername)
For a muxer:
REGISTER_MUXER(MUXERNAME, muxername)
The macro will add the _demuxer or whatever is appropriate. Run configure in the top level directory and make clean, as config.h will be automatically modified.
make distclean ./configure make
libavformat/Makefile
Add
OBJS-$(CONFIG_DEMUXERNAME_DEMUXER) += filename.o
demuxer code
This section is merely an overview; please look at an actual demuxer to see how to do it.
demuxername_probe
The probe will be called by the framework; this is where you can detect if the file is your format. There should be no dependence on filename, in fact you probably can't even access it. Most video containers start with some constant sequence of bytes. If there are 4 bytes and they are always the same, and unique, then return AVPROBE_SCORE_MAX. Otherwise, return 0. If the format is mis-designed and doesn't have this, divide AVPROBE_SCORE_MAX by something (e.g. 2) to designate limited confidence that the file corresponds to your demuxer.
demuxername_read_header
Here you should get any header information, e.g. the frame width if it is video, the sample rate if it is audio, etc. You should also setup your streams (looking at examples usually explains most things, except perhaps timestamp information); set codec_type, codec_id, and possibly width, height, pix_fmt for video, and channels, sample_rate, bits_per_sample, and bit_rate for audio. return 0.
demuxername_read_packet
Most formats are split into blocks of audio and video. The read_packet function should set up pkt. This involves initializing the packet with av_new_packet, or, preferably, av_get_packet (which also takes the file stream as an argument). After you initialize the packet, you should set (in any order) pos and data (if you used av_new_packet), stream_index (to set which decoder, usually audio or video, to send the packet to, which corresponds to the order you initialized them in), and pts, the presentation timestamp.