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:\phpEdit
C:\php\php.iniand uncomment theextension=php_curl.dllline´git clone https://github.com/K-S-V/Scripts`
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" --deleteUse
ffmpegto 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
ts.txtConcatenate
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/deadbeef012345678890abcdefabcdefrtmp://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/channel1rtmp://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
Links
Command line arguments
misc
-yOverwrite output files without asking-loglevel debug(or verbose, quiet, panic, fatal)
Input
-f dshowuse DirectShow Filter-i video="Integrated Camera":audio="Microphone (Realtek High Definition Audio)"use internal web cam and microphone
Video output
-s 640x480Resolution-codec:v libx264H.264 / AVC video-pix_fmt yuv420ppixel format YUV420-preset veryfast(ultrafast,superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo)-b:v 200ktarget video bit rate-minrate 200kminimum video bit rate-maxrate 200kmaximum video bit rate-r 30frame rate-keyint_min 60minimum GOP size-g 60maximum GOP size-sc_threshold 0scene change threshold-bsf:v h264_mp4toannexbbitstream filter. Useffmpeg -bsfsfor a full list-profile:v mainpreset according to docs-level 3.1compatible level according to docs
Audio output
-codec:a libvo_aacencAAC audio-b:a 128kaudio bit rate-ar 44100audio sampling frequency-ac 2audio channels-strict experimental
overall stream
-bufsize 200kbuffer size-maxrate 200kmaximim bit rate
Destination
-f flv rtmp://chan1-acc2.channel.mediaservices.windows.net:1936/live/deadbeef/chan1target 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
[FFMPEG for TS streaming](https://www.wowza.com/forums/content.php?213-How-to-use-FFmpeg-with-Wowza-Media-Server-(MPEG-TS))
Open Broadcaster Software (OBS Classic & OBS Studio)
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