ffmpeg - trying to add a reversed section of original video to the back (boomerang effect) - ffmpeg

I have a ffmpeg command as follows which basically scales the video down to 720p. Now i want to add a section to my command which will make a concatination of the video but in reverse. So that the video will also be in a loop like this:
0s -> 10s -> 0s
original command:
ffmpeg -ss 0.0 -to 10.0 -i in.mp4 -filter_complex "fps=15,scale=720:-1" -y out.mp4
Command after my edits:
ffmpeg -ss 0.0 -to 10.0 -i in.mp4 -filter_complex "[0:v]fps=15,scale=720:-1,reverse,fifo[r];[0:v][r] concat=n=2:v=1 [v]" -map "[v]" -y out.mp4
When executing im getting following erorrs:
Parsed_concat_4 # 0x7feb89d01d40] Input link in1:v0 parameters (size 720x1280, SAR 1:1) do not match the corresponding output link in0:v0 parameters (1080x1920, SAR 1:1)
[Parsed_concat_4 # 0x7feb89d01d40] Failed to configure output pad on Parsed_concat_4
Error reinitializing filters!
Failed to inject frame into filter network: Invalid argument
Error while processing the decoded data for stream #0:1
I'm very new into coding advanced ffmpeg commands.

Input link in1:v0 parameters (size 720x1280, SAR 1:1) do not match
the corresponding output link in0:v0 parameters (1080x1920, SAR 1:1)
The concat filter requires all inputs to be the same size and aspect ratio, but you are attempting to concatenate different sizes and aspect ratios. To fix this you can also scale the other segments to be concatenated.
You can use the split filter to efficiently duplicate outputs from other filters, then reverse one of the duplicates, and finally concat everything together.
ffmpeg -to 10 -i in.mp4 -filter_complex "[0:v]fps=15,scale=720:-1,split=3[begin][mid][end];[mid]reverse[r];[begin][r][end]concat=n=3:v=1:a=0[v]" -map "[v]" out.mp4

Related

Extract first frame of multi video streams video

I am curious about how to use FFmpeg in order to extract the first frame of the first video stream from a multi-video stream file.
What I have so far is:
ffmpeg -i {mediaFile} -ss 0 -map 0:v -vframes 1 -f image2 firstFrame.jpeg.
I am not sure about the -map part. How can be certain that I work on the first video stream? Is there a way to first filter streams by codec type, then select the first and then extract the frame?
Thanks.
ffmpeg -i {mediaFile} -map 0:v:0 -frames:v 1 firstFrame.jpeg
Add an input stream index to your -map as shown in the example above. 0:v:0 is input #0:video:stream #0. Note that ffmpeg starts counting from 0. If you wanted video stream #3, it would be 0:v:2.
I removed the superfluous options from your command.
Also see
-map option documentation
How can I extract a good quality JPEG image from a video with ffmpeg?

FFMPEG Input area failure

I'm trying to convert an input clip to a fixed, padded output and applying an overlay on it.
This command works fine for resizing:
ffmpeg -y -i clip.mp4 -vf scale="min(iw*375/ih\,500):min(375\,ih*500/iw),pad=500:375:(500-iw)/2:(375- ih)/2" output.mp4
I created the following one to make sure the overlay would be created:
ffmpeg -y -i clip.mp4 -i clip_overlay.png -strict -2 -filter_complex "[0]scale=min(iw*375/ih\,500):min(375\,ih*500/iw),pad=500:375:(500-iw)/2:(375-ih)/2[v];[v][1]overlay=x=W-w-5:y=H-h-5" output.mp4
I cannot find the error, but ffmpeg returns:
[Parsed_pad_1 # 0x2eae8e0] Input area 144:0:355:375 not within the padded area 0:0:500:374 or zero-sized
[Parsed_pad_1 # 0x2eae8e0] Failed to configure input pad on Parsed_pad_1
Error reinitializing filters!
Failed to inject frame into filter network: Invalid argument
Error while processing the decoded data for stream #1:0
[aac # 0x2eb3020] Qavg: 102.113
[aac # 0x2eb3020] 2 frames left in the queue on closing
Why does that upper command work, and combined with the second one, it doesn't?
The most common pixel format in a typical MP4 video stream is yuv420p and the default encoder (x264) requires that the dimensions be even.
So, set pad to use even dimensions,
ffmpeg -y -i clip.mp4 -i clip_overlay.png -strict -2 -filter_complex "[0]scale=min(iw*375/ih\,500):min(375\,ih*500/iw),pad=500:376:(500-iw)/2:(376-ih)/2[v];[v][1]overlay=x=W-w-5:y=H-h-5" output.mp4

Getting Exception while merging two file with ffmpeg

I am trying to merge two mp4 files using ffmpeg command. My input files are not in same encoding so they are not merge with normal command. I have use below command but got exception.
Command: -
ffmpeg -i File_1.mp4 -i File_2.mp4 -filter_complex "[0:v]setsar=1[0v];[1:v]scale=720:576:force_original_aspect_ratio=decrease,setsar=1,pad=720:576:(ow-iw)/2:(oh-ih)/2[1v];[0v][0:a][1v][1:a]concat=n=2:v=1:a=1[outv][outa]" -map "[outv]" -map "[outa]" -c:v libx264 -crf 23 ffmpeg1.mp4
Exception I have got: -
[Parsed_concat_4 # 00000000067ea380] Input link in1:v0 parameters (size 720x576, SAR 1:1) do not match the corresponding
output link in0:v0 parameters (320x240, SAR 1:1)
[Parsed_concat_4 # 00000000067ea380] Failed to configure output pad on
Parsed_concat_4
Error reinitializing filters!
Failed to inject frame into filter network: Invalid argument
Error while processing the decoded data for stream #1:0
Conversion failed!
Please tell me what is the solution for that or any command which can help me out with merge any two mp4 file in windows using cmd.
The concat filter requires all its video inputs to have the same resolution and sample aspect ratio. The framerate and pixel format can differ, though the output may not be what you want.
So, in this command, alter the filtering of the first video input to match the second.
ffmpeg -i File_1.mp4 -i File_2.mp4 -filter_complex "[0:v]scale=720:576:force_original_aspect_ratio=decrease,setsar=1,pad=720:576:(ow-iw)/2:(oh-ih)/2[0v];[1:v]scale=720:576:force_original_aspect_ratio=decrease,setsar=1,pad=720:576:(ow-iw)/2:(oh-ih)/2[1v];[0v][0:a][1v][1:a]concat=n=2:v=1:a=1[outv][outa]" -map "[outv]" -map "[outa]" -c:v libx264 -crf 23 ffmpeg1.mp4

how to use ffmpeg to apply 1:1 SAR before concat on large complex filter

I use ffmpeg to concat videos in a fashion similar to this:
I ran into a weird error with my inputs
[Parsed_concat_0 # 000000002a05bb80] Input link in10:v0 parameters (size 1280x720, SAR 2049:2048)
do not match the corresponding output link in0:v0 parameters (1280x720, SAR 1:1)
From what I've researched I need to use setsar to force all the videos to be 1:1 before I concat, but I'm not sure how to do that in my filter.
Add the setsar filter:
ffmpeg -i 0.mp4 -i 1.mp4 -i 2.mp4 -filter_complex "[0:v]setsar=1[v0];[v0][1:v][2:v]concat=n=3:v=1:a=0[v]" -map "[v]" out.mp4
This example is assuming that 0.mp4 is the video with the wrong SAR.

ffmpeg - Input link in1:v0 parameters (size 640x640, SAR 16:9) do not match the corresponding output link in0:v0 parameters (640x640, SAR 427:240)

I'm trying to concat 4 mp4 files. I'm using the command below but not able to concat
ffmpeg -i new1.mp4 -i new2.mp4 -i new3.mp4 -i new4.mp4 -filter_complex concat=n=4:v=1:a=1 output.mp4
Getting this error :
Input link in1:v0 parameters (size 640x640, SAR 16:9) do not match the corresponding output link in0:v0 parameters (640x640, SAR 427:240)
All four vides has the same codec and same size (640x640) and the same bitrate (30)
What I am doing wrong?
The inputs don't have identical sample aspect ratios. Try
ffmpeg -i new1.mp4 -i new2.mp4 -i new3.mp4 -i new4.mp4 -filter_complex \
"[0]setdar=16/9[a];[1]setdar=16/9[b];[2]setdar=16/9[c];[3]setdar=16/9[d]; \
[a][b][c][d]concat=n=4:v=1:a=1" output.mp4
Here is one more simple way https://stackoverflow.com/a/48853654/6465520
ffmpeg -i input1.mp4 -i input2.mp4 -filter_complex "[0:v]scale=1024:576:force_original_aspect_ratio=1[v0]; [1:v]scale=1024:576:force_original_aspect_ratio=1[v1]; [v0][0:a][v1][1:a]concat=n=2:v=1:a=1[v][a]" -map [v] -map [a] output.mp4
So, first you scale all input videos to the same resolution and then concatenate them.
UPD
The answer above does not work for videos with different aspect ratio. I constructed another filter, which first scales the videos to the desired resolution, adding a black padding if necessary, and then concats them:
ffmpeg -i 1.mp4 -i 2.mp4 -n -filter_complex "[0:v]scale=1280:720:force_original_aspect_ratio=decrease:eval=frame,pad=1280:720:-1:-1:color=black[v0]; [1:v]scale=1280:720:force_original_aspect_ratio=decrease:eval=frame,pad=1280:720:-1:-1:color=black[v1]; [v0][0:a][v1][1:a] concat=n=2:v=1:a=1 [v] [a]" -map [v] -map [a] -s hd720 -vcodec libx264 result1.mp4

Resources