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


0

这个问题已经在这里有了答案:

因此,在将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%

音频和视频实际上是不同步的,还是只是在不同的时间开始和结束?您正在使用哪个播放器来播放视频?
slhck

@slhck现在您提到了它,我尝试在VLC中播放视频,视频的开始只是一个黑屏,但之后它开始与音频同步播放...就像开始部分被切断一样...
user902222 '18

Answers:


1

如果您在复制视频比特流时(即不进行重新编码)在任意点剪切视频,这是正常的。切入点可以指定一帧,要求解码器可以使用以前的帧,而ffmpeg将包括那些带有负时间戳的帧,但并非所有播放器都能正确处理。

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

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

或者,省略该-c copy部分,然后使用进行重新编码-c:v libx264


因此,这意味着如果没有mkv和mp4之间的黑屏,我将无法进行无损转换,对吗?
user902222'5

这取决于玩家。有些人会支持它。或者,您可以在已知关键帧位置创建切割。(您可以使用此处所示的解决方案:superuser.com/questions/885452/…
slhck
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.