使用 FFMPEG 将 MKV 转换为 MP4 时,如何选择要保留哪些音频和字幕轨道?

使用 FFMPEG 将 MKV 转换为 MP4 时,如何选择要保留哪些音频和字幕轨道?

我有一个 .mkv 文件,其中有 2 个音轨和 2 个字幕轨(SRT 格式)。

我想将该 .mkv 转换为 mp4,并让其具有音轨 #2 和子轨道 #2 作为启动 mp4 时播放的轨道。

图像

我正在使用 FFMPEG,因此我使用它来转换:

ffmpeg -i myMovie.mkv -vcodec copy -acodec copy myMovieMP4.mp4

这会导致两个问题:

  1. 它使用音轨 #1
  1. 即使选择了字幕轨道,字幕也不会出现

*编辑:ffmpeg -i test.mp4 的结果:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'test.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf58.45.100
  Duration: 00:22:59.76, start: 0.000000, bitrate: 362 kb/s
    Chapter #0:0: start 0.000000, end 90.400000
    Metadata:
      title           : Opening
    Chapter #0:1: start 90.400000, end 532.334000
    Metadata:
      title           : Part A
    Chapter #0:2: start 532.334000, end 1299.801000
    Metadata:
      title           : Part B
    Chapter #0:3: start 1299.801000, end 1359.334000
    Metadata:
      title           : Ending
    Chapter #0:4: start 1359.334000, end 1379.754000
    Metadata:
      title           : Next on AAAA
    Stream #0:0(und): Video: hevc (Main 10) (hev1 / 0x31766568), yuv420p10le(tv, unknown/bt709/unknown), 720x480 [SAR 1:1 DAR 3:2], 326 kb/s, SAR 8:9 DAR 4:3, 23.98 fps, 23.98 tbr, 16k tbn, 23.98 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (HE-AAC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 30 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
    Stream #0:2(eng): Subtitle: mov_text (tx3g / 0x67337874), 0 kb/s (default)
    Metadata:
      handler_name    : SubtitleHandler
    Stream #0:3(eng): Data: bin_data (text / 0x74786574)
    Metadata:
      handler_name    : SubtitleHandler
At least one output file must be specified

*编辑2:

