-1

For example,

  • there is a jpeg with dimensions 1900x1000 and it has a frame (a rectangle) with pixel coordinates 490x100 and 1400x500
  • a video with resolution 720p needs to be placed within this rectangle

Could you pls share the ffmpeg command to concatenate the jpeg and video? I tried -hstack and -xstack filters. But, couldn't get the video inside the rectangle.

TIA

Krishna Chebrolu
  • 145
  • 2
  • 13

1 Answers1

0

Your rectangle has a size of 910x400, so you have to downscale the 1280x720 video to fit. But the aspect ratios do not match. So you need to also pad or crop the 1280x720 video to properly fit inside 910x400 if you want to preserve the aspect ratio.

Combine these answers:

Crop to fit

ffmpeg -i image.jpg -i video.mp4 -filter_complex "[1]scale=910:400:force_original_aspect_ratio=increase,crop=910:400[fg];[0][fg]overlay=x=490:y=100,format=yuv420p" -c:a copy -movflags +faststart output.mp4

Pad to fit

ffmpeg -i image.jpg -i video.mp4 -filter_complex "[1]scale=910:400:force_original_aspect_ratio=decrease,pad=910:400:-1:-1[fg];[0][fg]overlay=x=490:y=100,format=yuv420p" -c:a copy -movflags +faststart output.mp4

Squish/stretch to fit

This will ignore the aspect ratio and will result in a distorted image.

ffmpeg -i image.jpg -i video.mp4 -filter_complex "[1]scale=910:400,setsar=1[fg];[0][fg]overlay=x=490:y=100,format=yuv420p" -c:a copy -movflags +faststart output.mp4
llogan
  • 121,796
  • 28
  • 232
  • 243
  • Thanks @llogan. I didn't want to crop the video and needed to scale the video only to match the dimensions of the rectangle. Your response to [Resizing videos with ffmpeg to fit into static size](https://superuser.com/questions/547296/resizing-videos-with-ffmpeg-avconv-to-fit-into-static-sized-player) helped addressing these.. – Krishna Chebrolu Jun 18 '21 at 05:53
  • @KrishnaChebrolu I added more examples – llogan Jun 18 '21 at 06:21