如何使用 ffmpeg 命名音轨

如何使用 ffmpeg 命名音轨

当文件有更多音轨时,VLC 可以在“音频”>“音轨”下的菜单中显示它们的名称(或标题,我不确定这个术语)。

当我用

ffmpeg -i input.mp4 -map 0:0 -map 0:1 -map 0:2  -c:v libx264 -preset slow -profile:v high -crf 17  -c:a copy output.mp4

名称丢失,只显示通用的“Track 1”和“Track 2”。我该如何保留它?或者我该如何设置自定义名称。

该命令的输出如下:

ffmpeg -ss 0 -i Shades_of_winter_24FPS_x264_5.1_AC3+R128.mp4 -map 0:0 -map 0:1 -map 0:2  -vf "ass=p.ass"  -c:v libx264 -preset slow -profile:v high -crf 17  -c:a copy -metadata:s:a:0:0 -language="ble" -metadata:s:a:1 language="bli" -metadata:s:a:0:2 title="bla"  -t 6 a.mp4
ffmpeg version 2.3.git-1ace957 Copyright (c) 2000-2014 the FFmpeg developers
  built on Jul 26 2014 20:25:06 with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
  configuration: --extra-libs=-ldl --prefix=/opt/ffmpeg --enable-avresample --disable-debug --enable-nonfree --enable-gpl --enable-version3 --enable-x11grab --enable-libpulse --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-decoder=amrnb --disable-decoder=amrwb --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-libvorbis --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libspeex --enable-libass --enable-avisynth --enable-libsoxr
  libavutil      52. 92.101 / 52. 92.101
  libavcodec     55. 69.100 / 55. 69.100
  libavformat    55. 49.100 / 55. 49.100
  libavdevice    55. 13.102 / 55. 13.102
  libavfilter     4. 11.102 /  4. 11.102
  libavresample   1.  3.  0 /  1.  3.  0
  libswscale      2.  6.100 /  2.  6.100
  libswresample   0. 19.100 /  0. 19.100
  libpostproc    52.  3.100 / 52.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Shades_of_winter_24FPS_x264_5.1_AC3+R128.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isomavc1
    creation_time   : 2014-10-04 00:16:47
    encoder         : HandBrake 0.9.9 2013051800
  Duration: 00:51:22.63, start: 0.000000, bitrate: 19802 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 18780 kb/s, 24 fps, 24 tbr, 90k tbn, 180k tbc (default)
    Metadata:
      creation_time   : 2014-10-04 00:16:47
      encoder         : JVT/AVC Coding
    Stream #0:1(und): Audio: ac3 (ac-3 / 0x332D6361), 48000 Hz, 5.1(side), fltp, 640 kb/s (default)
    Metadata:
      creation_time   : 2014-10-04 00:16:47
    Stream #0:2(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 197 kb/s
    Metadata:
      creation_time   : 2014-10-12 23:08:29
File 'a.mp4' already exists. Overwrite ? [y/N] y
[Parsed_ass_0 @ 0x1a682a0] Added subtitle file: 'p.ass' (7 styles, 9 events)
[libx264 @ 0x1a87be0] using SAR=1/1
[libx264 @ 0x1a87be0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x1a87be0] profile High, level 5.0
[libx264 @ 0x1a87be0] 264 - core 142 r2389 956c8d8 - H.264/MPEG-4 AVC codec - Copyleft 2003-2014 - http://www.videolan.org/x264.html - options: cabac=1 ref=5 deblock=1:0:0 analyse=0x3:0x113 me=umh subme=8 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=2 b_bias=0 direct=3 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=24 scenecut=40 intra_refresh=0 rc_lookahead=50 rc=crf mbtree=1 crf=17.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
[mp4 @ 0x1a86a20] track 1: codec frame size is not set
Output #0, mp4, to 'a.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isomavc1
    encoder         : Lavf55.49.100
    Stream #0:0(und): Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=-1--1, 24 fps, 12288 tbn, 24 tbc (default)
    Metadata:
      creation_time   : 2014-10-04 00:16:47
      encoder         : Lavc55.69.100 libx264
    Stream #0:1(und): Audio: ac3 ([165][0][0][0] / 0x00A5), 48000 Hz, 5.1(side), 640 kb/s (default)
    Metadata:
      creation_time   : 2014-10-04 00:16:47
      -language       : ble
      title           : bla
    Stream #0:2(bli): Audio: aac ([64][0][0][0] / 0x0040), 44100 Hz, stereo, 197 kb/s
    Metadata:
      creation_time   : 2014-10-12 23:08:29
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (copy)
  Stream #0:2 -> #0:2 (copy)
