Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#309 closed defect (invalid)

width or height not divisible by 2

Reported by: AlanJames1987 Owned by:
Priority: normal Component: undetermined
Version: git-master Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: yes
Analyzed by developer: yes

Description

While using -vf 'scale=' if the output has an a height that is an odd number it gives an error like below.

[libx264 @ 0x175c880] width or height not divisible by 2 (854x363)

This has caused me lots of headache when down-converting large amounts of video and not having all of it be converted.

Change History (7)

comment:1 Changed 5 years ago by cehoyos

  • Component changed from avfilter to undetermined
  • Status changed from new to open

Command line and complete, uncut output missing (but I fear you used the wrong bug tracker).

comment:2 Changed 5 years ago by AlanJames1987

Command line

#!/bin/bash
ffmpeg -i input.mov \
  -vcodec libx264 -vf 'scale=854:-1' -b 854k \
  -acodec aac -strict experimental -ab 112k \
  -vpre baseline -threads 0 -map_metadata -1 -y output.mp4

uncut output

ffmpeg version N-31018-gebc64dc, Copyright (c) 2000-2011 the FFmpeg developers
  built on Jun 26 2011 04:42:51 with gcc 4.5.2
  configuration: --enable-gpl --enable-version3 --enable-nonfree --enable-postproc --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-x11grab
  libavutil    51. 10. 0 / 51. 10. 0
  libavcodec   53.  7. 0 / 53.  7. 0
  libavformat  53.  4. 0 / 53.  4. 0
  libavdevice  53.  1. 1 / 53.  1. 1
  libavfilter   2. 23. 0 /  2. 23. 0
  libswscale    2.  0. 0 /  2.  0. 0
  libpostproc  51.  2. 0 / 51.  2. 0
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x21d2440] Unknown container channel layout.
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x21d2440] max_analyze_duration 5000000 reached at 5013333

Seems stream 0 codec frame rate differs from container frame rate: 5994.00 (5994/1) -> 23.98 (2997/125)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mov':
  Metadata:
    major_brand     : qt  
    minor_version   : 537199360
    compatible_brands: qt  
    creation_time   : 2008-07-15 16:22:37
    comment         : Encoded and delivered by apple.com/trailers/
    comment-eng     : Encoded and delivered by apple.com/trailers/
    copyright       : © 2008 Warner Bros. Pictures. All Rights Reserved
    copyright-eng   : © 2008 Warner Bros. Pictures. All Rights Reserved
    title           : The Dark Knight
    title-eng       : The Dark Knight
  Duration: 00:02:06.93, start: 0.000000, bitrate: 10488 kb/s
    Stream #0.0(eng): Video: h264 (Main), yuv420p, 1920x816, 10275 kb/s, 23.98 fps, 23.98 tbr, 2997 tbn, 5994 tbc
    Metadata:
      creation_time   : 2008-07-15 16:22:37
    Stream #0.1(eng): Audio: aac, 48000 Hz, 5.1, s16, 208 kb/s
    Metadata:
      creation_time   : 2008-07-15 16:22:37
    Stream #0.2(eng): Data: tmcd / 0x64636D74
    Metadata:
      creation_time   : 2008-07-15 16:22:37
[buffer @ 0x21d6280] w:1920 h:816 pixfmt:yuv420p tb:1/1000000 sar:0/1 sws_param:
[scale @ 0x21d5260] w:1920 h:816 fmt:yuv420p -> w:854 h:363 fmt:yuv420p flags:0x4
[libx264 @ 0x21d68c0] Default settings detected, using medium profile
[libx264 @ 0x21d68c0] width or height not divisible by 2 (854x363)
Output #0, mp4, to 'output.mp4':
    Stream #0.0(eng): Video: libx264, yuv420p, 854x363, q=2-31, 854 kb/s, 90k tbn, 23.98 tbc
    Metadata:
      creation_time   : 2008-07-15 16:22:37
    Stream #0.1(eng): Audio: libfaac, 48000 Hz, 5.1, s16, 112 kb/s
    Metadata:
      creation_time   : 2008-07-15 16:22:37
Stream mapping:
  Stream #0.0 -> #0.0
  Stream #0.1 -> #0.1
Error while opening encoder for output stream #0.0 - maybe incorrect parameters such as bit_rate, rate, width or height

The problem is in avfilter somewhere in the vf_scale.c file.

comment:3 Changed 5 years ago by saste

  • Analyzed by developer set
  • Reproduced by developer set
  • Resolution set to invalid
  • Status changed from open to closed

This is a limitation of libx264, which is unrelated to libavfilter/scale.

When choosing scale=W:-1 the filter won't round the scaled H by 2, you need to explicitely express this to the scale filter, either by employing scripting or using expressions in the scale filter itself.

For example the following will round the scaled height to a multiple of 2, keeping the same input aspect ratio:
scale="854:trunc(ow/a/2)*2"

comment:4 follow-up: Changed 5 years ago by cehoyos

Wouldn't scale="854:-2" be much simpler?

comment:5 in reply to: ↑ 4 Changed 5 years ago by saste

Replying to cehoyos:

Wouldn't scale="854:-2" be much simpler?

Patches are welcome, if you believe that is cleaner and if you can provide a consistent semantics for negative h/w values.

comment:6 follow-up: Changed 5 years ago by cehoyos

If the value for @var{width} or @var{height} is -n (negative), the scale filter will
use, for the respective output size, a value that maintains the aspect
ratio of the input image, and rounds to the nearest multiple of +n.

Do you believe anything is unclear or inconsistent?

comment:7 in reply to: ↑ 6 Changed 5 years ago by saste

Replying to cehoyos:

If the value for @var{width} or @var{height} is -n (negative), the scale filter will
use, for the respective output size, a value that maintains the aspect
ratio of the input image, and rounds to the nearest multiple of +n.

Do you believe anything is unclear or inconsistent?

Looks sane.

Note: See TracTickets for help on using tickets.