Skip to content

Instantly share code, notes, and snippets.

@SherifFathey
Created July 11, 2025 07:24
Show Gist options
  • Select an option

  • Save SherifFathey/3b6c0000cc3128d4c9199d5b04389d64 to your computer and use it in GitHub Desktop.

Select an option

Save SherifFathey/3b6c0000cc3128d4c9199d5b04389d64 to your computer and use it in GitHub Desktop.
Useful FFmpeg command examples for everyday media tasks like converting, compressing, and creating GIFs

🎬 FFmpeg Command Guide β€” Practical Workflow

πŸ“₯ 0. Install FFmpeg

On Ubuntu :

sudo apt update
sudo apt install ffmpeg

For Check:

ffmpeg -version

▢️ 1. Play or Preview Media (using ffplay)

  • Play a video:

    ffplay input.mp4
  • Play an audio file:

    ffplay input.mp3
  • Play without sound:

    ffplay -an input.mp4
  • Play specific section:

    ffplay -ss 00:00:10 -t 00:00:05 input.mp4

πŸ”„ 2. Convert Media

  • Convert video format (e.g., .mp4 β†’ .webm):

    ffmpeg -i input.mp4 output.webm
  • Extract audio from video:

    ffmpeg -i input.mp4 output.mp3
  • Convert GIF β†’ video:

    ffmpeg -i input.gif -movflags faststart -pix_fmt yuv420p output.mp4

βœ‚οΈ 3. Cut / Trim Videos

  • Cut from specific time:

    ffmpeg -ss 00:00:05 -i input.mp4 -t 00:00:10 -c copy output.mp4

πŸ“‰ 4. Compress Videos

  • Basic compression:

    ffmpeg -i input.mp4 -vcodec libx264 -crf 23 output.mp4
  • Resize & compress:

    ffmpeg -i input.mp4 -vf "scale=640:-1" -vcodec libx264 -crf 23 output.mp4

πŸ–ΌοΈ 5. Create Optimized GIFs

βœ… Best Method (2-step palette process):

  • Step 1 – Generate palette:

    ffmpeg -i input.mp4 -vf "fps=10,scale=480:-1:flags=lanczos,palettegen" palette.png
  • Step 2 – Create optimized GIF:

    ffmpeg -i input.mp4 -i palette.png -filter_complex \
    "fps=10,scale=480:-1:flags=lanczos[x];[x][1:v]paletteuse" output.gif
  • πŸ’‘ Tips:

    • Lower fps and scale for smaller size
    • Example: fps=7, scale=360:-1

🚫 Simple Method (not recommended):

ffmpeg -i input.mp4 output.gif

⚠️ Generates large files with poor performance.


🧼 6. Audio Editing

  • Remove audio:

    ffmpeg -i input.mp4 -an output.mp4
  • Increase volume:

    ffmpeg -i input.mp4 -filter:a "volume=2.0" output.mp4

⏩ 7. Control Video Speed

  • Speed up (2Γ— faster):

    ffmpeg -i input.mp4 -vf "setpts=0.5*PTS" -an fast.mp4
  • Slow down (0.5Γ— speed):

    ffmpeg -i input.mp4 -vf "setpts=2.0*PTS" -an slow.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment