Wednesday, 23 May 2018

Frequently requested FFMPEG command

Usage


A basic ffmpeg command is of the following form:

ffmpeg [INPUT OPTIONS] -i [INPUT] [OUTPUT OPTIONS] [OUTPUT]

Parameters placed before the input apply to the input. For example, if the source is a file, prefix with the "-re" option to limit reading the input (and hence writing the output) to the encoded bitrate.

ffmpeg -re -i [INPUT] [OUTPUT OPTIONS] [OUTPUT]

FFmpeg supports some protocols that can be push-published directly to a Wowza application and are available for viewing automatically: RTMP, RTSP. The OUTPUT URL looks like this:

[protocol]://[wowza-ip-address]/[application]/[streamName]

Other protocols such as MPEG-TS, or RTP with SDP, must be "started" manually using the StreamManager, automatically using StartupStreams.xml, or programmatically with the StreamClass API. OUTPUT URL format: 

[protocol]://[wowza-ip-address]:[dstport]


Inputs


1. Some VOD file path examples:

"%WMSAPP_HOME%/content/sample.mp4"

/usr/local/WowzaMediaServer/content/bigbuckbunny_1500.mp4

myRecording.mp3

streamcapture.ts

myStream.flv

2. RTSP/RTP camera:

rtsp://192.168.1.22/mycamera

3. MPEG-TS stream:

udp://localhost:1234

4. Native RTP stream SDP file:

unicast.sdp

5. RTMP source:

rtmp://[Streaming-Server-IP]:1935/vod/mp4:sample.mp4

6. Hardware device:

-f dshow -i video="Integrated Webcam" 

7. Linux X11 Desktop:

-f x11grab -s wxga -r 25 -i :0.0 -sameq 

Outputs


Note: Refer to the corresponding tutorial for your chosen live output stream type.

1. RTMP:

-f flv rtmp://127.0.0.1/live/myStream

2. RTSP

-f rtsp -muxdelay 0.1 rtsp://127.0.0.1:1935/live/myStream

3. RTSP (with publish password):

-f rtsp -muxdelay 0.1 rtsp://username:secretword@127.0.0.1:1935/live/myStream

4. RTP with SDP:

-f rtp rtp://127.0.0.1:10000 > "%WMSAPP_HOME%/content/10000.sdp"

-This will write an .sdp file to the Wowza content directory which can be started in Stream Manager.

5. MPEG-TS (requires .stream file and Stream Manager):

-vbsf h264_mp4toannexb -f mpegts udp://127.0.0.1:10000?pkt_size=1316

Examples



1. Output RTMP without transcoding:

  1. ffmpeg -re -i "%WMSAPP_HOME%/content/sample.mp4" -c:v copy -c:a copy -f flv rtmp://127.0.0.1/live/myStream


2. RTSP low bandwidth baseline stream:

-H.264/AAC, Baseline profile, level 1.2, 12FPS, keyframe at least every 96 frames (8 seconds), 110kbps video, 212x120 resolution, 40kbps audio, 22.05khz, mono 

  1. ffmpeg -re -i sample.mp4 -c:v libx264 -profile:v baseline -level:v 1.2 -r 12 -g 96 -vb 110000 -s 212x120 -c:a libvo_aacenc -ab 40000 -ar 22050 -ac 1 -f rtsp -muxdelay 0.1 rtsp://127.0.0.1/live/myStream


3. RTSP with publish password:

-H.264/AAC, Baseline profile, level 3.0, 24FPS, 2sec keyframe exactly, 350kbps stream, 44.1khz, stereo

  1. ffmpeg -re -i sample.mp4 -c:v libx264 -profile:v baseline -level 3.0 -r 24 -g 48 -keyint_min 48 -sc_threshold 0 -vb 310k -c:a libvo_aacenc -ab 40k -ar 44100 -ac 2 -f rtsp -muxdelay 0.1 rtsp://username:secretword@127.0.0.1:1935/live/myStream


4. MPEG-TS:

-H.264/AAC, Main profile, level 3.1, 24FPS, 4sec max keyframe interval, 404kbps constant bitrate video, 96kbps audio, 48khz, stereo

  1. ffmpeg -re -i sample.mp4 -c:v libx264 -profile:v main -level 3.1 -r 24 -g 96 -maxrate 404000 -minrate 404000 -bufsize 125k -c:a libvo_aacenc -ab 96000 -ar 48000 -ac 2 -vbsf h264_mp4toannexb -f mpegts udp://127.0.0.1:10000?pkt_size=1316


5. RTP with SDP:

-Capture local hardware devices, generate SDP file in current directory. Set 15FPS source framerate, 12bit color. 

  1. ffmpeg -y -f dshow -s 640x480 -r:v 15 -i video="Integrated Webcam":audio="Microphone (Realtek High Defini" -c:v libx264 -pix_fmt yuv420p -vb 450 -an -map 0:0 -f rtp rtp://127.0.0.1:10000 -flags +global_header -c:a libvo_aacenc -vn -map 0:1 -f rtp rtp://127.0.0.1:10002 > 10000.sdp


Miscellaneous FFMPEG Hints


1. Show VOD or Live stream encoding parameters for troubleshooting:

ffprobe -show_streams [media]

2. List available hardware device names such as webcams and microphones, for use as FFmpeg inputs:

ffmpeg -list_devices true -f dshow -i dummy

3. When testing short videos you may want loop your command to generate a constant test stream:

Windows: FOR /L %% IN (0) DO YourCommand

4. Convert .ts file (or any FFmpeg compatible input) to .mp4 container for use with Wowza VOD playback:

ffmpeg -i input.ts -c:v copy -c:a copy output.mp4

5. Check VOD files for keyframe alignment (Linux):

ffprobe -output_format csv -show_frames [media] |grep I 

-For each file in your multibitrate rendition ensure the PTS and/or DTS timestamps are identical for each corresponding I-frame.

6. Generate keyframe aligned multi-bitrate VOD rendition (Linux):

Use this media source for testing.

  1. ffmpeg -y -i bigbuckbunny_1500.mp4 -c:a libfaac -ac 2 -ab 64k -c:v libx264 -preset:v veryfast -threads 0 -r 24 -g 48 -keyint_min 48 -sc_threshold 0 -x264opts no-mbtree:bframes=1 -pass 1 -b:v 286k -s 384x216 bigbuck-350k.mp4
  2. ffmpeg -y -i bigbuckbunny_1500.mp4 -c:a libfaac -ac 2 -ab 64k -c:v libx264 -preset:v fast -threads 0 -r 24 -g 48 -keyint_min 48 -sc_threshold 0 -x264opts no-mbtree:bframes=1 -pass 2 -b:v 286k -s 384x216 bigbuck-350k.mp4
  3. ffmpeg -y -i bigbuckbunny_1500.mp4 -c:a libfaac -ac 2 -ab 64k -c:v libx264 -preset:v fast -threads 0 -r 24 -g 48 -keyint_min 48 -sc_threshold 0 -x264opts no-mbtree:bframes=1 -pass 2 -b:v 836k -s 640x360 bigbuck-900k.mp4

No comments:

Post a Comment