POSTS
🎥ffmpeg howto/examples
By Philip
FFMPEG is a video and audio manipulation library and cli program.
ffmpeg
is the main toolffplay
is a simple graphical viewer.ffprobe
will only probe input data (file, stream, … )
A short explanation how the ffmpeg cli accepts parameters:
ffmpeg <globaloptins> <format> <inputfile_options> <input> <output_option> <output>
show info
the ffmpeg cli has alot of options, this will give you a good starting point to find info about them:
get info about available input formats
ffplay -formats
get available filter info
ffmpeg -filters
get available codecs
ffmpeg -codecs
is hardware en/decode available?
ffmpeg -hwaccels
get system devices (audio, video, other hardware)
ffmpeg -devices
what options has a specific encoder?
# h264 software en/decoder
ffmpeg -h encoder=h264
# nvidia hardware encoder
ffmpeg -h encoder=h264_nvenc
The ffmpeg website has good documentation section:
http://ffmpeg.org/documentation.html
example snippets
next are some command line’s i use, with a small explanation how they work or what his needed
re/encode a video file
most basic encode to h264 (default encoder):
ffmpeg -i input.avi output.mp4
without audio, and lower quality
ffmpeg -i input.avi -an -crf 30 output.mp4
explantion:
ffmpeg
command-i input.avi
|the input file-an
: audio none, this will strip the audio-crf 30
: encoder qualtity (a higher number lowers the quality) the default encoder is x264 and the default crf (qualtiy factor) is 23output.mp4
: the name of the output file
hardware assisted encoding
ffmeg is able to use hardware to accelerate the processing of video data. Be aware that you need certain hardware. I only tested this with nvidia hardware but amd/ati will also be able to proffit from hardware assist.
ffmpeg -i input.avi -c:v h264_nvenc -crf 20 output.mp4
-c:v h264_nvenc
select the h264 nvidia codec for video-crf 20
encoder quality (higher numbers,lower the quality). The hardware encoder default uses a lower quality, I want more quality that is why i up it a little here.
encode ‘analog’ video
I use this to recompress analog fpv video’s
ffmpeg -i input.avi -vf deband,deflicker,hqdn3d -crf 25 output.mp4
explained:
ffmpeg
: command-i input.avi
: the input file-vf deband,deflicker,hqdn3d
: videofilter-crf 25
: lower the quality a little (default is 23), this gives smaller files and the video quality isn’t noticable for meoutput.mp4
: the name of the output file
stabilize shaky video
a 2 step process to create a stabilized, smoother video. for example: an old gopro’s video. note:
- output video will be a bit cropped, zoomed in
- underwater video’s near the surface can act wierd because the stabilizer try’s to stabilize the water mirror
step 1: analyse the source video
ffmpeg -i input.avi -vf vidstabdetect dummy.mp4
explained:
-i input.avi
the input file-vf vidstabdetect
analyze input video motiondummy.mp4
a dummy output file, can safely be deleted after the analyzing step
step 2 : stabilize the video
ffmpeg -i input.avi -vf vidstabtransform,unsharp output.mp4
explained:
-i input.avi
the input file-vf vidstabtransform,unsharp
vidstabtransform
transform the video to smooth it outunsharp
needed for the vidstabtransform to work
output.mp4
output video, wich is stabilized
more info: http://public.hronopik.de/vid.stab/
screen record
windows
ffmpeg.exe -f gdigrab -i desktop output.mp4
-f gdigrab
the format is gdigrab, a windows screen api-i desktop
select the desktop as gdigrab input
linux
ffmpeg -f x11grab -i :0.0 output.mp4
-f x11grab
the format is x11grab, X11 screen api-i :0.0
select screen 0 as x11grab input
screen record with hardware encode
windows
for this you need an nvidia card This is tested on 1920x1600, for higher screen resolutions you need to adjust the b:v and maxrate:v
ffmpeg.exe -f gdigrab -i desktop -c:v h264_nvenc -b:v 6M -maxrate:v 10M -rc:v vbr_hq output.mp4
-f gdigrab
the format is gdigrab, a windows screen api-i desktop
select the desktop as gdigrab input-c:v h264_nvenc
select the hardware h264 nvidia codec for video-b:v 6M
set video rate at 6M (for higher quality) note: you need to adjust this higher is you use a higher desktop resoloution.-maxrate:v 10M
set maximum burst rate to 10M. same note as previous-rc:v vbr_hq
set rate control to variable bit rate and high quality
for more info and options: ffmpeg -h encoder=h264_nvenc
references: nvidia website and stackoverflow
audio record
windows
fist you need to list the available audio devices
ffmpeg -list_devices true -f dshow -i dummy
see the ability’s of the input device
ffmpeg -f dshow -list_options true -i audio="Microfoon (High Definition Audio-apparaat)"
record audio
ffmpeg -f dshow -i audio="Microfoon (Realtek High Definition Audio)" output.ogg
linux
TODO
ffmpeg documentation & reference
- h264 codec: https://ffmpeg.org/ffmpeg-codecs.html#libx264_002c-libx264rgb
- h265 codec: https://ffmpeg.org/ffmpeg-codecs.html#libx265
- video filters: https://ffmpeg.org/ffmpeg-filters.html#Video-Filters
- vorbis codec: http://ffmpeg.org/ffmpeg-codecs.html#libvorbis