Input #0, matroska,webm, from 'myMovie.mkv':
  Metadata:
    creation_time   : 2016-10-04T14:07:11.000000Z
    ENCODER         : Lavf56.0.100
  Duration: 00:22:59.79, start: 0.000000, bitrate: 388 kb/s
    Chapter #0:0: start 0.000000, end 90.400000
    Metadata:
      title           : Opening
    Chapter #0:1: start 90.400000, end 532.334000
    Metadata:
      title           : Part A
    Chapter #0:2: start 532.334000, end 1299.801000
    Metadata:
      title           : Part B
    Chapter #0:3: start 1299.801000, end 1359.334000
    Metadata:
      title           : Ending
    Chapter #0:4: start 1359.334000, end 1379.754000
    Metadata:
      title           : Next on AAAA
    Stream #0:0: Video: hevc (Main 10), yuv420p10le(tv, unknown/bt709/unknown), 720x480 [SAR 1:1 DAR 3:2], SAR 8:9 DAR 4:3, 23.98 fps, 23.98 tbr, 1k tbn, 23.98 tbc (default)
    Metadata:
      title           : Encoded with IFME v4.9.4.0
      BPS             : 326855
      BPS-eng         : 326855
      DURATION        : 00:22:59.755000000
      DURATION-eng    : 00:22:59.755000000
      NUMBER_OF_FRAMES: 33081
      NUMBER_OF_FRAMES-eng: 33081
      NUMBER_OF_BYTES : 56372607
      NUMBER_OF_BYTES-eng: 56372607
      _STATISTICS_WRITING_APP: mkvmerge v9.2.0 ('Photograph') 64bit
      _STATISTICS_WRITING_APP-eng: mkvmerge v9.2.0 ('Photograph') 64bit
      _STATISTICS_WRITING_DATE_UTC: 2016-10-04 14:07:11
      _STATISTICS_WRITING_DATE_UTC-eng: 2016-10-04 14:07:11
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
    Stream #0:1: Audio: aac (HE-AAC), 48000 Hz, stereo, fltp (default)
    Metadata:
      title           : Track 1
      BPS             : 29395
      BPS-eng         : 29395
      DURATION        : 00:22:59.755000000
      DURATION-eng    : 00:22:59.755000000
      NUMBER_OF_FRAMES: 32338
      NUMBER_OF_FRAMES-eng: 32338
      NUMBER_OF_BYTES : 5069783
      NUMBER_OF_BYTES-eng: 5069783
      _STATISTICS_WRITING_APP: mkvmerge v9.2.0 ('Photograph') 64bit
      _STATISTICS_WRITING_APP-eng: mkvmerge v9.2.0 ('Photograph') 64bit
      _STATISTICS_WRITING_DATE_UTC: 2016-10-04 14:07:11
      _STATISTICS_WRITING_DATE_UTC-eng: 2016-10-04 14:07:11
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
    Stream #0:2: Audio: aac (HE-AAC), 48000 Hz, stereo, fltp
    Metadata:
      title           : Track 2
      BPS             : 30140
      BPS-eng         : 30140
      DURATION        : 00:22:59.755000000
      DURATION-eng    : 00:22:59.755000000
      NUMBER_OF_FRAMES: 32338
      NUMBER_OF_FRAMES-eng: 32338
      NUMBER_OF_BYTES : 5198254
      NUMBER_OF_BYTES-eng: 5198254
      _STATISTICS_WRITING_APP: mkvmerge v9.2.0 ('Photograph') 64bit
      _STATISTICS_WRITING_APP-eng: mkvmerge v9.2.0 ('Photograph') 64bit
      _STATISTICS_WRITING_DATE_UTC: 2016-10-04 14:07:11
      _STATISTICS_WRITING_DATE_UTC-eng: 2016-10-04 14:07:11
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
    Stream #0:3(eng): Subtitle: ass (default)
    Metadata:
      title           : Signs/Songs Sub
      LANGUAGE        : eng
      ENCODER         : Lavc56.0.100 ass
      BPS             : 13
      BPS-eng         : 13
      DURATION        : 00:22:38.710000000
      DURATION-eng    : 00:22:38.710000000
      NUMBER_OF_FRAMES: 30
      NUMBER_OF_FRAMES-eng: 30
      NUMBER_OF_BYTES : 2313
      NUMBER_OF_BYTES-eng: 2313
      _STATISTICS_WRITING_APP: mkvmerge v9.2.0 ('Photograph') 64bit
      _STATISTICS_WRITING_APP-eng: mkvmerge v9.2.0 ('Photograph') 64bit
      _STATISTICS_WRITING_DATE_UTC: 2016-10-04 14:07:11
      _STATISTICS_WRITING_DATE_UTC-eng: 2016-10-04 14:07:11
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
    Stream #0:4(eng): Subtitle: ass
    Metadata:
      title           : Full English Sub
      LANGUAGE        : eng
      ENCODER         : Lavc56.0.100 ass
      BPS             : 112
      BPS-eng         : 112
      DURATION        : 00:22:53.940000000
      DURATION-eng    : 00:22:53.940000000
      NUMBER_OF_FRAMES: 331
      NUMBER_OF_FRAMES-eng: 331
      NUMBER_OF_BYTES : 19247
      NUMBER_OF_BYTES-eng: 19247
      _STATISTICS_WRITING_APP: mkvmerge v9.2.0 ('Photograph') 64bit
      _STATISTICS_WRITING_APP-eng: mkvmerge v9.2.0 ('Photograph') 64bit
      _STATISTICS_WRITING_DATE_UTC: 2016-10-04 14:07:11
      _STATISTICS_WRITING_DATE_UTC-eng: 2016-10-04 14:07:11
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
Invalid input file index: 2.

*编辑 3:使用此命令:

ffmpeg -i myMovie.mkv -vcodec copy -acodec copy -map 0:s:1 -map 0:v:0 -map 0:a:1 -c:s mov_text test.mp4

