Opened 6 weeks ago

Closed 5 weeks ago

#6524 closed defect (invalid)

Video filter with relative scaling produces invalid resolutions (not divisible by 2)

Reported by: monty Owned by:
Priority: normal Component: undetermined
Version: unspecified Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Tested with ffmpeg-3.3.2-win64-static (and some older versions like in the error log)

When trying to rescale .mp4 videos with relative size it prodcues invalid result resolutions which are not divisible by 2.

Input: test_video.mp4 (1280x768, 18 seconds duration)

FFmpeg command line:
ffmpeg -ss 00:09 -i test_video.mp4 -vframes 1 -q:v 2 -vf scale="'if(lt(a,512/288),512,-1)':'if(lt(a,512/288),-1,288)'" test_preview.mp4 -y

It should rescale all videos fitting into a box of 512x288

It fails with the following error output:

ffmpeg version N-82324-g872b358 Copyright (c) 2000-2016 the FFmpeg developers

built with gcc 5.4.0 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-libebur128 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib
libavutil 55. 36.100 / 55. 36.100
libavcodec 57. 66.101 / 57. 66.101
libavformat 57. 57.100 / 57. 57.100
libavdevice 57. 2.100 / 57. 2.100
libavfilter 6. 66.100 / 6. 66.100
libswscale 4. 3.100 / 4. 3.100
libswresample 2. 4.100 / 2. 4.100
libpostproc 54. 2.100 / 54. 2.100

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'C:\data\test_video.mp4':

Metadata:

major_brand : mp42
minor_version : 0
compatible_brands: mp42mp41
creation_time : 2013-12-17T09:58:56.000000Z

Duration: 00:00:18.01, start: 0.000000, bitrate: 4962 kb/s

Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv), 1280x768 [SAR 1:1 DAR 5:3], 4830 kb/s, 25 fps, 25 tbr, 25k tbn, 50 tbc (default)
Metadata:

creation_time : 2013-12-17T09:58:56.000000Z
handler_name : Mainconcept MP4 Video Media Handler
encoder : AVC Coding

Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 125 kb/s (default)
Metadata:

creation_time : 2013-12-17T09:58:56.000000Z
handler_name : Mainconcept MP4 Sound Media Handler

[libx264 @ 00000000006c9f60] -qscale is ignored, -crf is recommended.
[libx264 @ 00000000006c9f60] height not divisible by 2 (512x307)
Stream mapping:

Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Stream #0:1 -> #0:1 (aac (native) -> aac (native))

Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height

Shouldn't the realtive scaling (-1) automatically ensure that the target resolution is valid (divisible by 2)?.

Change History (2)

comment:1 Changed 6 weeks ago by tbucher

-1 simply preserves source aspect ratio, it doesn't care whether output dimensions will be odd or even. If you need them divisible by 2, use -2.

FFmpeg documentation for the scale filter states:

If one and only one of the values is -n with n >= 1, the scale filter will use a value that maintains the aspect ratio of the input image, calculated from the other specified dimension. After that it will, however, make sure that the calculated dimension is divisible by n and adjust the value if necessary.

comment:2 Changed 5 weeks ago by llogan

  • Resolution set to invalid
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.