FFmpeg

Jump to: navigation, search

Installation

sudo zypper install ffmpeg-4

Usage

Remix Video & Audio

If you have a video file without sound and an audio file, and you don't want to re-encode anything:

ffmpeg -i video.mp4 -i audio.mp3 -c copy output.mp4

If you want to re-encode the audio:

ffmpeg -i video.mp4 -i audio.mp3 -c:v copy -c:a aac output.mp4

If the video already has audio but you want to replace it:

ffmpeg -i video.mp4 -i audio.mp3 -c:v copy -c:a aac -map 0:v:0 -map 1:a:0 output.mp4
  • -c copy: copy both audio and video, without re-encoding
  • -c:v copy: copy video, without re-encoding
  • -c:a aac: re-encode audio in AAC codec
  • -map 0:v:0: use #0 (first) file's #0 (first) video track
  • -map 1:a:0: use #1 (second) file's #0 (first) audio track

Rotate Video

Some cameras, lacking G sensors, cannot automatically rotate captured video. To watch the video in correct direction, you can rotate it with ffmpeg.

The recommended way is to set rotation meta data. It is fast, taking less than a second on SSD.

ffmpeg -i input.mp4 -map_metadata 0 -metadata:s:v rotate="90" -codec copy output.mp4

However, a few video players don't support meta data rotation. In this case, you need to re-encode the video. It takes more time and may lose a little video quality, but it is more compatible and portable.

ffmpeg -i input.mp4 -map_metadata 0 -vf "transpose=1" output.mp4
  • -map_metadata 0: keep all original meta data, like date time, location and camera model
  • -metadata:s:v rotate="90": set rotate meta data, from 0 to 360
  • -vf "transpose=1": rotate and re-encode video
    • 0 - rotate by 90 degrees counter-clockwise and flip vertically
    • 1 - rotate by 90 degrees clockwise
    • 2 - rotate by 90 degrees counter-clockwise
    • 3 - rotate by 90 degrees clockwise and flip vertically
    • "transpose=1,transpose=1" - rotate by 180 degrees