Input #0, matroska,webm, from 'myMovie.mkv':
  Metadata:
    creation_time   : 2016-10-04T14:07:11.000000Z
    ENCODER         : Lavf56.0.100
  Duration: 00:22:59.79, start: 0.000000, bitrate: 388 kb/s
    Chapter #0:0: start 0.000000, end 90.400000
    Metadata:
      title           : Opening
    Chapter #0:1: start 90.400000, end 532.334000
    Metadata:
      title           : Part A
    Chapter #0:2: start 532.334000, end 1299.801000
    Metadata:
      title           : Part B
    Chapter #0:3: start 1299.801000, end 1359.334000
    Metadata:
      title           : Ending
    Chapter #0:4: start 1359.334000, end 1379.754000
    Metadata:
      title           : Next on AAAA
    Stream #0:0: Video: hevc (Main 10), yuv420p10le(tv, unknown/bt709/unknown), 720x480 [SAR 1:1 DAR 3:2], SAR 8:9 DAR 4:3, 23.98 fps, 23.98 tbr, 1k tbn, 23.98 tbc (default)
    Metadata:
      title           : Encoded with IFME v4.9.4.0
      BPS             : 326855
      BPS-eng         : 326855
      DURATION        : 00:22:59.755000000
      DURATION-eng    : 00:22:59.755000000
      NUMBER_OF_FRAMES: 33081
      NUMBER_OF_FRAMES-eng: 33081
      NUMBER_OF_BYTES : 56372607
      NUMBER_OF_BYTES-eng: 56372607
      _STATISTICS_WRITING_APP: mkvmerge v9.2.0 ('Photograph') 64bit
      _STATISTICS_WRITING_APP-eng: mkvmerge v9.2.0 ('Photograph') 64bit
      _STATISTICS_WRITING_DATE_UTC: 2016-10-04 14:07:11
      _STATISTICS_WRITING_DATE_UTC-eng: 2016-10-04 14:07:11
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
    Stream #0:1: Audio: aac (HE-AAC), 48000 Hz, stereo, fltp (default)
    Metadata:
      title           : Track 1
      BPS             : 29395
      BPS-eng         : 29395
      DURATION        : 00:22:59.755000000
      DURATION-eng    : 00:22:59.755000000
      NUMBER_OF_FRAMES: 32338
      NUMBER_OF_FRAMES-eng: 32338
      NUMBER_OF_BYTES : 5069783
      NUMBER_OF_BYTES-eng: 5069783
      _STATISTICS_WRITING_APP: mkvmerge v9.2.0 ('Photograph') 64bit
      _STATISTICS_WRITING_APP-eng: mkvmerge v9.2.0 ('Photograph') 64bit
      _STATISTICS_WRITING_DATE_UTC: 2016-10-04 14:07:11
      _STATISTICS_WRITING_DATE_UTC-eng: 2016-10-04 14:07:11
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
    Stream #0:2: Audio: aac (HE-AAC), 48000 Hz, stereo, fltp
    Metadata:
      title           : Track 2
      BPS             : 30140
      BPS-eng         : 30140
      DURATION        : 00:22:59.755000000
      DURATION-eng    : 00:22:59.755000000
      NUMBER_OF_FRAMES: 32338
      NUMBER_OF_FRAMES-eng: 32338
      NUMBER_OF_BYTES : 5198254
      NUMBER_OF_BYTES-eng: 5198254
      _STATISTICS_WRITING_APP: mkvmerge v9.2.0 ('Photograph') 64bit
      _STATISTICS_WRITING_APP-eng: mkvmerge v9.2.0 ('Photograph') 64bit
      _STATISTICS_WRITING_DATE_UTC: 2016-10-04 14:07:11
      _STATISTICS_WRITING_DATE_UTC-eng: 2016-10-04 14:07:11
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
    Stream #0:3(eng): Subtitle: ass (default)
    Metadata:
      title           : Signs/Songs Sub
      LANGUAGE        : eng
      ENCODER         : Lavc56.0.100 ass
      BPS             : 13
      BPS-eng         : 13
      DURATION        : 00:22:38.710000000
      DURATION-eng    : 00:22:38.710000000
      NUMBER_OF_FRAMES: 30
      NUMBER_OF_FRAMES-eng: 30
      NUMBER_OF_BYTES : 2313
      NUMBER_OF_BYTES-eng: 2313
      _STATISTICS_WRITING_APP: mkvmerge v9.2.0 ('Photograph') 64bit
      _STATISTICS_WRITING_APP-eng: mkvmerge v9.2.0 ('Photograph') 64bit
      _STATISTICS_WRITING_DATE_UTC: 2016-10-04 14:07:11
      _STATISTICS_WRITING_DATE_UTC-eng: 2016-10-04 14:07:11
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
    Stream #0:4(eng): Subtitle: ass
    Metadata:
      title           : Full English Sub
      LANGUAGE        : eng
      ENCODER         : Lavc56.0.100 ass
      BPS             : 112
      BPS-eng         : 112
      DURATION        : 00:22:53.940000000
      DURATION-eng    : 00:22:53.940000000
      NUMBER_OF_FRAMES: 331
      NUMBER_OF_FRAMES-eng: 331
      NUMBER_OF_BYTES : 19247
      NUMBER_OF_BYTES-eng: 19247
      _STATISTICS_WRITING_APP: mkvmerge v9.2.0 ('Photograph') 64bit
      _STATISTICS_WRITING_APP-eng: mkvmerge v9.2.0 ('Photograph') 64bit
      _STATISTICS_WRITING_DATE_UTC: 2016-10-04 14:07:11
      _STATISTICS_WRITING_DATE_UTC-eng: 2016-10-04 14:07:11
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
Output #0, mp4, to 'test.mp4':
  Metadata:
    encoder         : Lavf58.45.100
    Chapter #0:0: start 0.000000, end 90.400000
    Metadata:
      title           : Opening
    Chapter #0:1: start 90.400000, end 532.334000
    Metadata:
      title           : Part A
    Chapter #0:2: start 532.334000, end 1299.801000
    Metadata:
      title           : Part B
    Chapter #0:3: start 1299.801000, end 1359.334000
    Metadata:
      title           : Ending
    Chapter #0:4: start 1359.334000, end 1379.754000
    Metadata:
      title           : Next on AAAA
    Stream #0:0(eng): Subtitle: mov_text (tx3g / 0x67337874)
    Metadata:
      title           : Full English Sub
      LANGUAGE        : eng
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
      BPS             : 112
      BPS-eng         : 112
      DURATION        : 00:22:53.940000000
      DURATION-eng    : 00:22:53.940000000
      NUMBER_OF_FRAMES: 331
      NUMBER_OF_FRAMES-eng: 331
      NUMBER_OF_BYTES : 19247
      NUMBER_OF_BYTES-eng: 19247
      _STATISTICS_WRITING_APP: mkvmerge v9.2.0 ('Photograph') 64bit
      _STATISTICS_WRITING_APP-eng: mkvmerge v9.2.0 ('Photograph') 64bit
      _STATISTICS_WRITING_DATE_UTC: 2016-10-04 14:07:11
      _STATISTICS_WRITING_DATE_UTC-eng: 2016-10-04 14:07:11
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
      encoder         : Lavc58.91.100 mov_text
    Stream #0:1: Video: hevc (Main 10) (hev1 / 0x31766568), yuv420p10le(tv, unknown/bt709/unknown), 720x480 [SAR 8:9 DAR 4:3], q=2-31, 23.98 fps, 23.98 tbr, 16k tbn, 1k tbc (default)
    Metadata:
      title           : Encoded with IFME v4.9.4.0
      BPS             : 326855
      BPS-eng         : 326855
      DURATION        : 00:22:59.755000000
      DURATION-eng    : 00:22:59.755000000
      NUMBER_OF_FRAMES: 33081
      NUMBER_OF_FRAMES-eng: 33081
      NUMBER_OF_BYTES : 56372607
      NUMBER_OF_BYTES-eng: 56372607
      _STATISTICS_WRITING_APP: mkvmerge v9.2.0 ('Photograph') 64bit
      _STATISTICS_WRITING_APP-eng: mkvmerge v9.2.0 ('Photograph') 64bit
      _STATISTICS_WRITING_DATE_UTC: 2016-10-04 14:07:11
      _STATISTICS_WRITING_DATE_UTC-eng: 2016-10-04 14:07:11
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
    Stream #0:2: Audio: aac (HE-AAC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp
    Metadata:
      title           : Track 2
      BPS             : 30140
      BPS-eng         : 30140
      DURATION        : 00:22:59.755000000
      DURATION-eng    : 00:22:59.755000000
      NUMBER_OF_FRAMES: 32338
      NUMBER_OF_FRAMES-eng: 32338
      NUMBER_OF_BYTES : 5198254
      NUMBER_OF_BYTES-eng: 5198254
      _STATISTICS_WRITING_APP: mkvmerge v9.2.0 ('Photograph') 64bit
      _STATISTICS_WRITING_APP-eng: mkvmerge v9.2.0 ('Photograph') 64bit
      _STATISTICS_WRITING_DATE_UTC: 2016-10-04 14:07:11
      _STATISTICS_WRITING_DATE_UTC-eng: 2016-10-04 14:07:11
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
Stream mapping:
  Stream #0:4 -> #0:0 (ass (ssa) -> mov_text (native))
  Stream #0:0 -> #0:1 (copy)
  Stream #0:2 -> #0:2 (copy)
Press [q] to stop, [?] for help
frame=33081 fps=0.0 q=-1.0 Lsize=   61130kB time=00:22:59.74 bitrate= 363.0kbits/s speed=5.91e+03x
video:55051kB audio:5076kB subtitle:14kB other streams:0kB global headers:1kB muxing overhead: 1.644363%

答案1

MKVToolNix可以列出各种流的数量,但只能输出为mkv。

作为可以输出到 mp4 的 ffmpeg 的 GUI,有媒体转换器

非常容易使用,但是如果带有字幕的话,我必须编辑字幕编解码器并更改为 mov_text。

在此处输入图片描述

它可以转换为各种格式,且具有 ffmpeg 的所有功能和限制。

相关内容