FFmpeg:将一个 MKV 源的 ASS 字幕流与另一个 MKV 进行混合/复制时出现问题,导致开头 33 秒的字幕丢失

FFmpeg:将一个 MKV 源的 ASS 字幕流与另一个 MKV 进行混合/复制时出现问题,导致开头 33 秒的字幕丢失

嘿,第一次发帖,

但我确实尝试了各种方法来解决 WebVTT 的类似问题,甚至尝试了其他解决方案中几个对我有用的选项 [这里]。

无论如何,我有两个来源,第一个 MKV 我只想要它所含的 ASS 字幕(以及所有相关附件),第二个 MKV 我想要保留其中的所有内容。所以我只想将第一个 MKV 中的 ASS 字幕与第二个 MKV 中的字幕混合/复制。

我最初尝试过这个:

ffmpeg -i "first.mkv" -i "second.mkv" -map 1 -map 0:s -map 0:t -map_metadata 0 -c copy "output.mkv"

在检查时,我注意到输出结果为一个工作文件,但 ASS 字幕的前 33 秒不起作用或不显示。然而,在视频的其余部分,它们工作正常并且实际上同步得很好。

然后我尝试做一些类似于我在 WebVTT 字幕中遇到的事情,甚至做得有点过头了:

ffmpeg -analyzeduration 100000000M -probesize 100000000M -c:s ass -i "first.mkv" -i "second.mkv" -map 1 -map 0 -map -0:a -map -0:v -map 0:t -map_metadata 0 -c copy "output.mkv"

我甚至尝试了上述命令而不强制解码器。我甚至尝试了更像这样的变体:

ffmpeg -analyzeduration 100000000M -probesize 100000000M -c:s ass -i "first.mkv" -i "second.mkv" -map 1 -map 0 -map -0:a -map -0:v -map 0:t -map_metadata 0 -c copy "output.mkv"

没有任何警告或错误弹出,甚至附件也能正确复制,并且视频部分的字幕看起来良好且正确。

任何帮助或提示都将不胜感激!

更新 1 (2021 年 6 月 24 日)

输出ffmpeg -i "first.mkv"文件以供检查(如果有帮助)

