[FFmpeg-user] Need help converting videos for on-demand-streaming

wtfux wtfux.dev at googlemail.com
Fri Mar 30 05:40:44 CEST 2012

Hello. I'm looking for some help to properly convert videos for
on-demand-streaming. The input files are in all kind of formats
(mainly h264, aac but also divx, mp3 or flac). Some videos contain
.ass subtitles that need to be burned into the video.
I need an automated way to convert those videos and after searching
for a long time I couldn't find anything so I decided to write my own
little script using ffmpeg. However I'm a newbie at this video stuff.

The output should be 720p and 480p for >=720p video, 480p for >=480p
and the original size for everything else. I think I'm going to use
mediainfo to get that info before conversion. The videos are
computer-animated and contain many steady scenes. The output file
should have an acceptable file size / bit rate for streaming but
should not lose (much) in quality.

This is what I got so far:

A video in 720p x264/aac without subtitles:
ffmpeg -i input.mp4 -codec:a copy -codec:v libx264 -preset slow -tune
animation -level 3.1 -crf 21 -threads 8 -f mp4 720p.mp4
=> encoding with 15 fps
ffmpeg -i input.mp4 -codec:a libfaac -b:a 128k -codec:v libx264
-preset slow -tune animation -level 3.1 -crf 21 -vf "scale=854:480"
-threads 8 -f mp4 480p.mp4
=> encoding with 35 fps

Input file: 299MB (mediainfo: http://pastebin.com/WdD2v7Qs )
Output file 720p: 251MB (mediainfo: http://pastebin.com/AJnJQaU1 )
Output file 480p: 147MB (mediainfo: http://pastebin.com/hsuV55aN )

Video in 720p x264/aac with .ass subtitles:
ffmpeg -i input.mkv -codec:a copy -codec:v libx264 -preset slow -tune
animation -level 3.1 -crf 21 -vf "ass=a.ass" -threads 8 -f mp4
=> forgot to notice fps but slower than the video itself
ffmpeg -i input.mkv -codec:a libfaac -b:a 128k -codec:v libx264
-preset slow -tune animation -level 3.1 -crf 21 -vf
"scale=854:480,ass=a.ass" -threads 8 -f mp4 480p.mp4
=> encoding with 43 fps

Input file: 422MB (mediainfo: http://pastebin.com/HCHLdzNS )
Output file 720p: 144 MB (mediainfo: http://pastebin.com/4pyiE1n8 )
Output file 480p: 77.3 MB (mediainfo: http://pastebin.com/vRQicQBS )
Huge difference in file size but I can't see any video quality difference.

I have several questions I couldn't find answers for. I hope someone
on this mailing list could help out:

1. How does variable bitrate in aac work?
Instead of copying the stream and using a fixed bitrate for the 480p
videos or videos with other codecs I think it'd be better to use a
variable bitrate depending on the source material. How do I do this?

2. Subtitle: Read subtitle and fonts from stream?
In order to burn the subtitle I need to extract the subtitle file and
fonts from the file (and place the fonts in ~/.fonts). Is it possible
to tell ffmpeg to read them from the input file?

3. -tune animation
What exactly is this for? Since the videos are animated I think this
is a good option?

4. What is a good value for -crf?
I tried 20, 21 and 22 and couldn't notice a difference. I want small
files so it's possible to watch the videos without buffering but you
shouldn't notice (much) difference in video quality.

5. Faster conversion?
If I need the conversion faster, should I change -preset slow to
-preset medium or something else? Will the file get larger or the
quality worse? I noticed that the conversion isn't slower when I run
multiple at the same time so I guess ffmpeg isn't using the full CPU.
I set "-threads 8" because i have 4 cores (8 in HT) but no difference.

6. Other params for improvement?
While googling for ffmpeg examples I found a lot of other parameters.
I omitted them since I don't know what I'm doing. I see "-partitions
+parti4x4+parti8x8+partp4x4+partp8x8+partb8x8" often.
Are there any important parameters I should use to make the video/sound better?

7. I'm not sure if this is related to ffmpeg but I can't seek when
streamed over HTTP (I do use qt-faststart after ffmpeg!). Other vids I
converted some months ago however work. The only difference I know of
is that I used that -partitions parameter from the question above.

I know these are a lot of questions but I spend so much time reading
lots of blogs and forum topics and couldn't find the right answers.
Thank you!

More information about the ffmpeg-user mailing list