ffmpeg | Cheatsheet¶
FFmpeg is a free and open-source software project consisting of a suite of libraries and programs for handling video, audio, and other multimedia files and streams. At its core is the command-line ffmpeg tool itself, designed for processing of video and audio files
Install media-video/ffmpeg
```bash echo "X alsa bzip2 dav1d encode gnutls gpl iconv mp3 network opengl postproc pulseaudio sdl svg threads truetype vorbis x264 xvid zlib cpudetection doc fontconfig jpeg2k libcaca libdrm librtmp libv4l lzma openh264 openssl samba ssh v4l webp x265"
/etc/portage/package/use/dnsmasq emerge --ask media-video/ffmpeg
Cut mp3 file from 30
seconds to 70
¶
This command cuts an MP3 file from the 30-second mark to the 70-second mark and saves it as a new MP3 file without re-encoding the audio stream.
Extract sound from movie file (-vn = no video)
¶
This command extracts the audio stream from a movie file and saves it as an MP3 file.
Cut mp3
file from 30
seconds to 70
only audio¶
This command cuts an MP3 file from the 30-second mark to the 70-second mark, encoding only the audio stream.
ffmpeg -i Molle_Musikvideo_Jobba,_Jobba,_Jobba-26tzRuurdgo.mkv -ss 56 -t 61 -q:a 0 -map a molle_-_jobba.jobba.mp3
Convert mp3
to ogg
¶
This command converts an MP3 file to the OGG format.
Convert all mp3
files in current dir to ogg
¶
This command converts all MP3 files in the current directory to the OGG format.
Convert all mp3
files in current dir to ogg
recursive¶
This command converts all MP3 files in the current directory and its subdirectories to the OGG format recursively.
find . -type f -name '*.mp3' -exec bash -c 'ffmpeg -i "$0" \
-c:a libvorbis -q:a 4 "${0/%mp3/ogg}"' '{}' \;
Stream video and audio using RTP¶
Stream video and audio from a source to a destination using RTP protocol.
Convert audio to FLAC¶
Convert an audio file to the FLAC format using SoX.
ffmpeg -loglevel 0 -y -i audio.mp3 -f sox - | sox -p -V -S -b24 -t audio.flac gain -3 rate -va 7056000 rate -v 48k
Capture video from webcam and audio from microphone¶
Capture video from a webcam and audio from the default microphone, and save it as an MP4 file.
Convert video to AVI with specific codecs¶
Convert a video file to AVI format with MPEG-4 video codec and MP3 audio codec.
Crop video¶
Crop a video file to a specific region.
Extract frames from video¶
Extract frames from a video file and save them as individual images.
Create video from frames¶
Create a video file from a sequence of images.
Add watermark to video¶
Add a watermark image to a video file.
ffmpeg -i input.mp4 -vhook '/usr/lib/vhook/watermark.so -f watermark.png -m 1 -t 222222' -an output.flv
Add text overlay to video¶
Add a text overlay to a video file.
ffmpeg -i input.flv -vhook '/usr/lib/vhook/imlib2.so -c white -x 250 -y H+(-1.8*N+80) -t Hallo! -A max(0,255-exp(N/16))' -sameq -acodec copy output.flv
Extract audio from video¶
Extract the audio stream from a video file and save it as an MP3 file.
Convert images to video¶
Convert a sequence of images to a video file.
Convert video file format¶
Convert a video file from one format to another.
Record desktop screen and audio¶
Record the desktop screen and audio and save it
as a MKV file.
ffmpeg -f alsa -ac 2 -i pulse -f x11grab -r 30 -s 1024x768 -i :0.0 -acodec pcm_s16le -vcodec libx264 -vpre lossless_ultrafast -threads 0 output.mkv
Trim audio file¶
Trim a section of an audio file.
Create video from image and audio¶
Create a video file from an image and an audio file.
Convert video to 3GP format¶
Convert a video file to 3GP format.
Record screen video using x11grab¶
Record the screen video using x11grab and save it as MPG file.
ffmpeg -f x11grab -s `xdpyinfo | grep 'dimensions:'|awk '{print $2}'` -r 25 -i :0.0 -sameq /tmp/output.mpg
Record audio and video from devices¶
Record audio from ALSA and video from video4linux2 devices and save as AVI file.
ffmpeg -f alsa -r 16000 -i hw:2,0 -f video4linux2 -s 800x600 -i /dev/video0 -r 30 -f avi -vcodec mpeg4 -vtag xvid -sameq -acodec libmp3lame -ab 96k output.avi
Merge video and audio files¶
Merge a video file and an audio file into a single video file.
Extract audio from video and convert to MP3¶
Extract the audio stream from a video file and save it as an MP3 file.
Convert video to animated GIF¶
Convert a video file to an animated GIF.
ffmpeg -i input.flv -vf scale=320:-1 -r 10 -f image2pipe -vcodec ppm - | convert -delay 5 -loop 0 - output.gif
Record desktop screen with audio¶
Record the desktop screen with audio and save it as a MKV file.
ffmpeg -f alsa -ac 2 -i hw:0,0 -f x11grab -r 30 -s $(xwininfo -root | grep 'geometry' | awk '{print $2;}') -i :0.0 -acodec pcm_s16le -vcodec libx264 -vpre lossless_ultrafast -threads 0 -y output.mkv
Convert video with experimental settings¶
Convert a video file with experimental settings to a specific format.
Convert video to¶
MP4 for iPod
Convert a video file to MP4 format with specific settings for iPod.
ffmpeg -i [source].avi -f mp4 -vcodec mpeg4 -b 250000 -s 480?320 -acodec aac -ar 24000 -ab 64 -ac 2 [destination].mp4
Convert video to MPEG format¶
Convert a video file to MPEG format for VCD.
ffmpeg -i movie.avi -y -f vcd -vcodec mpeg1video -map 0.0:0.0 -b 1150 -s 352x240 -r 29.97 -g 12 -qmin 3 -qmax 13 -acodec mp2 -ab 224 -ar 44100 -ac 2 -map 0.1:0.1 movie.mpg
Trim video file¶
Trim a section of a video file.
Convert audio with specific settings¶
Convert an audio file with specific audio codec and bitrate.
Fix broken video file¶
Fix a broken video file by copying the audio and video streams.
Convert M4A to MP3¶
Convert an M4A audio file to MP3 format.
Merge audio and video files with offset¶
Merge an audio file and a video file with an audio offset.
Extract audio from video and keep original format¶
Extract the audio stream from a video file and keep it in the original format.
Convert video to 3GP for mobile devices¶
Convert a video file to 3GP format with specific settings for mobile devices.
ffmpeg -i input.avi -s qcif -vcodec h263 -r 20 -b 180k -acodec libfaac -ab 64k -ac 2 -ar 22050 output.3gp
Extract audio from video and save as AC3 file¶
Extract the audio stream from a video file and save it as an AC3 file.
Capture video from video4linux device¶
Capture video from a video4linux device and save it as an AVI file.
Merge video and audio files with specific mapping¶
Merge a video file and an audio file with specific mapping of streams.
Convert video to MP3¶
Convert a video file to MP3 format by extracting the audio stream.
Convert image sequence to video¶
Convert a sequence of images to a video file.
Merge MP3 files using concat protocol¶
Merge multiple MP3 files using the concat protocol.
ffmpeg -i "concat:$(find . -name "*.mp3" | sort | tr '\n' '|')" -acodec copy output.mp3 && mp3val -f output.mp3
Convert WAV to MOV¶
Convert a WAV audio file to MOV format.
Record screen video using x11grab¶
Record the screen video using x11grab and save it as MPG file.
Extract audio from video and convert to MP3¶
Extract the audio stream from a video file and convert it to MP3 format.
Create video from image and audio¶
Create a video file from an image and an audio file.
ffmpeg -r 24 -i %04d.png -i INPUTSOUND -r 24 -aspect 16:9 -s 1920x1080 -vcodec libx264 -vpre hq -acodec ac3 -b 40000k -shortest -threads 0 OUTFILE.mp4
Crop video file¶
Crop a video file to a specific region.
Copy audio and video streams with a timestamp¶
Copy audio and video streams from the input file to the output file with a specific timestamp.
Crop video file with specific dimensions¶
Crop a video file to specific dimensions.
Trim video file with specific duration¶
Trim a video file to a specific duration.
Convert video for VCD¶
Convert a video file to VCD format.
Increase volume of audio file¶
Increase the volume of an audio file.
Add overlay image to video¶
Add an overlay image to a video file.
Record desktop screen¶
Record the desktop screen and save it as an MPG file.
Convert video with specific settings¶
Convert a video file with specific video and audio codecs.
Record screen video using x11grab¶
Record the screen video using x11grab and save it as MPG file.
Convert video with specific settings¶
Convert a video file with specific video and audio codecs and settings.
ffmpeg -i in.mkv -acodec libfaac -ab 128k -ac 2 -vcodec libx264 -vpre max -crf 22 -threads 0 out.mp4
Record screen video using x11grab¶
Record the screen video using x11grab and save it as MPG file.
Convert video with specific settings¶
Convert a video file with specific video and audio codecs and settings.
ffmpeg -i in.mkv -acodec libfaac -ab 128k -ac 2 -vcodec libx264 -vpre max -crf 22 -threads 0 out.mp4
Convert video with specific settings¶
Convert a video file with specific video and audio codecs and settings.
ffmpeg -i initial.mkv -acodec libvorbis -ab 128k -ac 2 -vcodec libx264 -vpre max -crf 22 -threads 0 final.mkv
Increase volume of audio file¶
Increase the volume of an audio file.
Add overlay image to video¶
Add an overlay image to a video file.
Record screen video using x11grab¶
Record the screen video using x11grab and save it as MPG file.
Convert video with specific settings¶
Convert a video file with specific video and audio codecs and settings.
ffmpeg -i in.mkv -acodec libfaac -ab 128k -ac 2 -vcodec libx264 -vpre max -crf 22 -threads 0 out.mp4
Convert video with specific settings¶
Convert a video file with specific video and audio codecs and settings.
Extract¶
audio from video and convert to MP3
Extract the audio stream from a video file and convert it to MP3 format.
Convert video to animated GIF¶
Convert a video file to an animated GIF.
ffmpeg -i input.flv -vf scale=320:-1 -r 10 -f image2pipe -vcodec ppm - | convert -delay 5 -loop 0 - output.gif
Record desktop screen with audio¶
Record the desktop screen with audio and save it as a MKV file.
ffmpeg -f alsa -ac 2 -i hw:0,0 -f x11grab -r 30 -s $(xwininfo -root | grep 'geometry' | awk '{print $2;}') -i :0.0 -acodec pcm_s16le -vcodec libx264 -vpre lossless_ultrafast -threads 0 -y output.mkv
Convert video with experimental settings¶
Convert a video file with experimental settings to a specific format.
Convert video to MP4 for iPod¶
Convert a video file to MP4 format with specific settings for iPod.
ffmpeg -i [source].avi -f mp4 -vcodec mpeg4 -b 250000 -s 480?320 -acodec aac -ar 24000 -ab 64 -ac 2 [destination].mp4
Convert video to MPEG format¶
Convert a video file to MPEG format for VCD.
ffmpeg -i movie.avi -y -f vcd -vcodec mpeg1video -map 0.0:0.0 -b 1150 -s 352x240 -r 29.97 -g 12 -qmin 3 -qmax 13 -acodec mp2 -ab 224 -ar 44100 -ac 2 -map 0.1:0.1 movie.mpg
Trim video file¶
Trim a section of a video file.
Convert audio with specific settings¶
Convert an audio file with specific audio codec and bitrate.
Fix broken video file¶
Fix a broken video file by copying the audio and video streams.
Convert M4A to MP3¶
Convert an M4A audio file to MP3 format.
Merge audio and video files with offset¶
Merge an audio file and a video file with an audio offset.
Extract audio from video and keep original format¶
Extract the audio stream from a video file and keep it in the original format.
Convert video to 3GP for mobile devices¶
Convert a video file to 3GP format with specific settings for mobile devices.
ffmpeg -i input.avi -s qcif -vcodec h263 -r 20 -b 180k -acodec libfaac -ab 64k -ac 2 -ar 22050 output.3gp
Extract audio from video and save as AC3 file¶
Extract the audio stream from a video file and save it as an AC3 file.
Capture video from video4linux device¶
Capture video from a video4linux device and save it as an AVI file.
Merge video and audio files with specific mapping¶
Merge a video file and an audio file with specific mapping of streams.
Convert video to MP3¶
Convert a video file to MP3 format by extracting the audio stream.
Convert image sequence to video¶
Convert a sequence of images to a video file.
Merge MP3 files using concat protocol¶
Merge multiple MP3 files using the concat protocol.
ffmpeg -i "concat:$(find . -name "*.mp3" | sort | tr '\n' '|')" -acodec copy output.mp3 && mp3val -f output.mp3
Convert WAV to MOV¶
Convert a WAV audio file to MOV format.
Record screen video using x11grab¶
Record the screen video using x11grab and save it as MPG file.
Extract audio from video and convert to MP3¶
Extract the audio stream from a video file and convert it to MP3 format.
Create video from image and audio¶
Create a video file from an image and an audio file.
ffmpeg -r 24 -i %04d.png -i INPUTSOUND -r 24 -aspect 16:9 -s 1920x1080 -vcodec libx264 -vpre hq -acodec ac3 -b 40000k -shortest -threads 0 OUTFILE.mp4
Crop video file¶
Crop a video file to a specific region.
```bash ffmpeg -acodec copy -vcodec copy -ss 00:05:00 -t 00: