I would like to cut (mulicut if possible else it's ok) a mp4 and generate the cut + a preview file in 360p.
My goal is to achieve something that looks like that :
`ffmpeg -y -progress /dev/stdout -i media.mp4
-vf "select='+between(t,0,25)',setpts=N/FRAME_RATE/TB"
-af "aselect='+between(t,0,25)’,asetpts=N/SR/TB"
-filter_complex split=2[mvideo][pvideo]
-map [mvideo] media_cut.mp4
-map [pvideo] -vf scale=-1:360 media_preview.mp4`
Here, a first -vf select filter to multicut the media, a split filter to generate both the cut media and a resized cut with a second -vf on scale that keep aspect ratio with a width of 360.
I can't mix filter with filter complex that's why i have no idea how to do it.
Thanks a lot for your tips.
You can do it one of two ways. 1) declare simple filtergraph for each output, or 2) do all filtering inside a complex filtergraph.
#1 Per-output simple filtergraph.
ffmpeg -y -progress /dev/stdout -i media.mp4
-vf "select='between(t,0,25)',setpts=N/FRAME_RATE/TB"
-af "aselect='between(t,0,25)’,asetpts=N/SR/TB"
media_cut.mp4
-vf "select='between(t,0,25)',setpts=N/FRAME_RATE/TB,scale=-2:360"
-af "aselect='between(t,0,25)’,asetpts=N/SR/TB"
media_preview.mp4
#2 A complex filtergraph.
ffmpeg -y -progress /dev/stdout -i media.mp4
-filter_complex
"[0:v]select='between(t,0,25)',setpts=N/FRAME_RATE/TB,split=2[mvideo][pvideo];
[pvideo]scale=-2:360[pvideo];
[0:a]aselect='between(t,0,25)’,asetpts=N/SR/TB,asplit=2[maudio][paudio]"
-map [mvideo] -map [maudio]
media_cut.mp4
-map [pvideo] -map [paudio]
media_preview.mp4
Related
I am using FFmpeg to speed up a video and add a watermark. The watermark is a percentage of the video size.
To speed up I am using
ffmpeg -i input.mp4 -filter_complex "[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a]" -map "[v]" -map "[a]" output.mp4
And to add a watermark, I am using
ffmpeg -i input.mp4 -i watermark.png -filter_complex "[1][0]scale2ref=w=oh*mdar:h=ih*0.1[logo][video];[video][logo]overlay=5:H-h-5" -c:a copy output.mp4
Both work well on their own. I am trying to combine them into a single command. There are many questions/answers regarding similar problems that I could find, however they seem to either be outdated or I just can't get them to work.
To combine filters I have read to just add a comma, but that doesn't seem to work:
ffmpeg -i input.mp4 -i watermark.png -filter_complex "[1][0]scale2ref=w=oh*mdar:h=ih*0.1[logo][video];[video][logo]overlay=5:H-h-5,[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a]" -map "[v]" -map "[a]" output.mp4
The command will run without errors, and add the watermark, but the audio/video filter is not being applied.
How can I do it?
Combined command:
ffmpeg -i input.mp4 -i watermark.png -filter_complex "[1][0]scale2ref=w=oh*mdar:h=ih*0.1[logo][video];[video][logo]overlay=5:H-h-5,setpts=0.5*PTS;[0:a]atempo=2.0" output.mp4
Connect linear filters with a comma. Connect filterchains with a semicolon. See FFmpeg Filtering Intro.
I want to combine some videos with some specific features like(video Speed, volume increase, resolution, rotation, framerate) of the final output of the video
We can do this process in 2 steps like
Combine video
ffmpeg -i test1.mp4 -i test2.mp4 -filter_complex [0:v:0][0:a:0][1:v:0][1:a:0]concat=n=2:v=1:a=1[outv][outa] -map [outv] -map [outa] output.mp4
Then apply filters
ffmpeg -i output.mp4 -filter:a volume=1.0,atempo=1.0 -vf transpose=2,setpts=1/1.0*PTS,scale=3840X2160,fps=30 final.mp4
I can do it this way but is there any way to do it in 1 step
thank you
You have to apply the filters after concat.
ffmpeg -i test1.mp4 -i test2.mp4 -filter_complex [0:v:0][0:a:0][1:v:0][1:a:0]concat=n=2:v=1:a=1[v][a];[v]transpose=2,setpts=1/1.0*PTS,scale=3840X2160,fps=30[outv];[a]volume=1.0,atempo=1.0[outa] -map [outv] -map [outa] output.mp4
I have these two filters that respectively, work just fine, but I can't seem to combine them.
Overlay with opacity
ffmpeg -i test.mp4 -i bar.png -filter_complex "[1:v]format=argb,geq=r='r(X,Y)':a='0.5*alpha(X,Y)'[zork]; [0:v][zork]overlay" -vcodec libx264 myresult.mp4
Overlay with left to right movement
ffmpeg -i test.mp4 -i bar.png -filter_complex "[0:v][1:v]overlay=x='if(lte(-w+(t)*100,100),-w+(t)*100,100)':y=0[out]" -map "[out]" -y out.mp4
End goal is to have my input picture with 0.5 opacity, and animated moving left to right.
Combined command:
ffmpeg -i test.mp4 -i bar.png -filter_complex "[1:v]format=argb,geq=r='r(X,Y)':a='0.5*alpha(X,Y)'[zork];[0:v][zork]overlay=x='if(lte(-w+(t)*100,100),-w+(t)*100,100)':y=0" output.mp4
I want to apply volume increase, brightness increase and placing the logo in top right of the video.
Please correct me:
ffmpeg -y -i input_video_path -i logo_path -filter_complex "[0:1]volume=volume=6dB:precision=fixed;[0:0]eq=gamma=1.5:saturation=1.3;[1:0]overlay= main_w-(overlay_w + 10): 10" -pix_fmt yuvj420p output_video_path
I am getting this error after apply this:
Cannot find a matching stream for unlabeled input pad 1 on filter Parsed_overlay_2
You need to provide labels for each filter:
ffmpeg -y -i input_video_path -i logo_path -filter_complex "[0:a]volume=volume=6dB:precision=fixed[a];[0:v]eq=gamma=1.5:saturation=1.3[bg];[bg][1:0]overlay=main_w-(overlay_w + 10):10,format=yuvj420p[v]" -map "[v]" -map "[a]" output_video_path
See FFmpeg Filtering Introduction for an illustrated example.
ffmpeg -i foo.mp4 -filter_complex "fade=d=0.5, reverse, fade=d=0.5, reverse" output.mp4
can be used to fade in and out foo.mp4 video. (we do not care about audio). According to https://video.stackexchange.com/questions/19867/how-to-fade-in-out-a-video-audio-clip-with-unknown-duration
It's good but only works in the simple situation of 1 input video, and 1 output. Now, how can I apply the fade in and out effect in the following more complex situation? I'm trying to concat a.jpg (a picture) with bar.mp4. I want only the bar.mp4 portion to fade in and out.
ffmpeg -loop 1 -t 2 -framerate 1 -i a.jpg -f lavfi -t 2 -i anullsrc -r 24 -i bar.mp4 -filter_complex "[0][1][2:v][2:a] concat=n=2:v=1:a=1 [vpre][a];[vpre]fps=24[v]" -map "[v]" -map "[a]" out.mp4 -y
Of course, I could first create a temporary temp.mp4 from bar.mp4 by running the first command, then input temp.mp4 in my second command. This involves an extra step and extra encoding. Could anyone help fix the commands or suggest something even better?
Use
ffmpeg -loop 1 -t 2 -framerate 24 -i a.jpg -f lavfi -t 2 -i anullsrc -r 24 -i bar.mp4 -filter_complex "[2:v]fade=d=0.5, reverse, fade=d=0.5, reverse[v2];[0][1][v2][2:a] concat=n=2:v=1:a=1 [v][a]" -map "[v]" -map "[a]" out.mp4 -y