Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create muted video and black screen video with FFmpeg

Tags:

ffmpeg

I'm trying to use FFmpeg to generate the following from a local mp4 file:

  • A copy of the original video with no audio
  • A copy of the original video with audio but without visuals (a black screen instead). This file also needs to be in mp4 format.

After reading through the documentation I am struggling to get the terminal commands right. To remove the audio I have tried this command without any success:

ffmpeg -i file.mp4 -map 0:0 -map 0:2 -acodec copy -vcodec copy

Could anyone guide me towards how to accomplish this?

like image 228
user2685832 Avatar asked Sep 22 '17 13:09

user2685832


2 Answers

Create black video and silent audio

Use the color and anullsrc filters. Example to make 10 second output, 1280x720, 25 frame rate, stereo audio, 44100 sample rate:

ffmpeg -f lavfi -i color=size=1280x720:rate=25:color=black -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 -t 10 output.mp4

Remove audio

Only keep video:

ffmpeg -i input.mp4 -map 0:v -c copy output.mp4

Keep everything except audio:

ffmpeg -i input.mp4 -map 0 -map -0:a -c copy output.mp4

See FFmpeg Wiki: Map for more info on -map.

Make video black but keep the audio

Using the drawbox filter.

ffmpeg -i input.mp4 -vf drawbox=color=black:t=fill -c:a copy output.mp4

Generate silent audio

See How to add a new audio (not mixing) into a video using ffmpeg? and refer to the anullsrc example.

like image 160
llogan Avatar answered Nov 08 '22 22:11

llogan


To remove the audio you can use this:

ffmpeg -i file.mp4 -c copy -an file-nosound.mp4

notice the -an option

-an (output) Disable audio recording.

To keep audio but "replace" the video with a black screen, you could do this:

ffmpeg -i file.mp4 -i image.png -filter_complex overlay out.mp4

image.png is a black wallpaper that is placed on top of the video, but there should be better ways of full removing the frames, you could either extract the audio and later create a new video with the audio as a background

like image 38
nbari Avatar answered Nov 08 '22 23:11

nbari