如何使用libav将视频编码为符合dvd的mpeg2

时间:2014-07-18 11:06:33

标签: c++ video ffmpeg libav mpeg-2

我是使用FFMpeg的新手,我喜欢使用命令行选项-f dvd,但在我的应用程序中,使用libav api。在FFMpeg的源中,该选项将一些参数设置为

 opt_video_codec(o, "c:v", "mpeg2video");
 opt_audio_codec(o, "c:a", "ac3");
 parse_option(o, "f", "dvd", options);

 parse_option(o, "s", norm == PAL ? "720x576" : "720x480", options);
 parse_option(o, "r", frame_rates[norm], options);
 parse_option(o, "pix_fmt", "yuv420p", options);
 av_dict_set(&o->g->codec_opts, "g", norm == PAL ? "15" : "18", AV_DICT_DONT_OVERWRITE);

 av_dict_set(&o->g->codec_opts, "b:v", "6000000", AV_DICT_DONT_OVERWRITE);
 av_dict_set(&o->g->codec_opts, "maxrate", "9000000", AV_DICT_DONT_OVERWRITE);
 av_dict_set(&o->g->codec_opts, "minrate", "0", AV_DICT_DONT_OVERWRITE); // 1500000;
 av_dict_set(&o->g->codec_opts, "bufsize", "1835008", AV_DICT_DONT_OVERWRITE); // 224*1024*8;

 av_dict_set(&o->g->format_opts, "packetsize", "2048", AV_DICT_DONT_OVERWRITE);  // from www.mpucoder.com: DVD sectors contain 2048 bytes of data, this is also the size of one pack.
 av_dict_set(&o->g->format_opts, "muxrate", "10080000", AV_DICT_DONT_OVERWRITE); // from mplex project: data_rate = 1260000. mux_rate = data_rate * 8

 av_dict_set(&o->g->codec_opts, "b:a", "448000", AV_DICT_DONT_OVERWRITE);
 parse_option(o, "ar", "48000", options);

这些与libav api有何关系?

传入的视频帧在yuv420p格式下的正确分辨率为720x576。我的一些参数......

pCodec = avcodec_find_encoder(AV_CODEC_ID_MPEG2VIDEO);

pContext->bitrate = 48000000;
pContext->width = 720;
pContext->height = 576;

AVRational fps = {1,25};
pContext->time_base = fps;

pContext->gop_size = 15;
pContext->max_b_frmaes = 2;
pContext->pix_fmt = AV_PIX_FMT_YUV420P;

av_set_dict(&pDict,"packet_size","2048",0); // This seems to be ignored?

avcodec_open2(pContext,pCodec,&pDict);

The AVDictionary ...字典是什么?它与编码过程有什么关系?它只是一个用户字典,用于传递代码周围的设置集合吗?

最终,我希望能够对已经具有正确大小和格式的输入视频帧进行转码,并输出符合dvd标准的mpeg2视频(2048字节的数据包)。我理解mpeg2视频格式,但我对ffmpeg params感到困惑。

谢谢!

0 个答案:

没有答案