使用avconv将带有字幕的DVD图像转换为MKV

时间:2013-10-05 17:43:42

标签: ffmpeg dvd mkv avconv

这是我将DVD图像转换为另一个视频格式(v.g. MP4)所知道的程序:

  1. VTS_01_文件夹中的.VOB n VIDEO_TS文件(对于 n > = 0)连接到单个VOB中文件。
  2. 使用avconvffmpeg将该VOB转换为其他格式。
  3. 到目前为止一直很好,但是现在我想将DVD图像转换为字幕。据我所知MKV格式支持字幕,所以它似乎是一个明显的选择。或者,我可以使用任何其他格式的硬字幕(字幕作为视频图像的一部分)。

    然而,DVD影像中的字幕编码是dvdsub,我收到以下错误

    Only SUBTITLE_ASS type supported.
    Subtitle encoding failed
    

    但是,在运行avconv -codecs时,我得到了:

    ...
     DES    dvdsub          DVD subtitles
    ...
    

    -c:s copy切换,虽然它可以防止命令失败,但它似乎不会产生玩家可以理解的副标题。

    那么,如何使用assdvdsub创建avconv个字幕?

    我的VOB文件有八个字幕通道和两个音频通道。 Ubuntu视频应用程序不显示任何字幕,只有第一个音频通道似乎正在工作,DVD图像可能会被破坏。

    对于双层DVD,另一个文件显示字幕编码错误,但是当使用-c:s copy开关时,它会进一步显示:

    Application provided invalid, non monotonically increasing dts to muxer in stream 2: 49 >= 49
    av_interleaved_write_frame(): Invalid argument
    

    提前感谢您提供有关如何解决这些问题的任何想法。

    (我使用的是Ubuntu ffmpegavconv的别名。我知道可以安装真正的ffmpeg但到目前为止我还没有这样做。)


    更新:命令和控制台输出:

    命令

    cat VTS_01_1.VOB VTS_01_2.VOB VTS_01_3.VOB VTS_01_4.VOB VTS_01_5.VOB > ~/temp/mymovie.VOB
    cd ~/temp
    avconv -i mymovie.VOB
    

    输出

    avconv version 0.8.6-6:0.8.6-1ubuntu2, Copyright (c) 2000-2013 the Libav developers
      built on Mar 30 2013 22:20:06 with gcc 4.7.2
    [mpeg @ 0x1a64d40] max_analyze_duration reached
    Input #0, mpeg, from 'mymovie.VOB':
      Duration: 00:00:01.95, start: 0.280633, bitrate: -2147483 kb/s
        Stream #0.0[0x1e0]: Video: mpeg2video (Main), yuv420p, 720x480 [PAR 8:9 DAR 4:3], 7500 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
        Stream #0.1[0x20]: Subtitle: dvdsub
        Stream #0.2[0x21]: Subtitle: dvdsub
        Stream #0.3[0x22]: Subtitle: dvdsub
        Stream #0.4[0x23]: Subtitle: dvdsub
        Stream #0.5[0x24]: Subtitle: dvdsub
        Stream #0.6[0x25]: Subtitle: dvdsub
        Stream #0.7[0x26]: Subtitle: dvdsub
        Stream #0.8[0x27]: Subtitle: dvdsub
        Stream #0.9[0x80]: Audio: ac3, 48000 Hz, 5.1, s16, 448 kb/s
        Stream #0.10[0x81]: Audio: ac3, 48000 Hz, 5.1, s16, 448 kb/s
    At least one output file must be specified
    

    命令

    avconv -i mymovie.VOB mymovie.mkv
    

    输出

    avconv version 0.8.6-6:0.8.6-1ubuntu2, Copyright (c) 2000-2013 the Libav developers
      built on Mar 30 2013 22:20:06 with gcc 4.7.2
    [mpeg @ 0x1cdad40] max_analyze_duration reached
    Input #0, mpeg, from 'mymovie.VOB':
      Duration: 00:00:01.95, start: 0.280633, bitrate: -2147483 kb/s
        Stream #0.0[0x1e0]: Video: mpeg2video (Main), yuv420p, 720x480 [PAR 8:9 DAR 4:3], 7500 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
        Stream #0.1[0x20]: Subtitle: dvdsub
        Stream #0.2[0x21]: Subtitle: dvdsub
        Stream #0.3[0x22]: Subtitle: dvdsub
        Stream #0.4[0x23]: Subtitle: dvdsub
        Stream #0.5[0x24]: Subtitle: dvdsub
        Stream #0.6[0x25]: Subtitle: dvdsub
        Stream #0.7[0x26]: Subtitle: dvdsub
        Stream #0.8[0x27]: Subtitle: dvdsub
        Stream #0.9[0x80]: Audio: ac3, 48000 Hz, 5.1, s16, 448 kb/s
        Stream #0.10[0x81]: Audio: ac3, 48000 Hz, 5.1, s16, 448 kb/s
    File 'mymovie.mkv' already exists. Overwrite ? [y/N] y
    [buffer @ 0x1ce23c0] w:720 h:480 pixfmt:yuv420p
    Output #0, matroska, to 'mymovie.mkv':
      Metadata:
        encoder         : Lavf53.21.1
        Stream #0.0: Video: mpeg4, yuv420p, 720x480 [PAR 8:9 DAR 4:3], q=2-31, 200 kb/s, 1k tbn, 29.97 tbc
        Stream #0.1: Audio: libvorbis, 48000 Hz, 5.1, s16
        Stream #0.2: Subtitle: ass, 200 kb/s
    Stream mapping:
      Stream #0:0 -> #0:0 (mpeg2video -> mpeg4)
      Stream #0:9 -> #0:1 (ac3 -> libvorbis)
      Stream #0:1 -> #0:2 (dvdsub -> ass)
    Press ctrl-c to stop encoding
    [ass @ 0x1ce0140] Only SUBTITLE_ASS type supported.
    Subtitle encoding failed
    

    命令

    avconv -i mymovie.VOB -c:s copy mymovie.mkv
    

    输出省略。

    命令

    avconv -i mymovie.mkv
    

    输出

    avconv version 0.8.6-6:0.8.6-1ubuntu2, Copyright (c) 2000-2013 the Libav developers
      built on Mar 30 2013 22:20:06 with gcc 4.7.2
    [matroska,webm @ 0xbc1d40] Estimating duration from bitrate, this may be inaccurate
    Input #0, matroska,webm, from 'mymovie.mkv':
      Metadata:
        ENCODER         : Lavf53.21.1
      Duration: 01:05:09.47, start: 0.000000, bitrate: N/A
        Stream #0.0: Video: mpeg4 (Simple Profile), yuv420p, 720x480 [PAR 8:9 DAR 4:3], 29.97 fps, 29.97 tbr, 1k tbn, 30k tbc (default)
        Stream #0.1: Audio: vorbis, 48000 Hz, 5.1, s16 (default)
        Stream #0.2: Subtitle: dvdsub (default)
    At least one output file must be specified
    

    现在,对于双层: 命令

    cat VTS_01_1.VOB VTS_01_2.VOB VTS_01_3.VOB VTS_01_4.VOB VTS_01_5.VOB VTS_01_6.VOB VTS_01_7.VOB VTS_01_8.VOB > ~/temp/mylongmovie.VOB
    cd ~/temp
    avconv -i mylongmovie.VOB mylongmovie.mkv
    

    输出

    avconv version 0.8.6-6:0.8.6-1ubuntu2, Copyright (c) 2000-2013 the Libav developers
      built on Mar 30 2013 22:20:06 with gcc 4.7.2
    [mpeg @ 0x13c2d40] max_analyze_duration reached
    Input #0, mpeg, from 'Cosmos-0203.VOB':
      Duration: 00:00:30.24, start: 0.280633, bitrate: 2103365 kb/s
        Stream #0.0[0x1e0]: Video: mpeg2video (Main), yuv420p, 720x480 [PAR 8:9 DAR 4:3], 8000 kb/s, 27.46 fps, 59.94 tbr, 90k tbn, 59.94 tbc
        Stream #0.1[0x20]: Subtitle: dvdsub
        Stream #0.2[0x21]: Subtitle: dvdsub
        Stream #0.3[0x22]: Subtitle: dvdsub
        Stream #0.4[0x23]: Subtitle: dvdsub
        Stream #0.5[0x24]: Subtitle: dvdsub
        Stream #0.6[0x25]: Subtitle: dvdsub
        Stream #0.7[0x26]: Subtitle: dvdsub
        Stream #0.8[0x27]: Subtitle: dvdsub
        Stream #0.9[0x81]: Audio: ac3, 48000 Hz, 5.1, s16, 448 kb/s
        Stream #0.10[0x80]: Audio: ac3, 48000 Hz, 5.1, s16, 448 kb/s
    File 'mylongmovie.mkv' already exists. Overwrite ? [y/N] y
    [buffer @ 0x13ca3c0] w:720 h:480 pixfmt:yuv420p
    Output #0, matroska, to 'mylongmovie.mkv':
      Metadata:
        encoder         : Lavf53.21.1
        Stream #0.0: Video: mpeg4, yuv420p, 720x480 [PAR 8:9 DAR 4:3], q=2-31, 200 kb/s, 1k tbn, 59.94 tbc
        Stream #0.1: Audio: libvorbis, 48000 Hz, 5.1, s16
        Stream #0.2: Subtitle: ass, 200 kb/s
    Stream mapping:
      Stream #0:0 -> #0:0 (mpeg2video -> mpeg4)
      Stream #0:9 -> #0:1 (ac3 -> libvorbis)
      Stream #0:1 -> #0:2 (dvdsub -> ass)
    Press ctrl-c to stop encoding
    [ass @ 0x13d19c0] Only SUBTITLE_ASS type supported.
    Subtitle encoding failed
    

    命令

    avconv -i mylongmovie.VOB -c:s copy mylongmovie.mkv 
    

    输出

    avconv version 0.8.6-6:0.8.6-1ubuntu2, Copyright (c) 2000-2013 the Libav developers
      built on Mar 30 2013 22:20:06 with gcc 4.7.2
    [mpeg @ 0xce1d40] max_analyze_duration reached
    Input #0, mpeg, from 'mylongmovie.VOB':
      Duration: 00:00:30.24, start: 0.280633, bitrate: 2103365 kb/s
        Stream #0.0[0x1e0]: Video: mpeg2video (Main), yuv420p, 720x480 [PAR 8:9 DAR 4:3], 8000 kb/s, 27.46 fps, 59.94 tbr, 90k tbn, 59.94 tbc
        Stream #0.1[0x20]: Subtitle: dvdsub
        Stream #0.2[0x21]: Subtitle: dvdsub
        Stream #0.3[0x22]: Subtitle: dvdsub
        Stream #0.4[0x23]: Subtitle: dvdsub
        Stream #0.5[0x24]: Subtitle: dvdsub
        Stream #0.6[0x25]: Subtitle: dvdsub
        Stream #0.7[0x26]: Subtitle: dvdsub
        Stream #0.8[0x27]: Subtitle: dvdsub
        Stream #0.9[0x81]: Audio: ac3, 48000 Hz, 5.1, s16, 448 kb/s
        Stream #0.10[0x80]: Audio: ac3, 48000 Hz, 5.1, s16, 448 kb/s
    File 'mylongmovie.mkv' already exists. Overwrite ? [y/N] y
    [buffer @ 0xce93c0] w:720 h:480 pixfmt:yuv420p
    Output #0, matroska, to 'mylongmovie.mkv':
      Metadata:
        encoder         : Lavf53.21.1
        Stream #0.0: Video: mpeg4, yuv420p, 720x480 [PAR 8:9 DAR 4:3], q=2-31, 200 kb/s, 1k tbn, 59.94 tbc
        Stream #0.1: Audio: libvorbis, 48000 Hz, 5.1, s16
        Stream #0.2: Subtitle: dvdsub
    Stream mapping:
      Stream #0:0 -> #0:0 (mpeg2video -> mpeg4)
      Stream #0:9 -> #0:1 (ac3 -> libvorbis)
      Stream #0:1 -> #0:2 (copy)
    Press ctrl-c to stop encoding
    [matroska @ 0xce4b40] Application provided invalid, non monotonically increasing dts to muxer in stream 2: 49 >= 49
    av_interleaved_write_frame(): Invalid argument
    

