创建视频文件的精确副本[ffmpeg]

时间:2015-10-13 07:40:38

标签: video ffmpeg

我用ffmpeg的库编写了一些代码,它解码了视频文件的每一帧,对它进行了一些操作,最后编码并将帧复用到新容器。这一切都有效。 我试图在这里解决的问题是如何使输出文件具有精确的流设置作为输入文件。

如果我在我的文件上运行ffmpeg -i,我会得到关注 -
1)输入文件 -

Duration: 00:00:30.95, start: 0.000000, bitrate: 1195 kb/s
    Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv), 1280x720 [SAR 1:1 DAR 16:9], **996 kb/s**, 25 fps, 25 tbr, 25k tbn, **50 tbc (default)**
    <br>Metadata:
      creation_time   : 2015-09-30 06:33:24
      handler_name    : Mainconcept MP4 Video Media Handler
      encoder         : AVC Coding

2)输出文件 -

Duration: 00:00:30.96, start: 0.000000, bitrate: 1225 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], **1032 kb/s**, 25.03 fps, 25 tbr, 25k tbn, **100 tbc (default)**<br>
    Metadata:
      handler_name    : VideoHandler

3)如果我在上面的输出文件上再次运行我的代码以生成另一个输出文件,那么该文件看起来像这样 -

Duration: 00:00:30.96, start: 0.000000, bitrate: 1264 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], **1071 kb/s**, 25.03 fps, 25 tbr, 25k tbn, **200 tbc (default)**

请注意,每次运行我的代码时,比特率和TBC都​​会发生变化。

如何配置编码器使输出文件与输入文件相同?配置编码器的当前代码如下所示 -

    c = out_stream->codec;
    c->codec_id                = inputStream->codec->codec_id;
    c->bit_rate                = inputStream->codec->bit_rate;

    /* Resolution must be a multiple of two. */
    c->width                   = inputStream->codec->width;
    c->height                  = inputStream->codec->height;
    c->gop_size                = inputStream->codec->gop_size;

    c->time_base               = inputStream->codec->time_base;
    out_stream->time_base      = inputStream->time_base;

        av_stream_set_r_frame_rate(out_stream,av_stream_get_r_frame_rate(inputStream));
    out_stream->avg_frame_rate = inputStream->avg_frame_rate;

    c->pix_fmt                 = AV_PIX_FMT_YUV420P;
    c->sample_aspect_ratio.num = inputStream->codec->sample_aspect_ratio.num;
    c->sample_aspect_ratio.den = inputStream->codec->sample_aspect_ratio.den;
    c->ticks_per_frame         = inputStream->codec->ticks_per_frame;
    c->profile                 = inputStream->codec->profile;
    out_stream->duration       = inputStream->duration;

0 个答案:

没有答案