3

I have the following issue: I have a video file (h264) that plays with the correct aspect ratio in mplayer. However, if I load it into Intel's Computer Vision Annotation Tool, or if I re-encode the video using openCV, the aspect ratio is no longer correct.

"ffprobe -i" on the original file gives

1440x1080 [SAR 4:3 DAR 16:9]

whereas for the re-encoded file I get

1440x1080 [SAR 1:1 DAR 4:3]

I have other video files with

1920x1080 [SAR 1:1 DAR 16:9]

that do not cause this issue.

Do I just have to modify the SAR in the header or is the problem more complicated? I would like to preserve the codec if possible.

2 Answers 2

4

For a H264 stream, use the h264_metadata bitstream filter

ffmpeg -i in.mp4 -c copy -bsf:v "h264_metadata=sample_aspect_ratio=4/3" out.mp4
1
  • that did it, thanks !
    – wuppi
    Commented May 2, 2020 at 17:11
2

If you want to change the Sample Aspect Ratio (aka Pixel Aspect Ratio) without reencoding use mkvmerge or mp4box:

mkvmerge

mkvmerge -o "out.mp4" --aspect-ratio-factor 0:4/3 "in.mp4"

mp4box

mp4box -add in.mp4 -par 1=4:3 out.mp4

In ffmpeg you cannot combine a filter with -c copy ...

ffmpeg -i in.mp4 -vf setsar=sar=4/3 -map 0 -c copy out.mp4

because

Filtering and streamcopy cannot be used together.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.