2 个答案:

答案 0 :(得分:40)

简短回答:请跳至完整命令行部分,然后从this site下载ffmpeg

最初,我计划用avconv来回答如何做到这一点,因为(a)答案仍然缺失,(b)avconv似乎是今天ubuntu系统的默认设置。然而,目前看起来目前还是太麻烦了 - 至少对于我的测试用例来说。

ffmpeg设置

由于您要求avconvffmpeg,我刚刚得知avconvffmpeg的分支(请参阅this answer进行讨论) ,我从this site下载了当前版本的ffmpeg,正如上述答案所解释的那样。 Windows版本也可用。对于典型的当前64位Linux构建,直接链接将是this page。它包含每日构建。向下滚动,直到您看到最新,最好的,下载,并解压缩,例如tar xzvf ffmpeg.static.64bit.2014-02-14.tar.gz。静态构建的优点是它具有较少(如果没有)依赖性。解压tarfile会在当前目录中创建两个新的可执行文件ffmpegffprobe

基本命令行

现在我们可以使用最新的ffmpegmymovie.vob*内的所有流复制到其他格式。例如:

./ffmpeg -i mymovie.vob -c:v copy -c:a copy -c:s copy -map 0 mymovie.mkv

此命令行

  • 从输入文件-i filename
  • 读入
  • 在其中复制视频流-c:v copy
  • 在其中复制音频流-c:a copy
  • 复制其中的字幕-c:s copy
  • 而不只是使用第一个,它使用并复制所有-map 0
  • 到输出文件outputfile

