[Libav-user] Encoding DVDs

Nick Clarke nick.clarke at gmail.com
Fri Apr 1 16:05:41 CEST 2011

I am trying to encode a video to DVD spec using AVCodec, however it is
failing with a large number of Buffer Underflow errors, and the
resultant file has no video data.

I am assuming this is the result of one or more missing or incorrect
parameters, but can't work out which.

I have video:

AVCodecContext *codecContext;

videoStream = av_new_stream(outputContext, 0);

codecContext = videoStream->codec;

avcodec_get_context_defaults2(codecContext, CODEC_TYPE_VIDEO);
codecContext->codec_id = outputFormat->video_codec;
codecContext->codec_type = CODEC_TYPE_VIDEO;

codecContext->pix_fmt = PIX_FMT_YUV420P;
codecContext->bit_rate = bitRate;
codecContext->rc_max_rate = 9000000;
codecContext->width = GetWidth();
codecContext->height = GetHeight();
codecContext->time_base.num = frameRate.denominator;
codecContext->time_base.den = frameRate.numerator;
codecContext->gop_size = (frameRate == FrameRate::_25 ? 15 : 18);
codecContext->rc_buffer_size = 1835008;


AVCodecContext *context;
audioStream = av_new_stream(outputContext, 1);

context = audioStream->codec;

context->codec_type = CODEC_TYPE_AUDIO;

context->bit_rate = outputSampleRate * bitsPerSample;
context->sample_rate = outputSampleRate;
context->codec_id = outputFormat->audio_codec;
context->channels = numberOfChannels;
context->sample_fmt = SAMPLE_FMT_S16;


outputFormat = guess_format("dvd", NULL, NULL);
outputContext = av_alloc_format_context();

outputContext->oformat = outputFormat;
outputContext->mux_rate = 10080000;
outputContext->packet_size = 2048;

Then I'm calling avcodec_encode_video (and avcodec_encode_audio),
av_init_packet and av_interlevad_write_frame. My video and audio
frames are written in seperate functions, alternately.

The original data is 50Mbit Mpeg2 HD video, and PCM audio, which I'm
decoding and scaling before trying to encode. If I try and transcode
my test source file with the command line version of FFMpeg it works
fine, and I can write out my scaled images as raw bitmaps and they
look correct.

Any suggestions as to what I have done wrong?

Many thanks,


More information about the Libav-user mailing list