I'm using FFmpeg to generate previews for the videos added to my website. The site script's (KVS) built-in tools help to some extent by automatically creating previews with the following properties:

  • Max. duration: 15s
  • Offset from beginning: 10%
  • Offset from end: 10%
  • Fragments: 5 (each lasting about 3s)
  • Crossfade between fragments: 1s

However, I don't know how to recreate those through the FFmpeg command line, in addition to adding an if/else part that will check if the video is landscape or portrait.

If the video is landscape, the previous properties should execute and generate the preview.

If the video is portrait, I'd like to execute the previously-listed properties as well as additional ones to insert a blurred video in the background.

I'm using the following command line for that, and it generates exactly what I had in mind.

ffmpeg -i source-video.mp4 -vf split[original][copy];[copy]scale=ih*16/9:-1,crop=h=iw*9/16,gblur=sigma=20[blurred];[blurred][original]overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2 new-video.mp4

I'm also using the following flags, which I'd like to apply to the preview video regardless of orientation.

-c:v libx264 -c:a copy -movflags +faststart -preset veryfast -strict 0 -f mp4

I found several unrelated solutions on if/else but none of them really match what I'm trying to achieve and only add to the confusion.

Note: I am not using PHP, Python, or otherwise, and would like to know whether it's achievable only through the FFmpeg command line itself.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.