ffmpeg: overlay video on top of a cropped video, map the overlay audio, cut the base video to the overlays length

I’m trying to overlay a video on top of a base video which is cropped to a shorts video format (standing phone). The overlayed video should be centered on top of the base layer. The base video’s length should be reduced to the overlay’s length. And I want to save only the overlay’s audio.

I’ve tried a bunch of stuff without much success. The current state of my ffmpeg command is this:

ffmpeg -i overlay.mp4 -ss 00:00:00 -to <insert base length?> -i base.mp4 -map 1:v:0 -map 1:a -vf "crop=ih*(9/16):ih" -crf 21 output.mp4

But this only gives me the cropped version of the base video. So my questions are:

  1. How can I figure out the base video’s length?
  2. How can I actually overlay (not map) other video on top of the base video?
  3. How can I map the overlay’s audio? Since -map 1:a the base’s audio and -map 0:a says: “Stream map ‘0:a’ matches no streams. To ignore this, add a trailing ‘?’ to the map.”

Any help is appreciated.

Read more here: Source link