让我们展开上面的命令行来解决工具中的一些可能的错误,或者损坏的输入文件,或者只是关于.vob文件的细节。

解决错误Can't write packet with unknown timestamp

在输入文件之前添加选项-fflags +genpts

./ffmpeg -fflags +genpts -i mymovie.vob -c:v copy -c:a copy -c:s copy -map 0 mymovie.mkv

ffmpeg中的选项始终只影响当前选项后名为的输入或输出文件。这两个选项必须影响输入文件,因此它们必须首先出现。

this bug ticket涵盖了此解决方法,并且在所有情况下都可能无效。

缺少部分或全部字幕

这是处理.vob文件时非常典型的行为,并在ffmpeg FAQ中介绍。视频容器文件类型(例如.avi.mp4.mkv具有列出文件所有内容的标头(文件开头的数据)。这使得玩家和转换工具可以轻松了解所期望的数据类型。 .vob个文件没有这样的显式标头。因此,当ffmpegavconv开始时,它们会查看前几千个字节。在vob文件中,字幕可能很晚才开始。在我的测试用例中,第一个字幕在几秒钟后出现,因此工具在启动时看不到它。以下是在这些情况下编码期间的典型示例输出:

Output #0, matroska, to 'test.mkv':
  Metadata:
    encoder         : Lavf55.32.101
    Stream #0:0: Video: mpeg2video (mpg2 / 0x3267706D), yuv420p, 720x576 [SAR 64:45 DAR 16:9], q=2-31, max. 9800 kb/s, 25 fps, 1k tbn, 90k tbc
    Stream #0:1: Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, 5.1(side), 448 kb/s
    Stream #0:2: Audio: dts ([1] [0][0] / 0x2001), 48000 Hz, 5.1(side), 768 kb/s
    Stream #0:3: Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, 5.1(side), 448 kb/s
    Stream #0:4: Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, stereo, 224 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
  Stream #0:2 -> #0:2 (copy)
  Stream #0:3 -> #0:3 (copy)
  Stream #0:4 -> #0:4 (copy)
Press [q] to stop, [?] for help
[mpeg @ 0x31f2540] New subtitle stream 0:5 at pos:16945166 and DTS:22.2473s
[mpeg @ 0x31f2540] New subtitle stream 0:6 at pos:16951310 and DTS:22.2473s
[mpeg @ 0x31f2540] New subtitle stream 0:7 at pos:16957454 and DTS:22.2873s
[mpeg @ 0x31f2540] New subtitle stream 0:8 at pos:16963598 and DTS:22.2873s
[mpeg @ 0x31f2540] New subtitle stream 0:9 at pos:18405390 and DTS:25.4873s
[mpeg @ 0x31f2540] New subtitle stream 0:10 at pos:18417678 and DTS:25.4873s
[mpeg @ 0x31f2540] New subtitle stream 0:11 at pos:264593422 and DTS:288.207sts/s    
[mpeg @ 0x31f2540] New subtitle stream 0:12 at pos:264597518 and DTS:288.207s
frame=24694 fps=7322 q=-1.0 Lsize=  859345kB time=00:16:27.74 bitrate=7127.1kbits/s    
video:632823kB audio:224996kB subtitle:0 data:0 global headers:0kB muxing overhead 0.177935%

可以看出,在实际编码期间发现了新的字幕流。如果有人试图添加-map 5选项以包含该流,ffmpeg会在启动时抱怨此流编号不存在。

解决方案是告诉ffmpeg分析文件开头的更多字节,以便查找所有流。

尝试在输入文件之前添加选项-analyzeduration 1000000k -probesize 1000000k

如果仍未找到流,请尝试增加数字。在我的测试用例中,这些数字足够大。然后输出变为:

Input #0, mpeg, from 'mymovie.vob':
  Duration: 00:59:39.90, start: 0.287267, bitrate: 5915 kb/s
    Stream #0:0[0x1e0]: Video: mpeg2video (Main), yuv420p(tv, bt470bg), 720x576 [SAR 64:45 DAR 16:9], max. 9800 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc
    Stream #0:1[0x80]: Audio: ac3, 48000 Hz, 5.1(side), fltp, 448 kb/s
    Stream #0:2[0x89]: Audio: dts (DTS), 48000 Hz, 5.1(side), fltp, 768 kb/s
    Stream #0:3[0x82]: Audio: ac3, 48000 Hz, 5.1(side), fltp, 448 kb/s
    Stream #0:4[0x83]: Audio: ac3, 48000 Hz, stereo, fltp, 224 kb/s
    Stream #0:5[0x20]: Subtitle: dvd_subtitle
    Stream #0:6[0x21]: Subtitle: dvd_subtitle
    Stream #0:7[0x22]: Subtitle: dvd_subtitle
    Stream #0:8[0x23]: Subtitle: dvd_subtitle
    Stream #0:9[0x24]: Subtitle: dvd_subtitle
    Stream #0:10[0x25]: Subtitle: dvd_subtitle
    Stream #0:11[0x26]: Subtitle: dvd_subtitle
    Stream #0:12[0x27]: Subtitle: dvd_subtitle
File 'test.mkv' already exists. Overwrite ? [y/N] y
Output #0, matroska, to 'test.mkv':
  Metadata:
    encoder         : Lavf55.32.101
    Stream #0:0: Video: mpeg2video (mpg2 / 0x3267706D), yuv420p, 720x576 [SAR 64:45 DAR 16:9], q=2-31, max. 9800 kb/s, 25 fps, 1k tbn, 90k tbc
    Stream #0:1: Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, 5.1(side), 448 kb/s
    Stream #0:2: Audio: dts ([1] [0][0] / 0x2001), 48000 Hz, 5.1(side), 768 kb/s
    Stream #0:3: Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, 5.1(side), 448 kb/s
    Stream #0:4: Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, stereo, 224 kb/s
    Stream #0:5: Subtitle: dvd_subtitle
    Stream #0:6: Subtitle: dvd_subtitle
    Stream #0:7: Subtitle: dvd_subtitle
    Stream #0:8: Subtitle: dvd_subtitle
    Stream #0:9: Subtitle: dvd_subtitle
    Stream #0:10: Subtitle: dvd_subtitle
    Stream #0:11: Subtitle: dvd_subtitle
    Stream #0:12: Subtitle: dvd_subtitle

完整命令行

./ffmpeg -fflags +genpts -analyzeduration 1000000k -probesize 1000000k -i mymovie.vob -c:v copy -c:a copy -c:s copy -map 0 mymovie.mkv

任何副本都可以用编解码器替换,以实际转换并可能压缩数据。但如果它只是三个副本,那么命令可以简化为:

./ffmpeg -fflags +genpts -analyzeduration 1000000k -probesize 1000000k -i mymovie.vob  -c copy -map 0 mymovie.mkv

avconv也支持所有这些选项。但是这个工具似乎仍然存在一些字幕的问题。如果您看到此错误:

[matroska @ 0x383aee60] Application provided invalid, non monotonically increasing dts to muxer in stream 7: 58280 >= 58280
av_interleaved_write_frame(): Invalid argument

您可以通过下载最新的ffmpeg并使用该工具代替解决方法,如上所述。

答案 1 :(得分:4)

如果您需要质量保证解决方案,请尝试MakeMKV 如果要压缩视频轨道或将MPEG-2转换为H.264,可以使用handbrake