1

我正在从 mp2 解码视频并编码为 mp4。

原始文件:

Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p, 720x576 [SAR 64:45 DAR 16:9]

结果文件:

Video: mpeg4 (Simple Profile) (mp4v / 0x7634706D), yuv420p, 720x576 [SAR 1:1 DAR 5:4]

如您所见,分辨率没有改变,但纵横比发生了变化。

我的问题是如何设置这些值(SAR 和/或 DAR)?

4

2 回答 2

1

要设置输出纵横比,您可以使用 `-aspect' 选项,请参阅ffmpeg 文档

-aspect[:stream_specifier] aspect (output,per-stream)’

    Set the video display aspect ratio specified by aspect.

    aspect can be a floating point number string, or a string of the form num:den, where num and den are the numerator and denominator of the aspect ratio. For example "4:3", "16:9", "1.3333", and "1.7777" are valid argument values.

    If used together with ‘-vcodec copy’, it will affect the aspect ratio stored at container level, but not the aspect ratio stored in encoded frames, if it exists.
于 2013-08-22T10:56:59.253 回答
0

您可以在尝试添加新的视频流进行编码时设置纵横比。就在使用 avformat_new_stream() 添加新流之后。类似这样的东西。

AVOutputFormat *outfmt = NULL;
AVStream  *out_vid_strm;
AVCodec *out_vid_codec;
outformat = avformat_alloc_context();
if(outformat)
{
    PRINT_MSG("Got Output context ")
        outformat->oformat = outfmt;
    _snprintf(outformat->filename, sizeof(outformat->filename), "%s", (const char*)outfile);
    if(outfmt->video_codec != AV_CODEC_ID_NONE)
    {
        out_vid_codec = avcodec_find_encoder(outfmt->video_codec);
        if(NULL == out_vid_codec)
        {
            PRINT_MSG("Could Not Find Vid Encoder")
        }
        else
        {
            PRINT_MSG("Found Out Vid Encoder ")
                out_vid_strm = avformat_new_stream(outformat, out_vid_codec);
            if(NULL == out_vid_strm)
            {
                PRINT_MSG("Failed to Allocate Output Vid Strm ")
            }
            else
            {
                out_vid_strm->sample_aspect_ratio.den = 1;
                out_vid_strm->sample_aspect_ratio.num = 1;
                out_vid_strm->time_base.num = in_vid_strm->time_base.num;
                out_vid_strm->time_base.den = in_vid_strm->time_base.den;
                out_vid_strm->r_frame_rate.den = in_vid_strm->r_frame_rate.den;
                out_vid_strm->r_frame_rate.num = in_vid_strm->r_frame_rate.num;
            }
        }
    }
}
于 2013-08-22T11:26:41.237 回答