<p>For a server, you <em>definitely</em> want ffmpeg. I would also strongly recommend <a href="https://ffmpeg.org/trac/ffmpeg/wiki/UbuntuCompilationGuide" rel="noreferrer">compiling it yourself</a> (those are Ubuntu instructions, but should work for Debian as well AFAIK) - the best AAC encoder available for ffmpeg (libfdk_aac) cannot be redistributed alongside x264 (because of the GPL), and the version of ffmpeg in the repositories is probably too old for some of the things I'm going to list here.</p>
<h2>MP4</h2>
<p>To convert an arbitrary video to an MP4 using libx264 and libfdk_aac:</p>
<pre><code>ffmpeg -i input.avi -c:v libx264 -crf 24 -preset veryfast \
-ac 2 -c:a libfdk_aac -vbr 3 -movflags faststart output.mp4
</code></pre>
<p>Control the quality of the video with <code>-crf</code>: a lower number is better quality, but larger file. 18 is visually lossless under most circumstances, and 24 should be more than good enough for online streaming. Use a <code>-preset</code> to control the speed/size of the video: a slower preset means a smaller file (the presets are ultrafast, superfast, veryfast, faster, fast, medium, slow, and slower). See <a href="https://ffmpeg.org/trac/ffmpeg/wiki/x264EncodingGuide" rel="noreferrer">here</a> for more detail.</p>
<p>Control the quality of the audio with <code>-vbr</code>: the scale is 1-5, where 5 is best quality. Actually, even a vbr of 1 should be good enough for your purposes. See <a href="https://ffmpeg.org/trac/ffmpeg/wiki/AACEncodingGuide" rel="noreferrer">here</a> for more detail. <code>-ac 2</code> means that ffmpeg will output 2 audio channels, mixing down if necessary; you only really need to use it if you think people will send in 5.1 surround sound audio or something.</p>
<p><code>-movflags faststart</code> is required for internet MP4 video.</p>
<h2>WEBM</h2>
<p>.webm is a little more complicated. libvpx (the VP8 encoder) should have a crf mode that will work in a similar way to x264's, but it is <a href="https://ffmpeg.org/trac/ffmpeg/ticket/2136" rel="noreferrer">currently broken</a>. Unfortunately, you'll have to target a bit rate instead. For standard definition, 1000kb/s should give very good quality (in fact, that is probably overkill). For full 1080p HD, about 5000kb/s will give really good quality (again, you can probably go lower - try it out and see). About 2200kb/s should do it for 720p.</p>
<pre><code>ffmpeg -i input.avi -c:v libvpx -b:v 1000k \
-c:a libvorbis -q:a 4 -ac 2 output.webm
</code></pre>
<p><strong>NOTE</strong> - make sure you use <em>libvorbis</em> (the xiph.org encoder lib), NOT <em>vorbis</em> (the inferior internal ffmpeg encoder). Set the quality with <code>-q:a</code>: the range is -1-10, where 10 is best quality, and 5 is indistinguishable from an original CD. 3 or 4 should be adequate for online streaming purposes.</p>
<h2>Subtitles &amp; scale video</h2>
<p>To hardcode subtitles, you have to first extract them from the original file, then use either the ass filter or the subtitles filter to encode them. Using the subtitles filter:</p>
<pre><code>ffmpeg -i input.mkv -map 0:s:0 -c:s ass subtitle.ass
ffmpeg -i input.mkv -filter:v 'subtitles=subtitle.ass' \
-c:v libx264 -crf 24 -preset veryfast \
-c:a libfdk_aac -vbr 3 -movflags faststart output.mp4 \
-filter:v 'subtitles=subtitle.ass' \
-c:v libvpx -b:v 1000k \
-c:a libvorbid -q:a 4 output.webm
</code></pre>
<p>To scale videos, use the scale filter. <code>-1:480</code> means 'for the width, keep the input aspect ratio, and scale the height to 480'.</p>
<pre><code>ffmpeg -i input.avi -filter:v 'scale=-1:480' \
-c:v libx264 -crf 24 -preset veryfast \
-c:a libfdk_aac -vbr 3 -movflags faststart output.mp4 \
-filter:v 'scale:-1:480' \
-c:v libvpx -b:v 1000k \
-c:a libvorbid -q:a 4 output.webm
</code></pre>
<p>You can combine the scale and subtitle filters like so:</p>
<pre><code>ffmpeg -i input.mkv -filter:v 'scale=-1:480,subtitles=subtitle.ass' \
-c:v libx264 -crf 24 -preset veryfast \
-c:a libfdk_aac -vbr 3 -movflags faststart output.mp4 \
-filter:v 'scale:-1:480,subtitles=subtitle.ass' \
-c:v libvpx -b:v 1000k \
-c:a libvorbid -q:a 4 output.webm
</code></pre>
<p>You'd probably want to use a bash script to detect the input height and test the existence of subtitles; I'd personally use mediainfo to find that information, it's pretty amenable to regex.</p>
<p>That should be enough to get you going.</p>

