Skip to content

Instantly share code, notes, and snippets.

@khavari
Last active April 27, 2022 17:51
Show Gist options
  • Save khavari/adf2dae16e93a76918ce82f91d5f13b6 to your computer and use it in GitHub Desktop.
Save khavari/adf2dae16e93a76918ce82f91d5f13b6 to your computer and use it in GitHub Desktop.
FFmpeg Commands

Useful FFmpeg Commands

Install FFmpeg:

sudo apt update
sudo apt install ffmpeg
ffmpeg -version

Get Video File Information:

ffmpeg -i my_video.mp4

Split a video into images:

To turn a video to number of images, run the command below. The command generates the files named image_1.jpg, image_2.jpg and ...

ffmpeg -i my_video.mp4 image_%d.jpg

Convert images into a video:

Turn number of images to a video sequence, use the following command. This command will transform all the images from the current directory (named image_1.jpg, image_2.jpg, etc…) to a video file named my_new_video.mp4

ffmpeg -f image2 -i image_%d.jpg my_new_video.mp4

Extract audio from video file:

ffmpeg -i my_video.mp4 -vn -ar 44100 -ac 2 -ab 192 -f mp3 my_audio.mp3

Covert mp4 video file to mpg format

ffmpeg -i my_video.mp4 my_new_video.mpg

for f in *.mkv; do ffmpeg -i "$f" -c copy "${f%.mkv}.mp4"; done

ffmpeg -i example.mkv -c copy example.mp4

Mix a video and audio together:

ffmpeg -i my_audio.mp3 -i my_video.mp4 my_video_audio_mix.mp4

Remove audio from video file:

ffmpeg -i my_video.mp4 -c copy -an my_soundless_video.mp4

Increase/Reduce Video Playback Speed:

ffmpeg -i my_video.mp4 -vf "setpts=0.5*PTS" my_highspeed_video.mp4
ffmpeg -i video.mpg -vf "setpts=4.0*PTS" lowerspeed.mpg -hide_banner

Add Photo or Banner to Audio:

ffmpeg -loop 1 -i my_image.png -i my_audio.mp3 -c:v libx264 -c:a aac -strict experimental -b:a 192k -shortest my_audio_and_image.mp4

Add subtitles to a Movie: !!

ffmpeg -i my_video.mp4 -i my_subtitle.srt -map 0 -map 1 -c copy -c:v libx264 -crf 23 -preset veryfast my_video_with_subtitle.mp4

Resize a video to make it smaller:

ffmpeg -i my_video.mp4 -s 720x480 -c:a copy output.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment