ffmpeg - Processing Media

Describe a couple of ffmpeg recipes

Download video from the web

HDS videos on Windows

The following snippet uses a PHP Script (executed at the command line) to download an HDS manifest and assembles the video fragments:

  • Download PHP for Windows and unpack to C:\php

  • Edit C:\php\php.ini and uncomment the extension=php_curl.dll line

  • php.exe AdobeHDS.php --manifest "http://adaptiv.wdr.de/...mp4.csmil/manifest.f4m?g=...&hdcore=3.10.0&plugin=aasp-3.10.0.29.28" --delete

  • Use ffmpeg to convert FLV to MP4 (ffmpeg -i 1.flv -vcodec copy -acodec copy -map_metadata 0 1.mp4)

Download HLS videos

Using RTMPDump to fetch an RTMP source

Download YouTube and create an animated GIF from sub-part

Convert videos

Figure out which DirectShow input devices I have

On my work laptop, I have an integrated web cam, a built-in microphone, and an additional head set:

The strings "Integrated Camera", "Microphone (Realtek High Definition Audio)" and "Headset Microphone (Plantronics C520-M)" now refer to the different usable sources. In ffmpeg, the -i parameter usually refers to the input file. In our case, we can now combine video & audio sources to an input specification for ffmpeg:

  • -i video="Integrated Camera":audio="Headset Microphone (Plantronics C520-M)"

  • -i video="Integrated Camera":audio="Microphone (Realtek High Definition Audio)"

Determine the capabilities of the hardware

Capture the local web cam & microphone and create a 5sec MP4 video

Stream TS (untested)

Src: https://elixirforum.com/t/live-video-cam-streaming-in-mpeg-ts-format/16957

Screen capture

Screen capture filter

For capturing the local screen, you need a driver to tap into the video card. ffmpeg on Windows ships with the GDI grabber -f gdigrab filter.

It is also possible to use a DirectShow filter (-f dshow), but then you need a driver.

After installing the driver above, you will be able to use the ffmpeg input

Write a 10 second screen capture (at 20 fps) to local MP4 file

Play back current screen

Capture web cam on my Lenovo

Concatenate videos

Convert individually to TS

ts.txt

Concatenate

Azure Media Players

Streaming to Azure Media Services Live Streaming

After creating an Azure Media Services Live channel, we get two RTMP ingest endpoints, which differ in their TCP port number (1935 and 1936):

  • rtmp://channel1-mediaservice321.channel.mediaservices.windows.net:1936/live/deadbeef012345678890abcdefabcdef

  • rtmp://channel1-mediaservice321.channel.mediaservices.windows.net:1936/live/deadbeef012345678890abcdefabcdef

For ffmpeg to work, we need to append the channel name /channel1 to the URLs:

  • rtmp://channel1-mediaservice321.channel.mediaservices.windows.net:1936/live/deadbeef012345678890abcdefabcdef/channel1

  • rtmp://channel1-mediaservice321.channel.mediaservices.windows.net:1936/live/deadbeef012345678890abcdefabcdef/channel1

Input specs

The Azure Blog now tells us to use RTMP with H.264 video and AAC audio, a 2-second key-frame interval, and CBR (constant bit rate) encoding.

Configuring ffmpeg

Command line arguments

misc

  • -y Overwrite output files without asking

  • -loglevel debug (or verbose, quiet, panic, fatal)

Input

  • -f dshow use DirectShow Filter

  • -i video="Integrated Camera":audio="Microphone (Realtek High Definition Audio)" use internal web cam and microphone

Video output

  • -s 640x480 Resolution

  • -codec:v libx264 H.264 / AVC video

  • -pix_fmt yuv420p pixel format YUV420

  • -preset veryfast (ultrafast,superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo)

  • -b:v 200k target video bit rate

  • -minrate 200k minimum video bit rate

  • -maxrate 200k maximum video bit rate

  • -r 30 frame rate

  • -keyint_min 60 minimum GOP size

  • -g 60 maximum GOP size

  • -sc_threshold 0 scene change threshold

  • -bsf:v h264_mp4toannexb bitstream filter. Use ffmpeg -bsfs for a full list

  • -profile:v main preset according to docs

  • -level 3.1 compatible level according to docs

Audio output

  • -codec:a libvo_aacenc AAC audio

  • -b:a 128k audio bit rate

  • -ar 44100 audio sampling frequency

  • -ac 2 audio channels

  • -strict experimental

overall stream

  • -bufsize 200k buffer size

  • -maxrate 200k maximim bit rate

Destination

  • -f flv rtmp://chan1-acc2.channel.mediaservices.windows.net:1936/live/deadbeef/chan1 target RTMP endpoint to push to

Ingest the RTMP stream

You can use the DASHPlayer or aka.ms/azuremediaplayer. Don't forget to append (format=mpd-time-csf) or (format=m3u8-aapl) to the streams for DASH or HLS streaming.

MPEG TS Streaming

Single bitrate:

Multi bitrate ( 3 bit rates 500, 300 and 150 Kbps)

Interesting FFMPEG Articles

Using FFMPEG to convert audio files

Convert a bunch of MP3 files to an iPod audio book

Using FFMPEG to create VOD files

Convert FLV (Flash Video) into real MP4

Files are FLVs, but named MP4. Make them real MP4. The -map_metadata 0 ensures that metadata like date etc flows over to the new file.

Concatenate video files

In order to concatenate MP4 files, each file must be converted into a Transport Stream (.ts), i.e. without a MOOV atom, and then concatenated and re-written into a proper .mp4 file (with MOOV atom):

Alternatively, you can list all input files in a text file:

Create MP4 from single images

Render Game Frame previews from a series of PNGs

Download art from the Game Frame Art Forum

Repair MP4

http://www.videohelp.com/software/recover-mp4-to-h264

Generate HLS

2-second TS

Last updated