{"id":1775,"date":"2017-09-05T15:31:14","date_gmt":"2017-09-05T19:31:14","guid":{"rendered":"http:\/\/blog.uvm.edu\/ctl-projects\/?p=1775"},"modified":"2017-09-05T15:31:14","modified_gmt":"2017-09-05T19:31:14","slug":"ffmpeg-barfs-on-avi-file","status":"publish","type":"post","link":"https:\/\/blog.uvm.edu\/waw\/2017\/09\/05\/ffmpeg-barfs-on-avi-file\/","title":{"rendered":"ffmpeg barfs on .AVI file"},"content":{"rendered":"<p><i>Entered on 08\/31\/2017 at 10:54 by <a href=\"mailto:juli@med.uvm.edu\">juli@med.uvm.edu<\/a>:<\/i><\/p>\n<blockquote><p><em><strong>Hi Wesley,<\/strong><\/em><br \/>\n<em><strong>I&#8217;ve uploaded 2 movies to the <a href=\"http:\/\/streaming.uvm.edu\/\">streaming.uvm.edu<\/a> server, which are not going through.\u00a01 is an avi file, the other a mp4 file.\u00a0Are there issues with the server?<\/strong><\/em><\/p><\/blockquote>\n<p>Issues with ffmpeg.<\/p>\n<p>Exploratory steps<\/p>\n<p>Look up client by NEtID in CTL_cumulusclips\/users table, get user_id<\/p>\n<p>Look up by user_id videos in videos table, status=new, get filename. Be an ugly thing like\u00a0oJAFxvqygTeeeJihlkIT<\/p>\n<p>Fetch \/var\/www\/html\/media\/cc-core\/logs\/oJAFxvqygTeeeJihlkIT.log<\/p>\n<p>&nbsp;<\/p>\n<p>Look for ffmpeg errors\/warnings. In this case, I see<\/p>\n<blockquote><p>Input #0, avi, from &#8216;\/wowza\/users\/j\/l\/jlovelet\/temp\/oJAFxvqygTeeeJihlkIT.avi&#8217;:<\/p>\n<p>Duration: 00:00:03.00, start: 0.000000, bitrate: 52594 kb\/s<\/p>\n<p>Stream #0:0: Video: mjpeg (MJPG \/ 0x47504A4D), yuvj420p(pc, bt470bg\/unknown\/unknown), 1139&#215;616 [SAR 1:1 DAR 1139:616], 52926 kb\/s, 50 fps, 50 tbr, 50 tbn, 50 tbc<\/p>\n<p>Metadata:<\/p>\n<p>title \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 : ImageJ AVI<\/p>\n<p>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.<\/p>\n<p>[swscaler @ 0x22d8420] deprecated pixel format used, make sure you did set range correctly<\/p>\n<p>[libx264 @ 0x22c4880] width not divisible by 2 (1139&#215;616)<\/p>\n<p>Output #0, mp4, to &#8216;\/wowza\/users\/j\/l\/jlovelet\/HD720\/oJAFxvqygTeeeJihlkIT_temp.mp4&#8217;:<\/p><\/blockquote>\n<p>So which is the error? Much googling suggested this:<\/p>\n<blockquote><p><strong>[libx264 @ 0x22c4880] width not divisible by 2 (1139&#215;616)<\/strong><\/p><\/blockquote>\n<p>OK, so what&#8217;s the fix? ffmpeg command was<\/p>\n<blockquote>\n<pre><strong>\/usr\/bin\/ffmpeg -i oJAFxvqygTeeeJihlkIT.avi -acodec aac -b:a 128k -ac 2 -ar 44100\u00a0 -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\u00a0 -x264opts keyint=60:min-keyint=60:no-scenecut -map_metadata -1 -f mp4 -y oJAFxvqygTeeeJihlkIT_temp.mp4\n<\/strong>\n<\/pre>\n<\/blockquote>\n<p>The offending option<\/p>\n<pre>-vf \"scale=min(1280\\,iw):trunc(ow\/a\/2)*2\"<\/pre>\n<p>The Fix<\/p>\n<pre>-vf \"scale=min(1280\\,trunc(iw\/2)*2):trunc(ow\/a\/2)*2\"<\/pre>\n<p>The How? lots of googling, some dumb luck, trial and error. What exactly does this mean? There are many cookbook recipes that say &#8220;use this&#8221; but finding a guide to the syntax was tricky. I eventually found <a href=\"https:\/\/sonnati.wordpress.com\/2012\/10\/19\/ffmpeg-the-swiss-army-knife-of-internet-streaming-part-vi\/\">this article <\/a> which said,<\/p>\n<blockquote><p>&#8220;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<br \/>\n&#8220;This command line uses as width the minimum between 1280\u00a0and the input width (iw), and then scales the height to maintain the original aspect ratio. Notice that \u201c,\u201d may require to be escaped to \u201c\\,\u201d in some shells.&#8221;<\/p><\/blockquote>\n<p>I tries the same with width, but it didn&#8217;t like that divide by a bit, but it did like<\/p>\n<p style=\"padding-left: 30px\">trunc(iw\/2)*2)<\/p>\n<p>Which is self explanatory.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Entered on 08\/31\/2017 at 10:54 by juli@med.uvm.edu: Hi Wesley, I&#8217;ve uploaded 2 movies to the streaming.uvm.edu server, which are not going through.\u00a01 is an avi file, the other a mp4 file.\u00a0Are there issues with the server? Issues with ffmpeg. Exploratory &hellip; <a href=\"https:\/\/blog.uvm.edu\/waw\/2017\/09\/05\/ffmpeg-barfs-on-avi-file\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[41826],"tags":[42758,59912,152257],"class_list":["post-1775","post","type-post","status-publish","format-standard","hentry","category-wes","tag-boffins","tag-media-manager","tag-video-2"],"_links":{"self":[{"href":"https:\/\/blog.uvm.edu\/waw\/wp-json\/wp\/v2\/posts\/1775","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.uvm.edu\/waw\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.uvm.edu\/waw\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.uvm.edu\/waw\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.uvm.edu\/waw\/wp-json\/wp\/v2\/comments?post=1775"}],"version-history":[{"count":0,"href":"https:\/\/blog.uvm.edu\/waw\/wp-json\/wp\/v2\/posts\/1775\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.uvm.edu\/waw\/wp-json\/wp\/v2\/media?parent=1775"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.uvm.edu\/waw\/wp-json\/wp\/v2\/categories?post=1775"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.uvm.edu\/waw\/wp-json\/wp\/v2\/tags?post=1775"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}