Simple commands to learn FFMPEG in real use case 🎥

1 — Converting a simple video

ffmpeg -i video.mov out.mp4
  • -i input file : this is the input file to proceed
  • out.mp4 : this is the file generated by ffmpeg
Simple command that optimizes video size (4,3M to 1.1M)

2 — Processing video without reencoding

ffmpeg -i video.mp4 -c:v copy -c:a copy out.mp4
  • -c:v copy : copy the video (v) track to the output file without transcoding (no processing on this track)
  • -c:a copy : copy the audio (a) track to the output file without transcoding (no processing on this track)

3 — Transcoding a video for the web (streamable)

Chrome reads the video file without downloading the entire file.
ffmpeg -i video_input.mp4  -movflags faststart out.mp4

4 — Creating a thumbnail from video (extract one frame)

ffmpeg -i video.mp4 -vframes 1 -ss 10.0 thumbnail.jpg
  • -vframes 1 : Proceeds only one frame of the video
  • -ss 10.0 : Grabs the frame at 10 seconds
  • .jpg : ffmpeg detects the output format with the extension of the file, so if you need an image, name your output file with a .jpg or .png extension.

5 — Changing the framerate of a video

ffmpeg -i video.mp4 -r 10 -c:v copy -c:a copy out.mp4
  • -r 10 : defines number of frame per seconds to generate on the output file
  • -c:v copy: We already viewed this parameter, but this is a good case to show how this parameter is important. You don’t need to transcode new frames on your output file, just copy 10 frames per second on the output file. With this command, the output file is generated in less than a second .

6 — Scaling down (change resolution) of a video

720p vs 1080p (5.9mo and 11mo)
ffmpeg -i video.mp4 -vf scale=-2:720 out.mp4
  • -vf scale=-2:720 : asks to rescale the video with width x height (-2 =auto, 720 = height)

7 — Trim a video (Cut beginning or end of the video) 🪚

ffmpeg -i video.mp4 -ss 10.0 out.mp4
  • -ss 10.0 : starts the input at 10 seconds (so remove the 0 to 10.0s of the video)
ffmpeg -i video.mp4 -t 10.0 out.mp4
  • -t 10.0 : generates the video only for 10.0s (so removes the 10.0s to the end of the video)

8— Create a Gif thumbnail from video

Gif thumbnail generated with ffmpeg 🌵
ffmpeg -i video.mp4 -ss 10.0 -t 5.0 -vf scale=-2:240 -r 7 -loop 0 thumbnail.gif
  • -r 7 : asks to generate only 7 frames per second, (it’s a gif not a video 😃)
  • -loop 0 : the output will loop at the end 🔁
  • .gif : defines a gif format for the output file

9 — Removing audio from a video 🤐

ffmpeg -i video.mp4 -map [0:v] out.mp4
  • -map [0:v]: maps the track video (v) from the first input (0)

10 — Replacing audio with an mp3 file 🎼

ffmpeg -i video.mp4 -i audio.mp3 -map [0:v] -map [1:a] out.mp4
  • -map [0:v]: maps the track video (v) from the first input (0)
  • -map [1:a]: maps the audio track (a) from the second input (1)

11 — Looping a video 🔁

Example of a 10 hours video (don’t click on ▶️ ! )
ffmpeg -re -f lavfi -i "movie=filename=video.mp4:loop=0, setpts=N/(FRAME_RATE*TB)" -t 600 out.mp4
  • filename=video.mp4: names of the video input
  • -t 600: duration in seconds of the video output (36,000 for 10 hours 🥴)

12 — Creating video from an image

Example of image to video use case
ffmpeg -loop 1 -i image.jpg -t 600 out.mp4
  • -loop 1: loops the input
  • -t 600: duration in seconds of the video output

13 — Launching ffmpeg in background

nice -n 19 ffmpeg -i input.mkv out.mp4
  • nice -n 19 : asks to the command to launch in priority 19 (20 is the lowest and -20 the highest) more information here

Conclusion

--

--

--

Hi, I’m Jeremy Rouet. I’m CTO / cofounder at https://weet.co and https://speach.me. I love imagining new features / concepts.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Python3: Mutable, Immutable… everything is object!

Attributes for Scaling SVGs

It’s Time to Take Back Your Data!

Software Test Automation Driving Maximized ROI and Reduced Time-to-Market!

UI tests practices to follow

Kludging AAAA for a tailnet

Airflow & Kubernetes Jobs

Episode 5. Understanding Docker Images and Containers in Depth

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jeremy Rouet

Jeremy Rouet

Hi, I’m Jeremy Rouet. I’m CTO / cofounder at https://weet.co and https://speach.me. I love imagining new features / concepts.

More from Medium

FTK Imager

Multi-version Odoo installation and configuration in PyCharm (odoo-10 and odoo-15)

Best Practices Around Workspace ONE Intelligent Hub For Windows When Using An Antivirus Or…

What is Cloudflare?