A Guide To Video And Audio Conversion Using FFmpeg


Install ffmpeg

  • brew install ffmpeg at MacOs.
  • sudo apt install ffmpeg
  • ffmpeg -version to check the version.
  • It provides 3 commands
    • ffmpeg
    • ffplay: a minimalistic player for testing ffmpeg
    • ffprobe: a simple analysis tool to inspect multimedia content.

Convert between different video formats

  • just specify the input video file, and the output video file with correct suffix, ffmpeg automatically selects the correct codecs.
  • ffmpeg supports conversion for most video types: avi, rmvb, mp4, webm, mkv, mpg, flv, dv, mpeg (used by dvd player)
  • ffmpeg -codecs to list all supported files.

Convert video to audio

Add Text Subtitles to a Video

Create gif from video

  • ffmpeg -i input.mp4 hide_banner output.gif
    • the file would be huge

Mix video and audio

Extract part of the video

  • -ss -t
  • Start: where you want the video to start splitting. The format used is hours:minutes:seconds (00:00:00).
  • Duration: the total duration of the video you want to split. The format used is hours:minutes:seconds (00:00:00).

Contact multiple videos

  • ffmpeg -f concat -safe 0 -i mylist.txt -c copy output

Selecting your codecs for conversion

  • -c:a audio_codec
  • -c:v video_codec
  • -c:a copy, -c:v copy, -c:av:copy
    • use same audio, video or both codec

Reduce the size of the video

  • -s “size”: set video resolution size (Width x Height)
  • -b: set the bitrate
  • -r: sets the framerate
  • Use ffmpeg -i input.mp4 to get info about the video

We can use ffplay command to test the effect.

Crop a video
  • the format of crop: width:height:left:top.
  • -vf means video filter
Resize a video
  • -vf “scale=300:-1”
  • scale=width:height
  • -1 tells ffmpeg to automagically calculate
Rotate a video
  • -vf “rotate=90”
  • ffmpeg -i input.mp4 -vf "rotate=90" -c:a copy out.mp4

Extract images from video

  • -r fps: Set frame rate (default 25)
  • ffmpeg -i input.mp4 image%d.jpg: this will generate a lot of images

Convert images into a video

ffmpeg -f image2 -i image%d.jpg output.mp4

Add images to audio

Option Lists

  • -vn disables the video
  • -acodec copy allows to copy the audio stream without touching it
  • -an: disables audio
  • -s “size”: set video resolution size (Width x Height)

More Tips about ffmpeg

Online Tools

https://file-converter-online.com/ https://rmvb-to-mp4.file-converter-online.com/

Labels

adsense (5) Algorithm (69) Algorithm Series (35) Android (7) ANT (6) bat (8) Big Data (7) Blogger (14) Bugs (6) Cache (5) Chrome (19) Code Example (29) Code Quality (7) Coding Skills (5) Database (7) Debug (16) Design (5) Dev Tips (63) Eclipse (32) Git (5) Google (33) Guava (7) How to (9) Http Client (8) IDE (7) Interview (88) J2EE (13) J2SE (49) Java (186) JavaScript (27) JSON (7) Learning code (9) Lesson Learned (6) Linux (26) Lucene-Solr (112) Mac (10) Maven (8) Network (9) Nutch2 (18) Performance (9) PowerShell (11) Problem Solving (11) Programmer Skills (6) regex (5) Scala (6) Security (9) Soft Skills (38) Spring (22) System Design (11) Testing (7) Text Mining (14) Tips (17) Tools (24) Troubleshooting (29) UIMA (9) Web Development (19) Windows (21) xml (5)