ffmpeg width not divisible by 2 (375x500) error - ffmpeg

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.

Related

Converting images to video keeping GOP 1 using ffmpeg

I have a list of images, containing incremental integer values saved in png format starting from number 1, which need to be converted to a video with GOP 1 using ffmpeg. I have used the following command to convert the images to video and subsequently used ffplay to seek to a particular frame. The displayed frame doesn't match the frame being seek. Any help?
ffmpeg -i image%03d.png -c:v libx264 -g 1 -pix_fmt yuv420p out.mp4

ffmpeg - why does hstack fail with " width not divisible by 2" When both of my inputs have even heights?

Here's the command I'm using to horizontally stack 2 mp4's together:
ffmpeg -y -i input1.mp4 -i input2.mp4 -filter_complex "[0:v][1:v]hstack[v]" -map "[v]" -vsync 0 stacked.mp4
input1.mp4 has dimensions 594x512, and input2.mp4 has dimensions 512x512. I get this error in return:
width not divisible by 2 (1113x512)
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
The confusing thing is that 1113 is such an odd number - it is not 1024, and not even 512+594 (1106). What is causing the assumed width to be such a strange value?
Windows Explorer is incorrect. It does not properly support yuvj444p, so it is giving a wrong width.

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

FFMPEG - height not divisible by 2

i have an problem with ffmpeg. i would like to format a image sequence into a video. I use the followed command for this:
ffmpeg -framerate 24 -i image%04d.jpeg Project.mp4 -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2"
i have 4 pictures:
image0001.jpeg
image0002.jpeg
image0003.jpeg
image0004.jpeg
With this command, i get the following error:
[libx264 # 000001f12e7a0540] height not divisible by 2 (1200x1599)
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
Conversion failed!
Can someone tell me why this mistake comes and how can I fix it?
Thanks
Option placement matters:
ffmpeg [input options] -i input [output options] output
Any trailing options (ones after the output), such as your -vf, may be ignored.
Corrected command:
ffmpeg -framerate 24 -i image%04d.jpeg -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" Project.mp4

Error when cropping video using FFMPEG

Question: Is there a single FFMPEG crop filter that will work for all videos, including (but not limited to): 856x480, 640x480, and 1280x720?
We have a video processing system (uses DirectShow), and all videos fed into this system must be 16:9 using the MJPEG codec. We use the following ffmpeg command to convert the source videos into MJPEG, scale the pixels to make them square, and then crop them to a 16:9 aspect ratio. This works great for most input videos, and the output is exactly what we want.
ffmpeg -i "1280x720input.mp4" -filter:v "scale=iw*sar:ih,crop=iw:iw/16*9" -codec:v mjpeg -q:v 2 -codec:a pcm_s16le -r 30 -y "output.avi"
However, when we use an input video with a resolution of 856x480, we get the following error:
[Parsed_crop_1 # 0000000004615720] Invalid too big or non positive
size for width '852' or height '480'
I tried a different crop filter that uses the input height in the calculation instead of input width, and it works with 856x480
ffmpeg -i "856x480input.mp4" -filter:v "scale=iw*sar:ih,crop=ih*16/9:ih" -codec:v mjpeg -q:v 2 -codec:a pcm_s16le -r 30 -y "output.avi"
However this does not work with other source videos in 16:9 (1280x720) or 4:3 (640x480) format. Is there a single crop command that will work on all videos?
You need conditional expressions:
crop='if(gte(dar,16/9),ih*16/9,iw)':'if(gte(dar,16/9),ih,iw*9/16)'
dar is the display aspect ratio i.e. iw * sar / ih

Resources