Skip to content

Instantly share code, notes, and snippets.

@NazemMahmud
Last active March 30, 2026 03:43
Show Gist options
  • Select an option

  • Save NazemMahmud/d868aa6e20e04b8b323d528d87ddcf52 to your computer and use it in GitHub Desktop.

Select an option

Save NazemMahmud/d868aa6e20e04b8b323d528d87ddcf52 to your computer and use it in GitHub Desktop.
ffmpeg CLI commands

1. save last frame of the video

ffmpeg -sseof -3 -i input.mp4 -update 1 -q:v 1 last.jpg

If you want PNG:

ffmpeg -sseof -3 -i input.mp4 -update 1 last.png

Notes:

  • -sseof -3 starts reading from 3 seconds before the end.
  • -update 1 keeps writing to the same output file.
  • The final saved file becomes the last processed frame.

If your video has a longer trailing audio section or odd timing, increase the seek window a bit:

ffmpeg -sseof -5 -i input.mp4 -update 1 -q:v 1 last.jpg

2. Reverse video

ffmpeg -i input.mp4 -vf reverse reversed.mp4

3. Remove metadata

# To only keep video and audio and remove everything else, like, subtitle, other extra streams
ffmpeg -i input.mp4 -map_metadata -1 -map_chapters -1 -map 0:v -map 0:a? -c copy output.mp4

# To only strip metdata
ffmpeg -i input.mp4 -map 0 -c copy -map_metadata -1 -map_chapters -1 output.mp4


# To inspect before and after:
ffprobe -hide_banner input.mp4
# more details
ffprobe -hide_banner -show_format -show_streams input.mp4
ffprobe -hide_banner -show_format -show_streams output.mp4

Part by part

  • -i input.mp4: Uses input.mp4 as the source file.

  • -map_metadata -1: Removes global/container metadata.
    Examples: title, comment, encoder tag, creation_time, some app/platform-added tags.

  • -map_chapters -1: Removes chapter data.

  • -c copy: Copies streams as-is, without re-encoding. So quality stays the same and processing is fast.

  • output.mp4: Writes the result to a new file.

  • -map 0:v: Takes all video streams from input 0.

  • -map 0:a?: Takes all audio streams from input 0 if exists.

So together:

  • keep video and audio
  • do not keep subtitles, attachments, data streams, or other extra streams

In simple words: “Make a new MP4 from this file, keep only video and audio, remove metadata and chapters, and do not re-encode anything.”

What it removes:

  • container metadata
  • chapters
  • subtitles, if present
  • other non-audio/non-video streams What it keeps
  • original video bitstream
  • original audio bitstream

4. Flip video

Use horizontal flip:

ffmpeg -i input.mp4 -vf hflip -c:a copy output.mp4
  • -vf hflip = horizontal flip (left ↔ right)
  • -c:a copy = keep audio unchanged

note: this re-encodes video (unavoidable for flipping). It means, filters like hflip modify pixels, so ffmpeg must decode and re-encode the video. You can't use -c:v copy here — it only works when the video stream passes through untouched. Re-encoding takes longer and may slightly change quality unless you specify a high bitrate or CRF value.

If you also want good MP4 output settings

ffmpeg -i input.mp4 -vf hflip -c:v libx264 -crf 18 -preset medium -c:a aac -b:a 192k output.mp4

If input has no audio

ffmpeg -i input.mp4 -vf hflip -an output.mp4

For up ↕ down flip instead:

ffmpeg -i input.mp4 -vf vflip -c:a copy output.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment