使用ffmpeg转码,输出文件丢帧,fps会突然下降

mkv源文件是从这里下载的:Sample mkv Video

使用的命令是:

ffmpeg -i input.mkv -c:v libx264 -crf 20 -preset ultrafast -c:a aac -ar 22050 -y output.flv

转码后的输出文件,在第4秒时会跳帧,然后FPS从20多突然下降到5-6左右.
我找了很多mkv文件,发现就是从上面这个网站上下载的mkv转码结果有问题。
大伙儿帮我看看是什么原因呢?

图片描述

我用ffprobe获取了源文件的信息:

{
    "streams": [
        {
            "index": 0,
            "codec_name": "h264",
            "codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",
            "profile": "Main",
            "codec_type": "video",
            "codec_time_base": "1/50",
            "codec_tag_string": "[0][0][0][0]",
            "codec_tag": "0x0000",
            "width": 320,
            "height": 240,
            "coded_width": 320,
            "coded_height": 240,
            "has_b_frames": 0,
            "sample_aspect_ratio": "1:1",
            "display_aspect_ratio": "4:3",
            "pix_fmt": "yuv420p",
            "level": 20,
            "chroma_location": "left",
            "refs": 1,
            "is_avc": "true",
            "nal_length_size": "4",
            "r_frame_rate": "25/1",
            "avg_frame_rate": "25/1",
            "time_base": "1/1000",
            "duration_ts": 21573,
            "duration": "21.573000",
            "bits_per_raw_sample": "8",
            "disposition": {
                "default": 1,
                "dub": 0,
                "original": 0,
                "comment": 0,
                "lyrics": 0,
                "karaoke": 0,
                "forced": 0,
                "hearing_impaired": 0,
                "visual_impaired": 0,
                "clean_effects": 0,
                "attached_pic": 0
            }
        },
        {
            "index": 1,
            "codec_name": "aac",
            "codec_long_name": "AAC (Advanced Audio Coding)",
            "profile": "LC",
            "codec_type": "audio",
            "codec_time_base": "1/48000",
            "codec_tag_string": "[0][0][0][0]",
            "codec_tag": "0x0000",
            "sample_fmt": "fltp",
            "sample_rate": "48000",
            "channels": 6,
            "channel_layout": "5.1",
            "bits_per_sample": 0,
            "r_frame_rate": "0/0",
            "avg_frame_rate": "0/0",
            "time_base": "1/1000",
            "duration_ts": 21573,
            "duration": "21.573000",
            "disposition": {
                "default": 1,
                "dub": 0,
                "original": 0,
                "comment": 0,
                "lyrics": 0,
                "karaoke": 0,
                "forced": 0,
                "hearing_impaired": 0,
                "visual_impaired": 0,
                "clean_effects": 0,
                "attached_pic": 0
            }
        }
    ],
    "format": {
        "filename": "big_buck_bunny_240p_2mb.mkv",
        "nb_streams": 2,
        "nb_programs": 0,
        "format_name": "matroska,webm",
        "format_long_name": "Matroska / WebM",
        "duration": "21.573000",
        "size": "2098346",
        "bit_rate": "778137",
        "probe_score": 100,
        "tags": {
            "ENCODER": "Lavf53.24.2"
        }
    }
}
阅读 12.7k
1 个回答

应该是音频编码代来的,把音频去掉没有问题,你所用的音频编码参数采样率与原采样率不匹配,相差太大了,可以用44100,这样与48000相差不多,音视频同步时就可以和原来的差别不大了,视频也不会像原来播放时fps变慢了。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进