Video media uploader breaks if the video doesn't have a multiple of 2 dimensions.

Trying to upload the attached video results in the following error:

Upload error: 
Object { message: "Request failed with status code 422", name: "AxiosError", code: "ERR_BAD_REQUEST", config: {…}, request: XMLHttpRequest, response: {…}, stack: "" }
​
code: "ERR_BAD_REQUEST"
​
config: Object { timeout: 0, xsrfCookieName: "XSRF-TOKEN", xsrfHeaderName: "X-XSRF-TOKEN", … }
​
message: "Request failed with status code 422"
​
name: "AxiosError"
​
request: XMLHttpRequest { readyState: 4, timeout: 0, withCredentials: true, … }
​​
mozAnon: false
​​
mozSystem: false
​​
onabort: function onabort()
​​
onerror: function onerror()
​​
onload: null
​​
onloadend: function Q()
​​
onloadstart: null
​​
onprogress: null
​​
ontimeout: function ontimeout()
​​
readyState: 4
​​
response: `{"error":"MP4 encoding failed: Command failed: nice -19 ffmpeg -i \\"/srv/www/nashipunch-api/tmp/video-processing/3783-be018285-8f63-4764-8b66-cb9e50b8cb8c-original.webm\\" -y -c:v libx264 -preset fast -crf 23 -maxrate 2M -bufsize 4M -c:a aac -b:a 128k -movflags +faststart -f mp4 \\"/srv/www/nashipunch-api/tmp/video-processing/3783-be018285-8f63-4764-8b66-cb9e50b8cb8c.mp4\\"\\nffmpeg version 4.4.2-0ubuntu0.22.04.1 Copyright (c) 2000-2021 the FFmpeg developers\\n  built with gcc 11 (Ubuntu 11.2.0-19ubuntu1)\\n  configuration: --prefix=/usr --extra-version=0ubuntu0.22.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-pocketsphinx --enable-librsvg --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared\\n  libavutil      56. 70.100 / 56. 70.100\\n  libavcodec     58.134.100 / 58.134.100\\n  libavformat    58. 76.100 / 58. 76.100\\n  libavdevice    58. 13.100 / 58. 13.100\\n  libavfilter     7.110.100 /  7.110.100\\n  libswscale      5.  9.100 /  5.  9.100\\n  libswresample   3.  9.100 /  3.  9.100\\n  libpostproc    55.  9.100 / 55.  9.100\\nInput #0, matroska,webm, from '/srv/www/nashipunch-api/tmp/video-processing/3783-be018285-8f63-4764-8b66-cb9e50b8cb8c-original.webm':\\n  Metadata:\\n    ENCODER         : Lavf61.7.100\\n  Duration: 00:00:12.84, start: 0.016000, bitrate: 3605 kb/s\\n  Stream #0:0: Video: vp9 (Profile 0), yuv420p(tv), 766x727, SAR 1:1 DAR 766:727, 60 fps, 60 tbr, 1k tbn, 1k tbc\\n    Metadata:\\n      DURATION        : 00:00:12.843000000\\nCodec AVOption b (set bitrate (in bits/s)) specified for output file #0 (/srv/www/nashipunch-api/tmp/video-processing/3783-be018285-8f63-4764-8b66-cb9e50b8cb8c.mp4) has not been used for any stream. The most likely reason is either wrong type (e.g. a video option with no video streams) or that it is a private option of some encoder which was not actually used for any stream.\\nStream mapping:\\n  Stream #0:0 -> #0:0 (vp9 (native) -> h264 (libx264))\\nPress [q] to stop, [?] for help\\n[libx264 @ 0x7fc1634b2d00] height not divisible by 2 (766x727)\\nError 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\\nConversion failed!\\n"}`
​​
responseText: `{"error":"MP4 encoding failed: Command failed: nice -19 ffmpeg -i \\"/srv/www/nashipunch-api/tmp/video-processing/3783-be018285-8f63-4764-8b66-cb9e50b8cb8c-original.webm\\" -y -c:v libx264 -preset fast -crf 23 -maxrate 2M -bufsize 4M -c:a aac -b:a 128k -movflags +faststart -f mp4 \\"/srv/www/nashipunch-api/tmp/video-processing/3783-be018285-8f63-4764-8b66-cb9e50b8cb8c.mp4\\"\\nffmpeg version 4.4.2-0ubuntu0.22.04.1 Copyright (c) 2000-2021 the FFmpeg developers\\n  built with gcc 11 (Ubuntu 11.2.0-19ubuntu1)\\n  configuration: --prefix=/usr --extra-version=0ubuntu0.22.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-pocketsphinx --enable-librsvg --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared\\n  libavutil      56. 70.100 / 56. 70.100\\n  libavcodec     58.134.100 / 58.134.100\\n  libavformat    58. 76.100 / 58. 76.100\\n  libavdevice    58. 13.100 / 58. 13.100\\n  libavfilter     7.110.100 /  7.110.100\\n  libswscale      5.  9.100 /  5.  9.100\\n  libswresample   3.  9.100 /  3.  9.100\\n  libpostproc    55.  9.100 / 55.  9.100\\nInput #0, matroska,webm, from '/srv/www/nashipunch-api/tmp/video-processing/3783-be018285-8f63-4764-8b66-cb9e50b8cb8c-original.webm':\\n  Metadata:\\n    ENCODER         : Lavf61.7.100\\n  Duration: 00:00:12.84, start: 0.016000, bitrate: 3605 kb/s\\n  Stream #0:0: Video: vp9 (Profile 0), yuv420p(tv), 766x727, SAR 1:1 DAR 766:727, 60 fps, 60 tbr, 1k tbn, 1k tbc\\n    Metadata:\\n      DURATION        : 00:00:12.843000000\\nCodec AVOption b (set bitrate (in bits/s)) specified for output file #0 (/srv/www/nashipunch-api/tmp/video-processing/3783-be018285-8f63-4764-8b66-cb9e50b8cb8c.mp4) has not been used for any stream. The most likely reason is either wrong type (e.g. a video option with no video streams) or that it is a private option of some encoder which was not actually used for any stream.\\nStream mapping:\\n  Stream #0:0 -> #0:0 (vp9 (native) -> h264 (libx264))\\nPress [q] to stop, [?] for help\\n[libx264 @ 0x7fc1634b2d00] height not divisible by 2 (766x727)\\nError 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\\nConversion failed!\\n"}`
​​
responseType: ""
​​
responseURL: "https://api.knockout.chat/v2/postVideos"
​​
responseXML: null
​​
status: 422
​​
statusText: ""
​​
timeout: 0
​​
upload: XMLHttpRequestUpload { onloadstart: null, onprogress: null, onabort: null, … }
​​
withCredentials: true
​​
<prototype>: XMLHttpRequestPrototype { open: open(), setRequestHeader: setRequestHeader(), send: send(), … }
​
response: Object { data: {…}, status: 422, statusText: "", … }
​
stack: ""
​
<prototype>: Object { constructor: E(s, m, S, y, j), toJSON: toJSON(), stack: "", … }
f05c5c272.16fe8efe.js:168:8572

The important text in question:

[libx264 @ 0x7fc1634b2d00] height not divisible by 2 (766x727)

Fixed by adding the following filter before upload: -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2"!

Screencast_20260226_005905{width=633 height=600}

Assignee Loading
Time tracking Loading