Press [q] to stop, [?] for help
[Parsed_ass_0 @ 0x1a682a0] Neither PlayResX nor PlayResY defined. Assuming 384x288
frame=  144 fps= 79 q=-1.0 Lsize=     651kB time=00:00:06.01 bitrate= 886.3kbits/s    
video:122kB audio:522kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.122499%
[libx264 @ 0x1a87be0] frame I:1     Avg QP: 2.17  size:  7785
[libx264 @ 0x1a87be0] frame P:48    Avg QP:11.31  size:  2128
[libx264 @ 0x1a87be0] frame B:95    Avg QP:11.73  size:   151
[libx264 @ 0x1a87be0] consecutive B-frames: 11.1%  1.4%  4.2% 83.3%
[libx264 @ 0x1a87be0] mb I  I16..4: 99.1%  0.0%  0.9%
[libx264 @ 0x1a87be0] mb P  I16..4:  0.1%  0.1%  0.2%  P16..4:  1.1%  0.2%  0.1%  0.0%  0.0%    skip:98.1%
[libx264 @ 0x1a87be0] mb B  I16..4:  0.0%  0.0%  0.0%  B16..8:  0.4%  0.0%  0.0%  direct: 0.0%  skip:99.5%  L0:51.3% L1:43.9% BI: 4.8%
[libx264 @ 0x1a87be0] 8x8 transform intra:4.3% inter:28.6%
[libx264 @ 0x1a87be0] direct mvs  spatial:92.6% temporal:7.4%
[libx264 @ 0x1a87be0] coded y,uvDC,uvAC intra: 5.4% 2.2% 2.2% inter: 0.2% 0.0% 0.0%
[libx264 @ 0x1a87be0] i16 v,h,dc,p: 97%  1%  2%  0%
[libx264 @ 0x1a87be0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu:  2%  3% 94%  0%  0%  0%  0%  0%  0%
[libx264 @ 0x1a87be0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 36% 15% 19%  4%  6%  5%  5%  4%  5%
[libx264 @ 0x1a87be0] i8c dc,h,v,p: 98%  0%  1%  0%
[libx264 @ 0x1a87be0] Weighted P-Frames: Y:39.6% UV:0.0%
[libx264 @ 0x1a87be0] ref P L0: 72.3%  8.1% 14.8%  2.8%  1.6%  0.3%  0.1%
[libx264 @ 0x1a87be0] ref B L0: 58.4% 29.7%  8.5%  3.5%
[libx264 @ 0x1a87be0] ref B L1: 95.3%  4.7%
[libx264 @ 0x1a87be0] kb/s:165.74

答案1

您可以将元数据应用于特定流。此示例将向音频流/音轨 1 和 2 添加元数据(注意title从0 开始计数)。languageffmpeg

ffmpeg -i input.mp4 -map 0 -c copy -metadata:s:a:0 title="One" -metadata:s:a:1 title="Two" -metadata:s:a:0 language=eng -metadata:s:a:1 language=spa output.mp4
  • -map 0从中选择所有流input.mp4,否则为默认流选择行为对于每种流类型仅选择 1 个流。

  • -c copy启用流复制模式以避免重新编码。

  • -metadata:s:a:0 title="One"将标题设置One为音频 0。

  • -metadata:s:a:1 title="Two"将标题设置Two为音频 1。

  • -metadata:s:a:0 language=eng将音频 0 设置为英语。

  • -metadata:s:a:1 language=spa将音频 1 设置为西班牙语。

有关详细信息,请-metadata查找-map_metadata文档

相关内容