CC BY-SA 3.0
2013-01-16T23:58:42.843Z
2013-01-16T23:58:42.843Z
2020-06-17T09:53:03.607Z
evilsoup
<p>Video transcoding is very confusing and there is loads of different options.</p>

<p>If you dont want to use FFMpeg you could try VLC</p>

<p>Read more about transcoding with VLC <a href="http://wiki.videolan.org/Transcode#Transcoding_with_the_Command_Prompt" rel="nofollow">here</a></p>

<p>Otherwise FFMpeg (or some kind of wrapper tool) is your best bet.
By omitting the -vb option you let FFMpeg decide bitrate. There is also a few Presets you can use for encoding to specific devices and qualitys, like ipod640.</p>

<p>I've build a tiny java application that transcodes video from a que (using MySQL)
but a cronjob and a shell-script is also a good solution</p>

CC BY-SA 3.0
2012-03-23T10:31:50.217Z
2012-03-23T10:31:50.217Z
Artog
<p>I need an automatic solution to convert video clips for html5 (mp4/x264, webm/vp8) and flash (mp4/x264) video-on-demand streaming. For a site like Youtube, just much smaller.</p>

<p>The input files are mostly h264/x264 but sometimes others (like divx/xvid) and have different resolution and sometimes contain subtitles (.ass) that need to be hard-burned. The output resolution should be 720p and 480p for >=720p video, 480p for 480p-720p and the original resolution for everything else.</p>

<p>The server is running debian.</p>

<p>I couldn't find any open source project, just some cloud services (SaaS) that offer this kind of conversion. I tried working with ffmpeg but each video needs a different bitrate to be still in a good quality and have a file size that allows video-on-demand. If the input video is bad the output video shouldn't be larger. I have no idea how to set the x264/vp8 params right and obviously I can't do that manually.</p>

<p>Do you know of any (linux) tool for this? There are many video sites out there, how do they do this? I looked at video files from youtube and they all differ in bitrate and file size. Or do you know any website or tutorial that could help me? I've spend much time searching for tips but I just can't find anything, maybe I'm searching for the wrong terms..</p>

<video><streaming><codec><conversion>
Automatic conversion/encode video for Video On Demand streaming
XDragon
# Automatic conversion/encode video for Video On Demand streaming

(Asked by: username_0 on 2012-03-21)

I need an automatic solution to convert video clips for html5 (mp4/x264, webm/vp8) and flash (mp4/x264) video-on-demand streaming. For a site like Youtube, just much smaller.

The input files are mostly h264/x264 but sometimes others (like divx/xvid) and have different resolution and sometimes contain subtitles (.ass) that need to be hard-burned. The output resolution should be 720p and 480p for >=720p video, 480p for 480p-720p and the original resolution for everything else.

The server is running debian.

I couldn't find any open source project, just some cloud services (SaaS) that offer this kind of conversion. I tried working with ffmpeg but each video needs a different bitrate to be still in a good quality and have a file size that allows video-on-demand. If the input video is bad the output video shouldn't be larger. I have no idea how to set the x264/vp8 params right and obviously I can't do that manually.

Do you know of any (linux) tool for this? There are many video sites out there, how do they do this? I looked at video files from youtube and they all differ in bitrate and file size. Or do you know any website or tutorial that could help me? I've spend much time searching for tips but I just can't find anything, maybe I'm searching for the wrong terms..

**Tags:** video, streaming, codec, conversion


---

## 2 answers

### Answer by username_1 on 2013-01-16. Score: 5

