本文介绍了如何使用ffmpeg从视频文件中删除一条曲目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用ffmpeg从视频文件容器(.vob或.mkv)中仅删除一个曲目(不是全部)?

How to remove only one track (not all) from video file container (.vob or .mkv) using ffmpeg?

我知道我可以将视频(-c:v copy -an)和特定的音轨从容器复制到两个单独的文件中,然后将它们加入.

I know I can just copy video (-c:v copy -an) and specific audio track from container into two separated files and then join them.

但是有更简单的方法吗?我可以从容器中删除特定的音轨吗? ffmpeg命令?

But is there an easier way? Can I just remove specific audio track from container? ffmpeg command?

推荐答案

最有效的方法是使用 -map选项中的否定映射" ,以排除特定的流(轨道"),同时保留所有其他流.

The most efficient method is to use negative mapping in the -map option to exclude specific stream(s) ("tracks") while keeping all other streams.

ffmpeg -i input -map 0 -map -0:a:2 -c copy output

  • -map 0从输入中选择所有流.
  • -map -0:a:2然后取消选择音频流3.流索引从0开始计数,因此音频流10将为0:a:9.
    • -map 0 selects all streams from the input.
    • -map -0:a:2 then deselects audio stream 3. The stream index starts counting from 0, so audio stream 10 would be 0:a:9.
    • ffmpeg -i input -map 0 -map -0:a -c copy output
      

      • -map 0从输入中选择所有流.
      • -map -0:a然后从输入中取消选择所有音频流.
        • -map 0 selects all streams from the input.
        • -map -0:a then deselects all audio streams from the input.
        • 保留除音频流#3和#6以外的所有内容:

          Keep everything except audio streams #3 and #6:

          ffmpeg -i input -map 0 -map -0:a:3 -map -0:a:6 -c copy output
          

          删除所有字幕和数据

          ffmpeg -i input -map 0 -map -0:s -map -0:d -c copy output
          

          仅包含视频和音频

          此示例不需要使用任何否定映射.

          Only include video and audio

          This example does not need to use any negative mapping.

          ffmpeg -i input -map 0:v -map 0:a -c copy output
          

          删除其他流/曲目类型

          如果您要删除其他流类型,则可以使用相应的流说明符.

          • v-视频,例如-map -0:v
          • a-音频,例如-map -0:a(如上所示)
          • s-字幕,例如-map -0:s
          • d-数据,例如-map -0:d
          • t-附件,例如-map -0:t
          • v - video, such as -map -0:v
          • a - audio, such as -map -0:a (as shown above)
          • s - subtitles, such as -map -0:s
          • d - data, such as -map -0:d
          • t - attachments, such as -map -0:t

          使用立体声输入和 channelsplit 过滤器.仅获取正确频道并输出单声道音频文件的示例:

          Using a stereo input and channelsplit filter. Example to get the right channel only and output a mono audio file:

          ffmpeg -i stereo.wav -filter_complex "[0:a]channelsplit=channel_layout=stereo:channels=FR[right]" -map "[right]" front_right.wav
          

          • channel_layout是输入流的通道布局.默认值为stereo.

            • channel_layout is the channel layout of the input stream. The default is stereo.

              channels列出要提取的通道作为单独的输出流.默认值为all,它将每个输入通道提取为单独的单独流.

              channels lists the channels to be extracted as separate output streams. The default is all which extracts each input channel as a separate, individual stream.

              有关可接受的通道布局(用于channel_layout选项)和通道名称(用于channels选项)的列表,请参见ffmpeg -layouts.

              See ffmpeg -layouts for a list of accepted channel layouts (for channel_layout option) and channel names (for channels option).

              有关更多示例,请参见 FFmpeg Wiki:音频通道.

              See FFmpeg Wiki: Audio Channels for more examples.

              • -map option documentation
              • FFmpeg Wiki: Map

              这篇关于如何使用ffmpeg从视频文件中删除一条曲目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 19:44