4

I'm using ffmpeg version 1.2.4 in my local Rails app to convert video files. Everything works as expected when I run the app locally. When I deployed to heroku, I added a buildpack for ffmpeg:

https://github.com/shunjikonishi/heroku-buildpack-ffmpeg

This installs ffmpeg version git-2013-06-02-5711e4f. When I try to transcode a video to mp4, I get the following error:

Unrecognized option 'preset'. Error splitting the argument list: Option not found

Here is the complete log:

2013-11-17T19:45:05.255059+00:00 app[web.1]: Running transcoding...
2013-11-17T19:45:05.255059+00:00 app[web.1]: ffmpeg -y -i /app/public/uploads/tmp/1384717504-2-9158/Untitled.mov -vcodec libx264 -acodec libfaac -s 640x360  -qscale 0 -preset slow -g 30 -aspect 1.7777777777777777 /app/public/uploads/tmp/1384717504-2-9158/tmpfile.mp4
2013-11-17T19:45:05.255059+00:00 app[web.1]: 
2013-11-17T19:45:05.317895+00:00 app[web.1]: Failed encoding...
2013-11-17T19:45:05.317895+00:00 app[web.1]: ffmpeg -y -i /app/public/uploads/tmp/1384717504-2-9158/Untitled.mov -vcodec libx264 -acodec libfaac -s 640x360  -qscale 0 -preset slow -g 30 -aspect 1.7777777777777777 /app/public/uploads/tmp/1384717504-2-9158/tmpfile.mp4
2013-11-17T19:45:05.317895+00:00 app[web.1]: 
2013-11-17T19:45:05.317895+00:00 app[web.1]: ffmpeg version git-2013-06-02-5711e4f Copyright (c) 2000-2013 the FFmpeg developers
2013-11-17T19:45:05.317895+00:00 app[web.1]:   built on Jun  2 2013 07:38:40 with gcc 4.4.3 (Ubuntu 4.4.3-4ubuntu5.1)
2013-11-17T19:45:05.317895+00:00 app[web.1]:   configuration: --enable-shared --disable-asm --prefix=/app/vendor/ffmpeg
2013-11-17T19:45:05.317895+00:00 app[web.1]:   libavutil      52. 34.100 / 52. 34.100
2013-11-17T19:45:05.317895+00:00 app[web.1]:   libavcodec     55. 13.100 / 55. 13.100
2013-11-17T19:45:05.317895+00:00 app[web.1]:   libavformat    55.  8.102 / 55.  8.102
2013-11-17T19:45:05.317895+00:00 app[web.1]:   libavdevice    55.  2.100 / 55.  2.100
2013-11-17T19:45:05.318137+00:00 app[web.1]:   libavfilter     3. 74.101 /  3. 74.101
2013-11-17T19:45:05.318137+00:00 app[web.1]:   libswscale      2.  3.100 /  2.  3.100
2013-11-17T19:45:05.318137+00:00 app[web.1]:   libswresample   0. 17.102 /  0. 17.102
2013-11-17T19:45:05.318137+00:00 app[web.1]: Unrecognized option 'preset'.
2013-11-17T19:45:05.318137+00:00 app[web.1]: Error splitting the argument list: Option not found
2013-11-17T19:45:05.318137+00:00 app[web.1]: 
2013-11-17T19:45:05.318137+00:00 app[web.1]: Errors: no output file created. 

I think that the error may be a result of differences in the version of ffmpeg that I'm using locally and on Heroku. Does anyone have suggestions for how to resolve this issue?

scientiffic
  • 8,169
  • 13
  • 68
  • 138

1 Answers1

8

You're trying to use the encoders libfaac and libx264, but your ffmpeg was not compiled to support these encoders. libfaac requires ffmpeg configure options --enable-nonfree --enable-libfaac and libx264 requires --enable-gpl --enable-libx264. Using --disable-asm is not recommended and can significantly affect encoding time.

If you need help compiling see How to Compile FFmpeg on Ubuntu. Compilation is recommended because the so-called "ffmpeg" package in the repository is a fake, old, buggy, and outdated version from a fork and it does not supply a good AAC encoder.

As for the ffmpeg command options:

  • -qscale is ambiguous. You should tell ffmpeg if it should apply to the audio (-qscale:a or -q:a) or the video (-qscale:v or -q:v) but note that libx264 ignores -qscale and you should use the default settings or -crf as shown in the FFmpeg and x264 Encoding Guide.

  • No need to add -g 30 -aspect 1.7777777777777777. The default setting for -g should suffice and I don't see why you want to force a seemingly arbitrary aspect ratio.

  • Consider using -vf scale=640:-1 instead of explicitly forcing a hard size since this can change the aspect ratio and cause a squished or stretched look. The -1 tells ffmpeg to automatically calculate the value while preserving the aspect ratio.

  • If you compile ffmpeg, then use -codec:a libfdk_aac instead of libfaac. It will provide better quality per bitrate. See the FFmpeg and AAC Encoding Guide for more info.

  • I'm guessing you are making videos for display on the web. If yes, then add -movflags +faststart as an output option to allow the client to begin playback before the file is completely downloaded. This is only available with real ffmpeg and not the fake junk.

Community
  • 1
  • 1
llogan
  • 87,794
  • 21
  • 166
  • 190
  • thanks very much for your help! I'm actually using the carrierwave-video gem, so that's what's generating the ffmpeg encoding options. I'm not sure how to specify options for ffmpeg when using the heroku buildpack; do you have pointers for how to install ffmpeg on heroku? – scientiffic Nov 17 '13 at 21:23
  • @scientiffic No, sorry, but it's definitely a problem with the lack of configuration options (and therefore possible lack of installation of each required external library such as x264 and faac). – llogan Nov 18 '13 at 02:26
  • @scientiffic Did you ever come up with a solution to this? I know it's been awhile but we're seeing the same issue on Heroku. – Michael Paladino May 08 '15 at 19:31
  • @MichaelPaladino I actually wrote a gist about what I ended up doing: https://gist.github.com/ttseng/7682321 – scientiffic May 08 '15 at 23:25
  • @scientiffic I recommend using libfdk_aac instead of libfaac. Better quality per bitrate. – llogan May 09 '15 at 01:52