[FFmpeg-devel] Writing a "null" bitstreamfilter

John Lange john
Wed Mar 25 16:21:28 CET 2009


Ultimately my goal is to write an h264 bitstream filter that adjusts the
"level". To familiarize myself with concepts my first step was to create
a "null" filter. In other words, just copy the input to the output
making no changes.

Below is the code I came up with and it seems to work just fine but I
wanted to submit it here to see if there are any comments before
continuing on with the next steps.

To be honest, there is still lots about even this simple code that I
don't fully grasp yet for example the FF_INPUT_BUFFER_PADDING_SIZE and
some other things.

I also am still sceptical that a bitstream filter is even the write
place to make this work? Looking at the output of ffmpeg, it processes
the video header information including the "level" of the h264 stream
before it ever starts copying the raw video.

And it's only the raw-video which is sent to the bistream filter right?
Would the filter ever even "see" the headers where the level is set?

Anyhow, here is the code. I'm sorry if the formatting sucks; is it
better to include attachments?

----- code -----


#include "avcodec.h"

static int h264_level(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args,
                     uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size, int keyframe){

    if (avctx->codec_id != CODEC_ID_H264) {
        av_log(avctx, AV_LOG_ERROR, "h264level bitstream filter only applies to h264 codec\n");
        return 0;
    }

    *poutbuf_size = buf_size;
    *poutbuf = av_malloc(*poutbuf_size + FF_INPUT_BUFFER_PADDING_SIZE);
    memcpy(*poutbuf, buf, buf_size);

    return 1;
}

AVBitStreamFilter h264_level_bsf={
    "h264_level",
    0,
    h264_level,
};



-- 
John Lange
http://www.johnlange.ca





More information about the ffmpeg-devel mailing list