Changes between Version 1 and Version 2 of EncodingForStreamingSites


Ignore:
Timestamp:
Feb 19, 2014, 9:27:00 PM (6 years ago)
Author:
llogan
Comment:

nits, add crf and preset info, switch to AAC

Legend:

Unmodified
Added
Removed
Modified
  • EncodingForStreamingSites

    v1 v2  
    11= Encoding for streaming sites =
    22
    3 Such as justin.tv, twitch.tv, and ustream.tv.
     3Such as justin.tv, twitch.tv, ustream.tv, !YouTube Live, and other RTMP(E) streaming providers. Since FFmpeg development is very active it is recommend that you follow a [[CompilationGuide|compilation guide]] to take advantage of bug fixes and new features.
    44
    55{{{
    66#!div style="border: 1pt dotted; margin: 1em; background-color: #fffff9;"
    7 '''Note:''' Do not blindly run any of these commands. You must customize your `-maxrate`, `-bufsize`, and `-g` as shown in this guide.
     7'''Note:''' Do not blindly run any of these commands. You must customize your `-crf`, `-preset`, `-maxrate`, `-bufsize`, and `-g` as shown in this guide (do not worry – it is not difficult).
    88}}}
     9
     10== `-crf` ==
     11
     12Consider this to be as close as you can get to a "constant quality" mode. Range is 0-51: 0 is lossless, 18 is often considered to be roughly "visually lossless", 23 is the default, and 51 is the worst. Generally you want to use the highest value that still provides an acceptable quality. If you do not know what to choose then 23-28 will probably be acceptable for streaming.
     13
     14== `-preset` ==
     15
     16This provides the compression to encoding speed ratio. Use the slowest preset you can: `ultrafast`,`superfast`, `veryfast`, `faster`, `fast`, `medium`, `slow`, `slower`, `veryslow`, `placebo`. Try `-preset veryfast` if you are unsure of what to choose, then watch the console output or the video to see if the encoder is keeping up with your desired output frame rate: if it is not then use a faster preset and/or reduce your `-video_size`.
    917
    1018== `-maxrate` ==
     
    1220Anytime you are encoding video with bandwidth as a limiting factor you should be using VBV (Video Buffer Verifier) with the `-maxrate` and `-bufsize` options:
    1321
    14 * Assuming your upload rate is 1024kbit/s (1 megabit/s), and assuming you can reliably utilize 80% of that = 820 kbit/s. Audio will consume 128 kbit/s (64k/channel for stereo) leaving ~692 kbit/s for video: this is your `-maxrate` value.
     22* Assuming your upload rate is 1024kbit/s (1 megabit/s), and assuming you can reliably utilize 80% of that = 820 kbit/s. Audio will consume 128 kbit/s (64k/channel for stereo, but you can of course use a different audio bitrate) leaving ~692 kbit/s for video: this is your `-maxrate` value.
    1523
    16 * If you have a sane upload rate, or do not know what to choose then a `-maxrate` value of 3000k-4000k will probably be fine if your upload rate can handle it.
     24* If you have a sane upload rate, or do not know what to choose then a `-maxrate` value of up to 3000k-4000k will probably be fine if your upload rate can handle it (depending on your input complexity and `-video_size`). Refer to your streaming service for any limitations that may apply.
    1725
    1826* Note that the claimed data rate pay your ISP for may not actually be what you get. You can use a site like [http://www.speedtest.net/ speedtest.net] to test.
     
    2028== `-bufsize` ==
    2129
    22 `-bufsize` sets the buffer size, and can be 1-2 seconds. If you use `-maxrate 3000k` then use a `-bufsize` of 3000k-6000k. You will have to experiment to see what looks best for your content.
     30`-bufsize` sets the buffer size, and can be 1-2 seconds for most gaming screencasts, and up to 5 seconds for more static content. If you use `-maxrate 960k` then use a `-bufsize` of 960k-1920k. You will have to experiment to see what looks best for your content. Refer to your streaming service for the recommended buffer size (it may be shown in seconds or bits).
    2331
    2432== `-g` ==
    2533
    2634* Use a 2 second GOP (Group of Pictures), so simply multiply your output frame rate * 2. For example, if your input is `-framerate 30`, then use `-g 60`.
     35
     36== MP3 or AAC ==
     37
     38If you compiled `ffmpeg` with support for `libfdk_aac`, then you can use that for your audio. If not, then use `-acodec libmp3lame -ar 44100` as shown in many of these examples. MP3 in FLV is limited to specific audio rates, but you can omit `-ar` if you are encoding to AAC. See the [[AACEncodingGuide|FFmpeg and AAC Encoding Guide]] for more information.
     39
     40----
    2741
    2842== Streaming your desktop ==
     
    3448{{{
    3549$ ffmpeg -f alsa -ac 2 -i hw:0,0 -f x11grab -framerate 30 -video_size 1280x720 \
    36 -i :0.0+0,0 -vcodec libx264 -preset veryfast -maxrate 3000k -bufsize 3000k \
     50-i :0.0+0,0 -vcodec libx264 -preset veryfast -maxrate 1984k -bufsize 3968k \
    3751-vf "format=yuv420p" -g 60 -acodec libmp3lame -b:a 96k -ar 44100 \
    3852-f flv rtmp://live.justin.tv/app/<stream key>
     
    117131== Notes ==
    118132
    119 * You can use `xwininfo | grep geometry` to select the target window and get placement coordinates. For example, an output of  `-geometry 800x600+284+175` would result in using `-video_size 800x600 -i :0.0+284,175`.
     133* You can use `xwininfo | grep geometry` to select the target window and get placement coordinates. For example, an output of  `-geometry 800x600+284+175` would result in using `-video_size 800x600 -i :0.0+284,175`. You can also use it to automatically enter the input screen size: `-video_size $(xwininfo -root | grep 'geometry' | awk '{print $2;}')`.
    120134
    121135* The [http://ffmpeg.org/ffmpeg-devices.html#pulse-1 pulse input device] (requires `--enable-libpulse`) can be an alternative to the [http://ffmpeg.org/ffmpeg-devices.html#alsa-1 ALSA input device], as in: `-f pulse -i default`.
     
    128142
    129143If you need additional help then send a message to the [http://ffmpeg.org/contact.html ffmpeg-user mailing list] (see MailingListEtiquette first) or hang out in the ''#ffmpeg'' IRC channel on Freenode.
     144
     145{{{#!comment
     146* Needs some Windows specific dshow examples.
     147* Show recommended buffer sizes, and maxrate limitations for specific providers.
     148}}}