ffmpeg barfs on .AVI file

Entered on 08/31/2017 at 10:54 by juli@med.uvm.edu:

Hi Wesley,
I’ve uploaded 2 movies to the streaming.uvm.edu server, which are not going through. 1 is an avi file, the other a mp4 file. Are there issues with the server?

Issues with ffmpeg.

Exploratory steps

Look up client by NEtID in CTL_cumulusclips/users table, get user_id

Look up by user_id videos in videos table, status=new, get filename. Be an ugly thing like oJAFxvqygTeeeJihlkIT

Fetch /var/www/html/media/cc-core/logs/oJAFxvqygTeeeJihlkIT.log

 

Look for ffmpeg errors/warnings. In this case, I see

Input #0, avi, from ‘/wowza/users/j/l/jlovelet/temp/oJAFxvqygTeeeJihlkIT.avi’:

Duration: 00:00:03.00, start: 0.000000, bitrate: 52594 kb/s

Stream #0:0: Video: mjpeg (MJPG / 0x47504A4D), yuvj420p(pc, bt470bg/unknown/unknown), 1139×616 [SAR 1:1 DAR 1139:616], 52926 kb/s, 50 fps, 50 tbr, 50 tbn, 50 tbc

Metadata:

title           : ImageJ AVI

Codec AVOption b (set bitrate (in bits/s)) specified for output file #0 (/wowza/users/j/l/jlovelet/HD720/oJAFxvqygTeeeJihlkIT_temp.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.

[swscaler @ 0x22d8420] deprecated pixel format used, make sure you did set range correctly

[libx264 @ 0x22c4880] width not divisible by 2 (1139×616)

Output #0, mp4, to ‘/wowza/users/j/l/jlovelet/HD720/oJAFxvqygTeeeJihlkIT_temp.mp4’:

So which is the error? Much googling suggested this:

[libx264 @ 0x22c4880] width not divisible by 2 (1139×616)

OK, so what’s the fix? ffmpeg command was

/usr/bin/ffmpeg -i oJAFxvqygTeeeJihlkIT.avi -acodec aac -b:a 128k -ac 2 -ar 44100  -af "aresample=first_pts=0" -pix_fmt yuv420p -vsync -1 -sn -vcodec libx264 -r 30 -vf "scale=min(1280\,iw):trunc(ow/a/2)*2" -threads 0 -maxrate 3000k -bufsize 3000k -preset slower -profile:v high -tune film  -x264opts keyint=60:min-keyint=60:no-scenecut -map_metadata -1 -f mp4 -y oJAFxvqygTeeeJihlkIT_temp.mp4

The offending option

-vf "scale=min(1280\,iw):trunc(ow/a/2)*2"

The Fix

-vf "scale=min(1280\,trunc(iw/2)*2):trunc(ow/a/2)*2"

The How? lots of googling, some dumb luck, trial and error. What exactly does this mean? There are many cookbook recipes that say “use this” but finding a guide to the syntax was tricky. I eventually found this article which said,

“The expression trunc(ow/a/2)*2 as vertical resolution means: use as output height the output width (ow = in this case 1280) divided for input aspect ratio and approximated to the nearest multiple of 2
“This command line uses as width the minimum between 1280 and the input width (iw), and then scales the height to maintain the original aspect ratio. Notice that “,” may require to be escaped to “\,” in some shells.”

I tries the same with width, but it didn’t like that divide by a bit, but it did like

trunc(iw/2)*2)

Which is self explanatory.

About Wesley Wright

Born on a mountain top near New York City, Craziest state in the land of the pretty. Raised in the woods so's he knew every tree, Killed him a bear when he was only three.
This entry was posted in Wes and tagged , , . Bookmark the permalink.