从 mkv 转换为 mp4 后,FFMPEG 音频/视频不同步

从 mkv 转换为 mp4 后,FFMPEG 音频/视频不同步

因此,在我将 mkv 文件转换为 mp4 后,音频会在正确的时间播放,但视频会提前结束。这意味着视频的起始位已被切断,因此视频会在较晚的帧开始播放,而在结束时,视频仍停留在同一帧,导致音频/视频不同步的问题……我该如何解决这个问题?这是我的命令:

ffmpeg -i "input.mkv" -codec copy -ss 00:15:20 -t 00:00:17 "output.mp4"

输出结果如下:

ffmpeg version N-88804-g3af2bf0af0 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 7.2.0 (GCC)
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-cuda --enable-cuvid --enable-d3d11va --enable-nvenc --enable-dxva2 --enable-avisynth --enable-libmfx
  libavutil      56.  0.100 / 56.  0.100
  libavcodec     58.  2.100 / 58.  2.100
  libavformat    58.  2.100 / 58.  2.100
  libavdevice    58.  0.100 / 58.  0.100
  libavfilter     7.  0.101 /  7.  0.101
  libswscale      5.  0.101 /  5.  0.101
  libswresample   3.  0.101 /  3.  0.101
  libpostproc    55.  0.100 / 55.  0.100
Input #0, matroska,webm, from 'input.mkv':
  Metadata:
    CREATION_TIME   : 2018-05-02T15:19:05Z
    ENCODER         : Lavf57.7.2
  Duration: 01:33:57.65, start: 0.000000, bitrate: 13042 kb/s
    Chapter #0:0: start 0.000000, end 58.458000
    Metadata:
      title           : Chapter 1
    Chapter #0:1: start 58.458000, end 245.312000
    Metadata:
      title           : Chapter 2
    Chapter #0:2: start 245.312000, end 527.160000
    Metadata:
      title           : Chapter 3
    Chapter #0:3: start 527.160000, end 819.786000
    Metadata:
      title           : Chapter 4
    Chapter #0:4: start 819.786000, end 1772.704000
    Metadata:
      title           : Chapter 5
    Chapter #0:5: start 1772.704000, end 2106.037000
    Metadata:
      title           : Chapter 6
    Chapter #0:6: start 2106.037000, end 2181.212000
    Metadata:
      title           : Chapter 7
    Chapter #0:7: start 2181.212000, end 2440.939000
    Metadata:
      title           : Chapter 8
    Chapter #0:8: start 2440.939000, end 2725.089000
    Metadata:
      title           : Chapter 9
    Chapter #0:9: start 2725.089000, end 3018.282000
    Metadata:
      title           : Chapter 10
    Chapter #0:10: start 3018.282000, end 3352.182000
    Metadata:
      title           : Chapter 11
    Chapter #0:11: start 3352.182000, end 3964.427000
    Metadata:
      title           : Chapter 12
    Chapter #0:12: start 3964.427000, end 4318.181000
    Metadata:
      title           : Chapter 13
    Chapter #0:13: start 4318.181000, end 4644.140000
    Metadata:
      title           : Chapter 14
    Chapter #0:14: start 4644.140000, end 5062.057000
    Metadata:
      title           : Chapter 15
    Chapter #0:15: start 5062.057000, end 5361.089000
    Metadata:
      title           : Chapter 16
    Chapter #0:16: start 5361.089000, end 5636.631000
    Metadata:
      title           : Chapter 17
    Stream #0:0: Video: h264 (Main), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 29.97 fps, 29.97 tbr, 1k tbn, 180k tbc (default)
    Stream #0:1(jpn): Audio: aac (LC), 48000 Hz, stereo, fltp (default)
    Metadata:
      title           : Stereo
Output #0, mp4, to 'output.mp4':
  Metadata:
    encoder         : Lavf58.2.100
    Chapter #0:0: start 0.000000, end 17.000000
    Metadata:
      title           : Chapter 5
    Stream #0:0: Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 29.97 fps, 29.97 tbr, 16k tbn, 1k tbc (default)
    Stream #0:1(jpn): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp (default)
    Metadata:
      title           : Stereo
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame=  395 fps= 24 q=-1.0 Lsize=   30997kB time=00:00:16.99 bitrate=14938.1kbits/s speed=1.02x
video:30645kB audio:333kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.061779%

答案1

如果您在复制视频比特流时在随机点剪切视频(即不重新编码),这是正常的。剪切点可能指定需要先前帧可供解码器使用的帧,ffmpeg 将包含具有负时间戳的那些帧,但并非所有播放器都能正确处理这种情况。

如果您使用不支持这些负时间戳的播放器,视频将仅从指定剪切点后的第一个关键帧开始播放。

您可以添加选项-avoid_negative_ts make_zero到命令行,但这可能会导致视频显示切点。

或者,省略该-c copy部分并使用例如重新编码视频-c:v libx264

相关内容