[FFmpeg-user] ffmpeg keep aspect ratio when scaling, keep dimensions divisable by n
Peter van den Houten
petervdh at gmail.com
Thu Apr 9 16:00:29 EEST 2020
On 09/04/2020 14:43, atticus via ffmpeg-user wrote:
> ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
> On Thursday, April 9, 2020 9:42 AM, Michael Koch <astroelectronic at t-online.de> wrote:
>
>>> Am 09.04.2020 um 11:36 schrieb atticus via ffmpeg-user:
>>>
>
>>>> Hi there,
>>>> I'm scaling a video by with this filter:
>>>> -vf "scale=720:320:force_original_aspect_ratio=decrease"
>>>> which works perfectly fine, since I can input the my desired resolution and
>>>> ffmpeg decides on its own which dimension should be scaled by how much to
>>>> keep the aspect ratio. The problem now is that in some cases ffmpeg will
>>>> calculate a uneven number for one of the dimensions (with the h264 codec)
>>>> thus I get this error:
>>>> [libx264 @ 0x5633df10bcc0] width not divisible by 2 (569x320)
>>>> 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
>>>> Is there some way to prevent this to give ffmpeg a width and a height as an
>>>> input and it says on its own which should be scaled by how much AND keep (at
>>>> least the calculated) dimensions divisable by n (I know something similar is
>>>> possible with negative numbers, but then I can only give one dimension)?
>>>
>
>>> The scale filter has an option 'force_divisible_by'
>>>
>
>>> Michael
>
>> Thanks for your fast reply.
>>
>> Oh sorry to have bothered you all, I must have overlooked this option when
>> studying the ffmpeg site for scaling.
>>
>
>> With Best Wishshes
>
> Well I still have a problem when using this:
>
> ffmpeg -y -i video.MTS -vf "scale=720:320:force_original_aspect_ratio=decrease:force_divisible_by=2" -c:a copy -c:v h264 padded.MTS
> ffmpeg version n4.2.2 Copyright (c) 2000-2019 the FFmpeg developers
> built with gcc 9.3.0 (Arch Linux 9.3.0-1)
> configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libjack --enable-libmfx --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-nvdec --enable-nvenc --enable-omx --enable-shared --enable-version3
> libavutil 56. 31.100 / 56. 31.100
> libavcodec 58. 54.100 / 58. 54.100
> libavformat 58. 29.100 / 58. 29.100
> libavdevice 58. 8.100 / 58. 8.100
> libavfilter 7. 57.100 / 7. 57.100
> libswscale 5. 5.100 / 5. 5.100
> libswresample 3. 5.100 / 3. 5.100
> libpostproc 55. 5.100 / 55. 5.100
> Input #0, mpegts, from 'video.MTS':
> Duration: 00:00:08.32, start: 1.040000, bitrate: 22401 kb/s
> Program 1
> Stream #0:0[0x1011]: Video: h264 (High) (HDMV / 0x564D4448), yuv420p(top first), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 50 tbr, 90k tbn, 50 tbc
> Stream #0:1[0x1100]: Audio: ac3 (AC-3 / 0x332D4341), 48000 Hz, stereo, fltp, 256 kb/s
> Stream #0:2[0x1200]: Subtitle: hdmv_pgs_subtitle ([144][0][0][0] / 0x0090), 1920x1080
> Stream mapping:
> Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
> Stream #0:1 -> #0:1 (copy)
> Press [q] to stop, [?] for help
> [Parsed_scale_0 @ 0x562f226b0980] Option 'force_divisible_by' not found
> [AVFilterGraph @ 0x562f226ae400] Error initializing filter 'scale' with args '720:320:force_original_aspect_ratio=decrease:force_divisible_by=2:flags=bicubic'
> Error reinitializing filters!
> Failed to inject frame into filter network: Option not found
> Error while processing the decoded data for stream #0:0
> Conversion failed!
>
> Does someone know why ffmpeg doesn't want the option force_divisible:by?
>
> With best Wished
>
>
Try:
ffmpeg -i video.MTS -vf scale=720:-2 -c:v libx264 -crf 20 -c:a copy -y padded.MTS
Change -crf 20 up or down to suit quality and/or file size.
Regards
Peter
More information about the ffmpeg-user
mailing list