FFMPEG Input area failure - ffmpeg

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

Related

ffmpeg watermark: scale2ref output can't be used in second overlay

I was able to add a watermark to 2 position(top left & bottom right) of a video with scaling image height to tenth of the video height in one command
ffmpeg -hide_banner -i /path/to/input.mp4 -i /path/to/watermark.jpg -filter_complex "[1:v][0:v]scale2ref=oh*mdar:ih/10[logo-out][video-out];[video-out][logo-out]overlay=10:10[flag];[1:v][flag]scale2ref=oh*mdar:ih/10[logo-out2][video-out2];[video-out2][logo-out2]overlay=W-w-10:H-h-10" -c:a copy /path/to/output.mp4
But the above command is too redundant, so I remove the second scale2ref
ffmpeg -hide_banner -i /path/to/input.mp4 -i /path/to/watermark.jpg -filter_complex "[1:v][0:v]scale2ref=oh*mdar:ih/10[logo-out][video-out];[video-out][logo-out]overlay=10:10[flag];[flag][logo-out]overlay=W-w-10:H-h-10" -c:a copy /path/to/output.mp4
But sadly, error occurs
[mov,mp4,m4a,3gp,3g2,mj2 # 0x7fb195013c00] Invalid stream specifier: logo-out.
Last message repeated 1 times
Stream specifier 'logo-out' in filtergraph description [1:v][0:v]scale2ref=oh*mdar:ih/10[logo-out][video-out];[video-out][logo-out]overlay=10:10[flag];[flag][logo-out]overlay=W-w-10:H-h-10 matches no streams
I know error occurs because of the first overlay didn't set an image output specifier, but it seems we can't do this? I only know overlay can set a video stream specifier.
How can I use the [logo-out] specifier which output from scale2ref in the second overlay?
An output generated inside a filtergraph can only be consumed once. To reuse it, split it first.
ffmpeg -hide_banner -i /path/to/input.mp4 -i /path/to/watermark.jpg -filter_complex "[1:v][0:v]scale2ref=oh*mdar:ih/10[logo-out][video-out];[logo-out]split=2[logo-left][logo-right];[video-out][logo-left]overlay=10:10[flag];[flag][logo-right]overlay=W-w-10:H-h-10" -c:a copy /path/to/output.mp4

ffmpeg filter_complex trim out-sync

command line:
ffmpeg -i <INPUT> -filter-complex "<FILTER_COMPLEX>" -map "[ofa]" -map "[ofv]" -acodec aac -vcodec libx264 test.mp4
FILTER_COMPLEX content:
[0:v]split=3[sv1][sv2][sv3];
[0:a]asplit=3[sa1][sa2][sa3];
[sv1]trim=start=200:duration=5,setpts=PTS-STARTPTS[ov1];[sa1]atrim=start=200:duration=5[oa1];
[sv2]trim=start=300:duration=5,setpts=PTS-STARTPTS[ov2];[sa2]atrim=start=300:duration=5[oa2];
[sv3]trim=start=400:duration=5,setpts=PTS-STARTPTS[ov3];[sa3]atrim=start=400:duration=5[oa3];
[ov1][ov2][ov3]concat=n=3:v=1:a=0[ofv];
[oa1][oa2][oa3]concat=n=3:v=0:a=1[ofa]
As a result, the output video sounds are out of sync, and the video is redirected to 00:00:00, but the sound remains at the original time position.
Therefore, how to use ffmpeg to intercept several clips from a video, recombine them into a new video file, and keep the sound and picture synchronized.
I tried with [sa1]atrim=start=200:duration=5,setpts=PTS-STARTPTS[oa1] but an error:
Media type mismatch between the 'Parsed_atrim_4' filter output pad 0 (audio) and the 'Parsed_setpts_5' filter input pad 0 (video)
Cannot create the link atrim:0 -> setpts:0
Error initializing complex filters.
Invalid argument

ffmpeg width not divisible by 2 (375x500) error

i tried to scale the video to 375x500 using ffmpeg.
ffmpeg -i input.mp4 -s 375x500 -c:a copy output.mp4
Getting this error, [libx264 # 0x5639d358ad60] width not divisible by 2 (375x500)
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height.
I tried so many commands but i didnt get my solution.
libx264 requires width/height to be divisible by 2 when using the standard yuv420p pixel format. Refer to the many suggestions regarding how to fix the not divisible by 2 error with scale/pad/crop:
FFMPEG (libx264) “height not divisible by 2”
ffmpeg : width not divisible by 2 (when keep proportions)
ffmpeg add watermark libx264 width not divisible by 2 (853x480)
However, if you must have exactly 375x500 then you have to use a pixel format that supports this size:
ffmpeg -i input.mp4 -vf "format=yuv444p,scale=375:500" -c:a copy output.mp4
Drawback is that almost no player or device will be able to play it (unless it uses FFmpeg).
See the format and scale filter documentation and the output of ffmpeg -pix_fmts for more info.

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

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

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

Resources