Changes between Version 5 and Version 6 of EncodingForStreamingSites


Ignore:
Timestamp:
Jan 26, 2017, 8:35:17 PM (3 years ago)
Author:
llogan
Comment:

added tee example. removed useless mp3 info: use aac instead.

Legend:

Unmodified
Added
Removed
Modified
  • EncodingForStreamingSites

    v5 v6  
    3434Use 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`.
    3535
    36 == MP3 or AAC ==
    37 
    38 If 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 
    4036----
    4137
     
    4844{{{
    4945$ ffmpeg -f alsa -ac 2 -i hw:0,0 -f x11grab -framerate 30 -video_size 1280x720 \
    50 -i :0.0+0,0 -vcodec libx264 -preset veryfast -maxrate 1984k -bufsize 3968k \
     46-i :0.0+0,0 -c:v libx264 -preset veryfast -maxrate 1984k -bufsize 3968k \
    5147-vf "format=yuv420p" -g 60 -c:a aac -b:a 128k -ar 44100 \
    5248-f flv rtmp://live.twitch.tv/app/<stream key>
     
    5955{{{
    6056$ ffmpeg -f alsa -ac 2 -i hw:0,0 -f x11grab -framerate 30 -video_size 1680x1050 \
    61 -i :0.0+0,0 -vcodec libx264 -preset veryfast -maxrate 3000k -bufsize 3000k \
     57-i :0.0+0,0 -c:v libx264 -preset veryfast -maxrate 3000k -bufsize 3000k \
    6258-vf "scale=1280:-1,format=yuv420p" -g 60 -c:a aac -b:a 128k -ar 44100 \
    6359-f flv rtmp://live.twitch.tv/app/<stream key>
     
    7773 [1:v]scale=120:-1,setpts=PTS-STARTPTS[fg]; \
    7874 [bg][fg]overlay=W-w-10:10,format=yuv420p[out]"
    79 -map "[out]" -map 2:a -vcodec libx264 -preset veryfast \
     75-map "[out]" -map 2:a -c:v libx264 -preset veryfast \
    8076-maxrate 3000k -bufsize 4000k -c:a aac -b:a 160k -ar 44100 \
    8177-f flv rtmp://live.twitch.tv/app/<stream key>
     
    9894 [bg][fg]overlay=W-w-10:10[bg2]; \
    9995 [bg2][3:v]overlay=W-w-10:H-h-10,format=yuv420p[out]"
    100 -map "[out]" -map 2:a -vcodec libx264 -preset veryfast \
     96-map "[out]" -map 2:a -c:v libx264 -preset veryfast \
    10197-maxrate 3000k -bufsize 4000k -c:a aac -b:a 160k -ar 44100 -b:a 128k \
    10298-f flv rtmp://live.twitch.tv/app/<stream key>
     
    108104
    109105{{{
    110 $ ffmpeg -re -i input.mkv -vcodec libx264 -preset veryfast -maxrate 3000k \
     106$ ffmpeg -re -i input.mkv -c:v libx264 -preset veryfast -maxrate 3000k \
    111107-bufsize 6000k -pix_fmt yuv420p -g 50 -c:a aac -b:a 160k -ac 2 \
    112108-ar 44100 -f flv rtmp://live.twitch.tv/app/<stream key>
     
    118114
    119115{{{
    120 $ ffmpeg -i input.mkv -vcodec libx264 -preset medium -maxrate 3000k -bufsize 6000k \
    121 -vf "scale=1280:-1,format=yuv420p" -g 50 -acodec libmp3lame -b:a 128k -ac 2 -ar 44100 file.flv
     116$ ffmpeg -i input.mkv -c:v libx264 -preset medium -maxrate 3000k -bufsize 6000k \
     117-vf "scale=1280:-1,format=yuv420p" -g 50 -c:a aac -b:a 128k -ac 2 -ar 44100 file.flv
    122118}}}
    123119
    124120Then [http://ffmpeg.org/ffmpeg.html#Stream-copy stream copy] it to the streaming service:
    125121{{{
    126 $ ffmpeg -re -i file.flv -codec copy -f flv rtmp://live.twitch.tv/app/<stream key>
     122$ ffmpeg -re -i file.flv -c copy -f flv rtmp://live.twitch.tv/app/<stream key>
     123}}}
     124
     125=== Outputting to multiple streaming services & local file ===
     126
     127You can use the [https://ffmpeg.org/ffmpeg-formats.html#tee-1 tee muxer] to efficiently stream to multiple sites and save a local copy if desired. Using tee will allow you to encode only once and send the same data to multiple outputs. Using the `onfail` option will allow the other streams to continue if one fails.
     128
     129{{{
     130$ ffmpeg -i input -map 0 -c:v libx264 -c:a aac -muxrate 1000k -bufsize 2000k -g 50 -f tee \
     131"[f=flv:onfail=ignore]rtmp://facebook|[f=flv:onfail=ignore]rtmp://youtube|local_file.mkv"
    127132}}}
    128133
     
    131136== Notes ==
    132137
    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 | awk '/-geo/{print $2}')`.
     138* Linux users 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 | awk '/-geo/{print $2}')`.
    134139
    135140* 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`.