ffmpeg version 4.4-full_build-www.gyan.dev Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 10.2.0 (Rev6, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libdav1d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libglslang --enable-vulkan --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
Input #0, matroska,webm, from 'first.mkv':
  Metadata:
    title           : S01E01
    encoder         : libebml v1.4.2 + libmatroska v1.6.4
    creation_time   : 2021-06-19T15:23:43.000000Z
  Duration: 00:23:37.12, start: 0.000000, bitrate: 1859 kb/s
  Chapters:
    Chapter #0:0: start 0.000000, end 60.978000
      Metadata:
        title           : Intro
    Chapter #0:1: start 60.978000, end 827.326000
      Metadata:
        title           : Part A
    Chapter #0:2: start 827.326000, end 1417.120000
      Metadata:
        title           : Part B
  Stream #0:0: Video: hevc (Main 10), yuv420p10le(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 1k tbn, 23.98 tbc (default)
    Metadata:
      title           : first
      BPS             : 1527506
      DURATION        : 00:23:36.999000000
      NUMBER_OF_FRAMES: 33974
      NUMBER_OF_BYTES : 270559312
      _STATISTICS_WRITING_APP: mkvmerge v57.0.0 ('Till The End') 64-bit
      _STATISTICS_WRITING_DATE_UTC: 2021-06-19 15:23:43
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
  Stream #0:1(eng): Audio: eac3, 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      BPS             : 128000
      DURATION        : 00:23:37.120000000
      NUMBER_OF_FRAMES: 44285
      NUMBER_OF_BYTES : 22673920
      _STATISTICS_WRITING_APP: mkvmerge v57.0.0 ('Till The End') 64-bit
      _STATISTICS_WRITING_DATE_UTC: 2021-06-19 15:23:43
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
  Stream #0:2(jpn): Audio: eac3, 48000 Hz, stereo, fltp, 128 kb/s
    Metadata:
      BPS             : 128000
      DURATION        : 00:23:37.120000000
      NUMBER_OF_FRAMES: 44285
      NUMBER_OF_BYTES : 22673920
      _STATISTICS_WRITING_APP: mkvmerge v57.0.0 ('Till The End') 64-bit
      _STATISTICS_WRITING_DATE_UTC: 2021-06-19 15:23:43
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
  Stream #0:3(eng): Subtitle: ass (default)
    Metadata:
      title           : Signs & Songs
      BPS             : 4446
      DURATION        : 00:19:35.720000000
      NUMBER_OF_FRAMES: 2858
      NUMBER_OF_BYTES : 653546
      _STATISTICS_WRITING_APP: mkvmerge v57.0.0 ('Till The End') 64-bit
      _STATISTICS_WRITING_DATE_UTC: 2021-06-19 15:23:43
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
  Stream #0:4(eng): Subtitle: ass
    Metadata:
      title           : Dialogue
      BPS             : 3881
      DURATION        : 00:23:26.400000000
      NUMBER_OF_FRAMES: 3320
      NUMBER_OF_BYTES : 682307
      _STATISTICS_WRITING_APP: mkvmerge v57.0.0 ('Till The End') 64-bit
      _STATISTICS_WRITING_DATE_UTC: 2021-06-19 15:23:43
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
  Stream #0:5: Video: mjpeg (Progressive), yuvj420p(pc, bt470bg/unknown/unknown), 400x567 [SAR 350:350 DAR 400:567], 90k tbr, 90k tbn, 90k tbc (attached pic)
    Metadata:
      filename        : cover.jpg
      mimetype        : image/jpeg
  Stream #0:6: Attachment: ttf
    Metadata:
      filename        : Amaranth-Bold.ttf
      mimetype        : application/x-truetype-font
  Stream #0:7: Attachment: ttf
    Metadata:
      filename        : Amaranth-BoldItalic.ttf
      mimetype        : application/x-truetype-font
  Stream #0:8: Attachment: ttf
    Metadata:
      filename        : Amaranth-Italic.ttf
      mimetype        : application/x-truetype-font
  Stream #0:9: Attachment: ttf
    Metadata:
      filename        : Amaranth-Regular.ttf
      mimetype        : application/x-truetype-font
  Stream #0:10: Attachment: ttf
    Metadata:
      filename        : ARIALNB.ttf
      mimetype        : application/x-truetype-font
  Stream #0:11: Attachment: ttf
    Metadata:
      filename        : COMFORTAA-LIGHT.ttf
      mimetype        : application/x-truetype-font
  Stream #0:12: Attachment: ttf
    Metadata:
      filename        : Comfortaa-VariableFont_wght.ttf
      mimetype        : application/x-truetype-font
  Stream #0:13: Attachment: ttf
    Metadata:
      filename        : DerNeueSpargel-Vwzx.ttf
      mimetype        : application/x-truetype-font
  Stream #0:14: Attachment: otf
    Metadata:
      filename        : FOT-ModeMinALargeStd-B.otf
      mimetype        : application/vnd.ms-opentype
  Stream #0:15: Attachment: ttf
    Metadata:
      filename        : GalapagosDemo-WyPYY.ttf
      mimetype        : application/x-truetype-font
  Stream #0:16: Attachment: ttf
    Metadata:
      filename        : keifont.ttf
      mimetype        : application/x-truetype-font
  Stream #0:17: Attachment: ttf
    Metadata:
      filename        : Koowalsky.ttf
      mimetype        : application/x-truetype-font
  Stream #0:18: Attachment: otf
    Metadata:
      filename        : Lalezar-Regular.otf
      mimetype        : application/vnd.ms-opentype
  Stream #0:19: Attachment: ttf
    Metadata:
      filename        : Moire-Regular.ttf
      mimetype        : application/x-truetype-font
  Stream #0:20: Attachment: ttf
    Metadata:
      filename        : olivia.ttf
      mimetype        : application/x-truetype-font
  Stream #0:21: Attachment: ttf
    Metadata:
      filename        : RobotRenegades-LxGE.ttf
      mimetype        : application/x-truetype-font
  Stream #0:22: Attachment: otf
    Metadata:
      filename        : Saira-Medium.otf
      mimetype        : application/vnd.ms-opentype
  Stream #0:23: Attachment: otf
    Metadata:
      filename        : Sedexpersonaluse-y5jq.otf
      mimetype        : application/vnd.ms-opentype
  Stream #0:24: Attachment: ttf
    Metadata:
      filename        : seguisym.ttf
      mimetype        : application/x-truetype-font
  Stream #0:25: Attachment: ttf
    Metadata:
      filename        : sylfaen.ttf
      mimetype        : application/x-truetype-font
  Stream #0:26: Attachment: ttf
    Metadata:
      filename        : Vogue  Bold.ttf
      mimetype        : application/x-truetype-font

答案1

您可以-fix_sub_duration在输入之前尝试该选项,记录如下:

“修复字幕时长。对于每个字幕,等待同一流中的下一个数据包并调整第一个数据包的时长以避免重叠。这对于某些字幕编解码器(尤其是 DVB 字幕)是必要的,因为原始数据包中的时长只是粗略估计,结尾实际上是由一个空的字幕帧标记的。在必要时未能使用此选项可能会导致时长过长或由于非单调时间戳导致多路复用失败。

请注意,此选项将延迟所有数据的输出,直到下一个字幕包被解码:它可能会大大增加内存消耗和延迟。”

从你的第一个例子:

ffmpeg -fix_sub_duration -i "first.mkv" -i "second.mkv" -map 1 -map 0:s -map 0:t -map_metadata 0 -c copy "output.mkv"

並报告。

相关内容