Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding silent audio in ffmpeg

Tags:

ffmpeg

People also ask

How do I play audio with FFmpeg?

In order to use the FFmpeg as an audio playback tool you can untilize FFplay (available for Windows and for Linux). It's as simple as: ffplay <input audio track> The audio track must be of a supported format, meaning you will need some libraries.


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 is the default, but I included it just as an example of how to use these options.

Ignoring existing audio

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 can be translated as: from the first input (0) use the audio (a), and from the second input (1) use the video (v).

Notes

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

  • 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.


Here's a command for the latest ffmpeg, works with MP4 (H264/AVC):

ffmpeg -f lavfi -i aevalsrc=0 -i input.mp4 -c:v copy -c:a aac -map 0 -map 1:v -shortest output.mp4

Create video from image or convert image into video then add slient audio using ffmpeg.

You can use the anullsrc audio source filter in ffmpeg. Example to make a 5.1 channel, 48000 Hz sample rate, 10 seconds silent video file from image:

ffmpeg -loop 1 -i img002.jpg -f lavfi -i anullsrc=channel_layout=5.1:sample_rate=48000 -t 10 -c:v libx264 -t 10 -pix_fmt yuv420p -vf scale=480:320 -y output.mp4

img002.jpg: Input image file

-i anullsrc: Add silent audio

-t 10: Number of seconds

scale=480:320: Video resolution width=420 and height=320

-y: Overwrite existing output file

output.mp4: Output file


Order matters. I have tried the sox command above and the ffmpeg command below and it works

ffmpeg -shortest -i silence.wav -acodec pcm_s16le -i out.mov -vcodec copy -strict -2 vid_with_sound.mov