Mark Dagger
Mark Dagger

Reputation: 13

ffmpeg merge silent video with another video+audio

I want to create, in a single command, a video from 3 sources:

  1. a silent background video;
  2. a smaller video to be overlayed (same length of 1), KEEPING its AUDIO;
  3. a PNG logo to be overlayed

I can create the video but cannot get the audio track. I don't understand if -vf is supposed to work in this case. This is what I've tried to do :

ffmpeg.exe -y -i MASTER_SILENT_VIDEO.mp4 -vf "movie=SMALLER_VIDEO_WITH_AUDIO.flv, scale=320:-1[inner];movie=MY_LOGO.png[inner2]; [in][inner] overlay=800:480,amerge [step1]; [step1][inner2] overlay=30:30 [out]" completed.mp4

The "amerge" filter should do the audio merging job, but of course it doesn't work. I've found similar questions involving -map or filtergraph but they refer to mixing a video source and an audio source; I tried several filtergraph examples without success. Any idea?

Upvotes: 1

Views: 1949

Answers (1)

llogan
llogan

Reputation: 133713

overlay one video over other using audio from one input

Use -filter_complex, eliminate the movie source filters, and explicitly define output streams with -map:

ffmpeg -y -i main.mp4 -i overlay_with_audio.flv -i logo.png -filter_complex
"[1:v]scale=320:-1[scaled];
 [0:v][scaled]overlay=800:480[bg];
 [bg][2:v]overlay=30:30,format=yuv420p[video]"
-map "[video]" -map 1:a -movflags +faststart
output.mp4

You may have to provide additional options to the overlay filters depending on the length of the inputs and how you want overlay to react, but because you did not provide the complete console output from your command I had to make a generic, less efficient, and possibly incorrect example.

overlay one video over other merging audio from both inputs

ffmpeg -y -i main.mp4 -i overlay_with_audio.flv -i logo.png -filter_complex
"[1:v]scale=320:-1[scaled];
 [0:v][scaled]overlay=800:480[bg];
 [bg][2:v]overlay=30:30,format=yuv420p[video];
 [0:a][1:a]amerge=inputs=2[audio]"
-map "[video]" -map "[audio]" -ac 2 -movflags +faststart
output.mp4

I'm assuming both inputs are stereo and that you want a stereo output. Also see FFmpeg Wiki: Audio channel Manipulation - 2 × stereo → stereo.

Upvotes: 3

Related Questions