For a server, you definitely want ffmpeg. I would also strongly recommend compiling it yourself (those are Ubuntu instructions, but should work for Debian as well AFAIK) - the best AAC encoder available for ffmpeg (libfdk_aac) cannot be redistributed alongside x264 (because of the GPL), and the version of ffmpeg in the repositories is probably too old for some of the things I'm going to list here.
MP4
To convert an arbitrary video to an MP4 using libx264 and libfdk_aac:
ffmpeg -i input.avi -c:v libx264 -crf 24 -preset veryfast \
-ac 2 -c:a libfdk_aac -vbr 3 -movflags faststart output.mp4

Control the quality of the video with -crf: a lower number is better quality, but larger file. 18 is visually lossless under most circumstances, and 24 should be more than good enough for online streaming. Use a -preset to control the speed/size of the video: a slower preset means a smaller file (the presets are ultrafast, superfast, veryfast, faster, fast, medium, slow, and slower). See here for more detail.
Control the quality of the audio with -vbr: the scale is 1-5, where 5 is best quality. Actually, even a vbr of 1 should be good enough for your purposes. See here for more detail. -ac 2 means that ffmpeg will output 2 audio channels, mixing down if necessary; you only really need to use it if you think people will send in 5.1 surround sound audio or something.
-movflags faststart is required for internet MP4 video.
WEBM
.webm is a little more complicated. libvpx (the VP8 encoder) should have a crf mode that will work in a similar way to x264's, but it is currently broken. Unfortunately, you'll have to target a bit rate instead. For standard definition, 1000kb/s should give very good quality (in fact, that is probably overkill). For full 1080p HD, about 5000kb/s will give really good quality (again, you can probably go lower - try it out and see). About 2200kb/s should do it for 720p.
ffmpeg -i input.avi -c:v libvpx -b:v 1000k \
-c:a libvorbis -q:a 4 -ac 2 output.webm

NOTE - make sure you use libvorbis (the xiph.org encoder lib), NOT vorbis (the inferior internal ffmpeg encoder). Set the quality with -q:a: the range is -1-10, where 10 is best quality, and 5 is indistinguishable from an original CD. 3 or 4 should be adequate for online streaming purposes.
Subtitles & scale video
To hardcode subtitles, you have to first extract them from the original file, then use either the ass filter or the subtitles filter to encode them. Using the subtitles filter:
ffmpeg -i input.mkv -map 0:s:0 -c:s ass subtitle.ass
ffmpeg -i input.mkv -filter:v 'subtitles=subtitle.ass' \
-c:v libx264 -crf 24 -preset veryfast \
-c:a libfdk_aac -vbr 3 -movflags faststart output.mp4 \
-filter:v 'subtitles=subtitle.ass' \
-c:v libvpx -b:v 1000k \
-c:a libvorbid -q:a 4 output.webm

To scale videos, use the scale filter. -1:480 means 'for the width, keep the input aspect ratio, and scale the height to 480'.
ffmpeg -i input.avi -filter:v 'scale=-1:480' \
-c:v libx264 -crf 24 -preset veryfast \
-c:a libfdk_aac -vbr 3 -movflags faststart output.mp4 \
-filter:v 'scale:-1:480' \
-c:v libvpx -b:v 1000k \
-c:a libvorbid -q:a 4 output.webm

You can combine the scale and subtitle filters like so:
ffmpeg -i input.mkv -filter:v 'scale=-1:480,subtitles=subtitle.ass' \
-c:v libx264 -crf 24 -preset veryfast \
-c:a libfdk_aac -vbr 3 -movflags faststart output.mp4 \
-filter:v 'scale:-1:480,subtitles=subtitle.ass' \
-c:v libvpx -b:v 1000k \
-c:a libvorbid -q:a 4 output.webm

You'd probably want to use a bash script to detect the input height and test the existence of subtitles; I'd personally use mediainfo to find that information, it's pretty amenable to regex.
That should be enough to get you going.


---

### Answer by username_2 on 2012-03-23. Score: 1

Video transcoding is very confusing and there is loads of different options.

If you dont want to use FFMpeg you could try VLC

Read more about transcoding with VLC [here](http://wiki.videolan.org/Transcode#Transcoding_with_the_Command_Prompt)

Otherwise FFMpeg (or some kind of wrapper tool) is your best bet.
By omitting the -vb option you let FFMpeg decide bitrate. There is also a few Presets you can use for encoding to specific devices and qualitys, like ipod640.

I've build a tiny java application that transcodes video from a que (using MySQL)
but a cronjob and a shell-script is also a good solution


---

