I have a short and a long mp4 video. In the long video, I would like to replace the visual with a part of the visual of the short video. Additionally, I would like to keep the audio of the long video throughout.
The following set of commands work. However the concat and audio replacing seems to add a slight delay to the video, which makes the audio slightly out of sync from the video.
ffmpeg -ss 0 -i short.mp4 -t 2.0 -vcodec copy -an v1_short.mp4
ffmpeg -ss 0 -i long.mp4 -t 6.0 -vcodec copy -an v1_before.mp4
ffmpeg -ss 8.0 -i v_before.mp4 -vcodec copy -an v1_after.mp4.mp4
ffmpeg -i v1_before.mp4 -i v1_short.mp4 -i v1_after.mp4 -filter_complex "[0:v] [1:v] [2:v] concat=n=3:v=1 [v]" -map "[v]" out_temp.mp4
ffmpeg -i long.mp4 -i out_temp.mp4 -c copy -map 0:v -map 1:a out_final.mp4
How can I do this without the audio getting out of sync?
I am using ffmpeg version 4.0.2.
Related
I am combining a video stream, one audio stream (music), another audio stream with offset (speech) and subtitles. Now I am trying to fade out everything towards the end. I got it to work without the subtitles. Once I add the subtitles, the result no longer fades out properly. Here is what I am trying:
ffmpeg -ss 00:00:00 -i galaxy.mp4 -i acoustic.m4a -itsoffset 00:00:03 -i speech.m4a -to 00:00:15 \
-vf "fade=t=out:st=10:d=5" \
-vf "subtitles=speech-resync.srt" \
-af "afade=t=out:st=10:d=5" \
-map 0:v -map 1:a -map 2:a -c:v libx264 -c:a aac output.mp4 -y
If I remove the -vf "subtitle s=speech-resync.srt" argument, I get a working fade out but no subs. Ideas anyone?
Can't have multiple -vf options. Combine them as a single filter chain:
-vf "fade=t=out:st=10:d=5,subtitles=speech-resync.srt"
I edit the video with the command
ffmpeg -i video.mp4 -y -vf eq=saturation={rand_saturation},fade=in:st=0:d={rand_fade},hflip,noise=alls={rand_noise}:allf=t -c:a copy output.mp4
then the resulting video
ffmpeg -i output.mp4 -i logo.png -filter_complex "[0:v][1:v]overlay=x='if(lt(mod(t,10),5),1,W-w-10)':y='if(lt(mod(t,10),5),5,H-h-200)'" -c:a copy output_1.mp4
I tried to combine all this together so that I didn't have to spend time processing the video twice, but I couldn't do it because you can't use the -vf and -filter_complex commands together. How can this problem be solved?
First apply the video specific filters before using the result as overlay input.
ffmpeg -i video.mp4 -i logo.png -filter_complex "[0:v]eq=saturation={rand_saturation},fade=in:st=0:d={rand_fade},hflip,noise=alls={rand_noise}:allf=t[vid];[vid][1:v]overlay=x='if(lt(mod(t,10),5),1,W-w-10)':y='if(lt(mod(t,10),5),5,H-h-200)'" -c:a copy output_1.mp4
I'm trying to achieve what I asked in title, but FFMpeg produces a 0 byte size file.
Here is the code [not working]:
ffmpeg -i input.mkv -codec copy -i watermark.png -filter_complex '[0:v] scale=1920:-1,setsar=1:1; [1:v] overlay=0:0' output.mp4
if possible I want to do the whole thing in just 1 command.
Thanks
Try this:
ffmpeg -i input.mkv -i watermark.png \
-filter_complex '[0:v] scale=1920:-1,setsar=1:1[v]; [v][1:v]overlay=0:0[out]' \
-map [out] -an output.mp4
-codec copy - No can do if you want to apply filter
-an disables audio
Filtergraph: you were missing label [v] to connect to the chains.
I am trying to use FFMPEG to splice few videos and output one combined video.
I managed to get all video stream with this command :
ffmpeg.exe -i 1.mov -i 2.mov -filter_complex "[0:v]scale=1920:1080[v0];[1:v]scale=1920:1080[v1];[v0][v1] concat=n=2:v=1[v]" -map "[v]" out.mp4
Also, to add a dummy audio to a video with this command:
ffmpeg.exe -i 1.mov -f lavfi -i aevalsrc=0 -shortest -i out.mov
Above commands work perfectly, however 2.mov has an audio stream while 1.mov does not.
Is there any method that can set a dummy audio for 1.mov and then combine both video and audio streams from 1.mov and 2.mov at one go, so that output a combined video that can play sound when it is at clip 2.mov.
Use
ffmpeg.exe -i 1.mov -i 2.mov -f lavfi -t 1 -i anullsrc -filter_complex "[0:v]scale=1920:1080[v0];[1:v]scale=1920:1080[v1];[v0][2:a][v1][1:a] concat=n=2:v=1:a=1[v][a]" -map "[v]" -map "[a]" out.mp4
-f lavfi -t 1 -i anullsrc adds a silent 1 second audio input, which is used as a counterpart to the video input from 1.mov. The concat filter will pad the audio to match the video duration of 1.mov.
I have a few video files without any audio. I want to concatenate these videos to create a single video and then add a sound track (an mp3 file) to it. Currently I am doing it in two phases -
First concatenate videos...
ffmpeg -y -i video1.mp4 -i video2.mp4 -i video3.mp4 -filter_complex "[0:v:0] [1:v:0] [2:v:0] concat=n=3:v=1 [v]" -map "[v]" -c:v libx264 concat_video.mp4
and then add audio...
ffmpeg -y -i concat_video.mp4 -i sound_track.mp3 -shortest output.mp4
This produces fairly good output but it takes considerable amount of time.
I was wondering if there could be a single ffmpeg command that would do both and save time.
You just need to add your audio input and -map it:
ffmpeg -y -i video1.mp4 -i video2.mp4 -i video3.mp4 -i sound_track.mp3 -filter_complex "[0:v:0] [1:v:0] [2:v:0] concat=n=3:v=1:a=0 [v]" -map "[v]" -map 3:a -c:v libx264 -shortest output.mp4