在 ffmpeg 中添加静音音频 [英] adding silent audio in ffmpeg

查看:369
本文介绍了在 ffmpeg 中添加静音音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 ffmpeg 将无声音轨添加到 MOV 文件中.

I'm trying to use ffmpeg to add a silent audio track to a MOV file.

我创建了一个比视频更长的无声音轨,并打算在 ffmpeg 中使用 -shortest 选项.

I created a silent audio track longer than the video, and intend to use the -shortest option with ffmpeg.

使用 SoX v14.3.1,我运行它来生成一个 wav 文件:

Using SoX v14.3.1, I run this to generate a wav file:

sox -n -r 44100 -b 16 -c 2 -L silence.wav trim 0.0 60.000

# -n  = Sox's null file
# -r = sample rate 
# -b = bits per sample
# -c = num of channels
# -L = little endian
# filename
# trim - is an effect, args start and length.

我的基本 ffmpeg 命令如下所示:

My basic ffmpeg command looks like this:

ffmpeg -shortest 
-i silence.wav -acodec pcm_s16le 
-i vid_no_sound.mov -vcodec copy vid_with_sound.mov

这样做的结果是:

ffmpeg version 0.11.1 Copyright (c) 2000-2012 the FFmpeg developers
  built on Aug 27 2012 13:11:25 with gcc 4.4.5
  configuration: --extra-cflags=-static --prefix=/root/ffmpeg_build/src/ffmpeg-0.11.1 --enable-bzlib --enable-gnutls --enable-libfreetype --enable-libmp3lame --enable-libdc1394 --enable-libpulse --enable-librtmp --enable-libschroedinger --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-openssl --enable-zlib --enable-gpl --enable-nonfree --enable-version3
  libavutil      51. 54.100 / 51. 54.100
  libavcodec     54. 23.100 / 54. 23.100
  libavformat    54.  6.100 / 54.  6.100
  libavdevice    54.  0.100 / 54.  0.100
  libavfilter     2. 77.100 /  2. 77.100
  libswscale      2.  1.100 /  2.  1.100
  libswresample   0. 15.100 /  0. 15.100
  libpostproc    52.  0.100 / 52.  0.100
[wav @ 0x29ab2e0] max_analyze_duration 5000000 reached at 5015510
Guessed Channel Layout for  Input Stream #0.0 : stereo
Input #0, wav, from 'silence.wav':
  Duration: 00:01:00.00, bitrate: 1411 kb/s
    Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, stereo, s16, 1411 kb/s
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'vid_no_sound.mov':
  Metadata:
    major_brand     : qt
    minor_version   : 537199360
    compatible_brands: qt
    creation_time   : 2012-07-25 13:41:44
  Duration: 00:00:14.50, start: 0.000000, bitrate: 27457 kb/s
    Stream #1:0(eng): Video: qtrle (rle  / 0x20656C72), rgb24, 1920x1080, 27450 kb/s, SAR 1920:1920 DAR 16:9, 24 fps, 24 tbr, 24 tbn, 24 tbc
    Metadata:
      creation_time   : 2012-07-25 13:41:44
      handler_name    : Apple Alias Data Handler
    Stream #1:1(eng): Data: none (tmcd / 0x64636D74)
    Metadata:
      creation_time   : 2012-07-25 13:42:06
      handler_name    : Apple Alias Data Handler
      timecode        : 00:00:00:00
File 'vid_with_sound.mov' already exists. Overwrite ? [y/N] y
auto-inserting filter 'auto-inserted resampler 0' between the filter 'src' and the filter 'aformat'
[aresample @ 0x2ab3b00] chl:stereo fmt:s16 r:44100Hz -> chl:stereo fmt:flt r:44100Hz
[NULL @ 0x2994320] Codec is experimental but experimental codecs are not enabled, try -strict -2
Output #0, mov, to 'vid_with_sound.mov':
    Stream #0:0(eng): Video: qtrle (rle  / 0x20656C72), rgb24, 1920x1080 [SAR 1920:1920 DAR 16:9], q=2-31, 27450 kb/s, 24 fps, 90k tbn, 24 tbc
    Metadata:
      creation_time   : 2012-07-25 13:41:44
      handler_name    : Apple Alias Data Handler
    Stream #0:1: Audio: none, 44100 Hz, stereo, flt, 128 kb/s
Stream mapping:
  Stream #1:0 -> #0:0 (copy)
  Stream #0:0 -> #0:1 (pcm_s16le -> aac)
Error while opening encoder for output stream #0:1 - maybe incorrect parameters such as bit_rate, rate, width or height

我已尝试按照建议添加 -strict -2,但我不确定将其放在命令行的何处.

I have tried adding the -strict -2 as suggested, although I am not sure where to put it in the command line.

我花了两个小时尝试不同的东西并阅读 ffmpeg 文档,但我仍然被卡住了.

I've spent two hours trying different things and reading ffmpeg documentation, but I'm still stuck.

如何在 mov 文件中添加静音音轨?

How do I add a silent audio track to a mov file?

推荐答案

anullsrc audio过滤器

您可以使用 ffmpeg 创建无声音频并将其与视频合并.此示例将使用 anullsrc 音频过滤器 生成采样率为 44100 的立体声静音音频:

anullsrc audio filter

You can use ffmpeg to create the silent audio and combine it with a video in one step. This example will use the anullsrc audio filter to generate stereo silent audio with a sample rate of 44100:

ffmpeg -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 -i video.mov -c:v copy -c:a aac -shortest output.mov

  • channel_layout=stereo:sample_rate=44100 是默认设置,但我将其包含为如何使用这些选项的示例.
    • channel_layout=stereo:sample_rate=44100 is the default, but I included it just as an example of how to use these options.
    • 如果您的视频输入文件有您想要忽略的音频,请使用 -map 选项来覆盖默认的流选择行为:>

      If your video input file has audio that you want to ignore then use the -map option to override the default stream selection behavior:

      ffmpeg -f lavfi -i anullsrc -i video.mov -c:v copy -c:a aac -map 0:a -map 1:v -shortest output.mp4
      

      • -map 0:a -map 1:v 可以翻译为:从第一个输入(0)使用音频(a>),然后从第二个输入 (1) 使用视频 (v).
        • -map 0:a -map 1:v can be translated as: from the first input (0) use the audio (a), and from the second input (1) use the video (v).
          • 这些示例将流式复制视频,因此它不会重新- 编码(如复制和粘贴").

          • These examples will stream copy the video so it does not get re-encoded (like a "copy and paste").

          始终建议使用最新的 ffmpeg.最新版本的链接位于 FFmpeg 下载 页面上,或者您可以参考分步操作 编译指南ffmpeg.

          It is always recommended to use a recent ffmpeg. Links to recent builds are on the FFmpeg Download page or you can refer to a step-by-step guide to compile ffmpeg.

          这篇关于在 ffmpeg 中添加静音音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