Skip to main content
Trim a video to a time range and simultaneously output multiple resolutions from the same input. One command instead of several — cheaper and faster because the input is decoded once.

Code

How the FFmpeg command works

  • -ss 00:00 -to 00:30 — trim the video to the first 30 seconds
  • split=2[vid1][vid2] — duplicate the video stream so each copy can be scaled independently
  • scale=...:320:...,pad=...:320:-1:-1[320p] — scale first copy to 320 px tall, letterbox to maintain aspect
  • scale=...:180:...,pad=...:180:-1:-1[180p] — scale second copy to 180 px tall
  • -map [320p] -map 0:a ... {{out_1}} — first output: 320p video + original audio
  • -map [180p] -map 0:a ... {{out_2}} — second output: 180p video + original audio
  • -c:a copy — pass audio through unchanged for both outputs
  • -c:v libx264 -preset medium — re-encode each video with H.264
For N resolutions, extend the split=N and add another scale...pad...[NNp] stage plus output mapping.

Response