user27446: 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.

user24237: 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.


user1871: 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


27446: <p>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. </p>

<p>"ffprobe -i" on the original file gives</p>

<blockquote>
  <p>1440x1080 [SAR 4:3 DAR 16:9]</p>
</blockquote>

<p>whereas for the re-encoded file I get</p>

<blockquote>
  <p>1440x1080 [SAR 1:1 DAR 4:3]</p>
</blockquote>

<p>I have other video files with</p>

<blockquote>
  <p>1920x1080 [SAR 1:1 DAR 16:9]</p>
</blockquote>

<p>that do not cause this issue.</p>

<p>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.</p>
 24237: <p>If you want to change the Sample Aspect Ratio (aka Pixel Aspect Ratio) without reencoding use <strong>mkvmerge</strong> or <strong>mp4box</strong>:</p>

<p>mkvmerge</p>

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

<p>mp4box</p>

<pre><code>mp4box -add in.mp4 -par 1=4:3 out.mp4
</code></pre>

<p>In <code>ffmpeg</code> you <strong>cannot</strong> combine a filter with <code>-c copy</code> ...</p>

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

<p>because</p>

<pre><code>Filtering and streamcopy cannot be used together.
</code></pre>
 1871: <p>For a H264 stream, use the h264_metadata bitstream filter</p>

<pre><code>ffmpeg -i in.mp4 -c copy -bsf:v "h264_metadata=sample_aspect_ratio=4/3" out.mp4
</code></pre>
