Create PNG from video with ffmpeg and force_original_aspect_ratio – resulting PNG is squashed to sample_aspect_ratio (instead of display_aspect_ratio)

Solution for Create PNG from video with ffmpeg and force_original_aspect_ratio – resulting PNG is squashed to sample_aspect_ratio (instead of display_aspect_ratio)
is Given Below:

I have a generic process whose purpose is to take a video at any aspect ratio and generate a PNG from one of its frames. This frame should:

  • Be as large as possible, but no larger than 720×405 (16:9)
  • Maintain the aspect ratio of the video
  • Have no letterboxing
ffmpeg -y -nostats -ss 10 -i ./video.mp4 -max_muxing_queue_size 6400 -an -frames:v 1 -r 24/1 -vf "scale=w=720:h=405:force_original_aspect_ratio=decrease" -f image2 ./frame.png

When I give this command a video with a sample_aspect_ratio (SAR) of 4:3 and a display_aspect_ratio (DAR) of 16:9, I end up with a 540×405 (4:3) PNG where the image is horizontally compressed. Presumably force_original_aspect_ratio is looking at sample_aspect_ratio rather than display_aspect_ratio.

How do I ensure that the generated image maintains the same aspect ratio as the video (as displayed to the user)?

Insert a scale filter to convert frames to square pixels.

-vf "scale=iw*sar:ih,setsar=1,scale=w=720:h=405:force_original_aspect_ratio=decrease"