<p>You can use a combo of the scale and setsar filters.</p>

<pre><code>ffmpeg -i hdv-input.m2t -vf "scale=iw*sar:ih,setsar=1" -crf 28 -c:a aac -b:a 80k -ac 1 -movflags +faststart h-264-out.mp4
</code></pre>

<p>The scaler width to set to <code>current width x sample/pixel aspect</code>. If it's already 1, it amounts to <code>new width = old width</code>. I've added a setsar afterwards to ensure the output SAR is <code>1</code>.</p>

<p>For MP4 format, default video codec is H.264. If that's what you want, no need to explicitly set <code>c:v</code>.</p>

<p>(For bitrates &lt; 128k, <code>libfdk_aac</code> is better than the native AAC encoder.)</p>

<p><code>-strict -2</code> is not needed for using native AAC encoder if your ffmpeg is from after Dec 2015.</p>

CC BY-SA 3.0
2017-03-09T20:33:00.520Z
So this command will output square pixels, but at the same resolution size as the input?
user3643
CC BY-SA 3.0
2017-03-10T04:58:12.077Z
At the same display resolution as the input.
Gyan
CC BY-SA 3.0
2017-03-10T17:15:20.153Z
I think you need "... setsar=1:1,setdar=16:9 ..." - See: http://video.stackexchange.com/questions/9947/how-do-i-change-frame-size-preserving-width-using-ffmpeg .
Rob
CC BY-SA 3.0
2017-03-10T17:36:18.773Z
All setdar does is alter the SAR so that the resultant video when displayed has `width = DAR x height`. For the OP's use case, setdar would be redundant. For other videos, it would force display to be 16:9,
Gyan
CC BY-SA 3.0
2017-03-20T15:01:58.657Z
Do I need to do something (download, etc) to use `libfdk_aac`? I changed `-c:a aac` to `-c:a libfdk_aac` and I get the error "unknown encoder 'libfdk_aac'".
user3643
CC BY-SA 3.0
2017-03-20T15:22:45.743Z
Due to license incompatibility, binaries cannot be distributed with that library included. You'll have to compile ffmpeg yourself with that library. I use this [script](https://github.com/jb-alvarado/media-autobuild_suite) to autocompile ffmpeg. First run will take 4-5 hours on an i7. Further runs, 2 hours or so.
Gyan
CC BY-SA 4.0
2020-08-17T16:57:10.370Z
@Gyan what if when you run this command, you get the "width not divisible by 2" error?
CRAIG
CC BY-SA 3.0
2017-03-09T20:29:00.150Z
2017-03-09T20:29:00.150Z
Gyan
<p>I have the following code to convert HDV video to a web ready mp4:</p>

<pre><code>ffmpeg -i hdv-input.m2t -crf 28 -c:a aac -b:a 80k -ac 1 -strict -2 -movflags +faststart h-264-out.mp4
</code></pre>

<p>The problem is that there is nowhere in this command to specify pixel aspect ratio. If you are not aware, HDV video files are 1440x1080, but the pixels are not square. When decoded for display, the pixels are stretched to make a full 1920x1080. This is called anamorphic video, and it is something that should definitely be avoided if producing for end users.</p>

<p>I honestly don't know if the mp4's I'm making with the above command are being produced with square pixels, but I want to make sure they are. What are the correct parameters I need to add to this command to ensure square pixels in my output mp4? Do I also have to set resolution, and how do I do that? It seems like there should be a <code>-c:v</code> command as well, but I don't really know.</p>

<ffmpeg><conversion><aspect><non-square-pixels>
How do I convert anamorphic hdv video to normal h.264 video with ffmpeg? How to ensure square pixels in output?
user3643
# How do I convert anamorphic hdv video to normal h.264 video with ffmpeg? How to ensure square pixels in output?

(Asked by: username_0 on 2017-03-09)

I have the following code to convert HDV video to a web ready mp4:
ffmpeg -i hdv-input.m2t -crf 28 -c:a aac -b:a 80k -ac 1 -strict -2 -movflags +faststart h-264-out.mp4

The problem is that there is nowhere in this command to specify pixel aspect ratio. If you are not aware, HDV video files are 1440x1080, but the pixels are not square. When decoded for display, the pixels are stretched to make a full 1920x1080. This is called anamorphic video, and it is something that should definitely be avoided if producing for end users.
I honestly don't know if the mp4's I'm making with the above command are being produced with square pixels, but I want to make sure they are. What are the correct parameters I need to add to this command to ensure square pixels in my output mp4? Do I also have to set resolution, and how do I do that? It seems like there should be a -c:v command as well, but I don't really know.

**Tags:** ffmpeg, conversion, aspect, non-square-pixels


---

## 1 answers

### Answer by username_1 on 2017-03-09. Score: 1 | Accepted answer

You can use a combo of the scale and setsar filters.
ffmpeg -i hdv-input.m2t -vf "scale=iw*sar:ih,setsar=1" -crf 28 -c:a aac -b:a 80k -ac 1 -movflags +faststart h-264-out.mp4

The scaler width to set to current width x sample/pixel aspect. If it's already 1, it amounts to new width = old width. I've added a setsar afterwards to ensure the output SAR is 1.
For MP4 format, default video codec is H.264. If that's what you want, no need to explicitly set c:v.
(For bitrates < 128k, libfdk_aac is better than the native AAC encoder.)
-strict -2 is not needed for using native AAC encoder if your ffmpeg is from after Dec 2015.

> **Comments:**
> **username_0**: So this command will output square pixels, but at the same resolution size as the input?  
> **username_1**: At the same display resolution as the input.  
> **username_2**: I think you need "... setsar=1:1,setdar=16:9 ..." - See: http://video.stackexchange.com/questions/9947/how-do-i-change-frame-size-preserving-width-using-ffmpeg .  
> **username_1**: All setdar does is alter the SAR so that the resultant video when displayed has `width = DAR x height`. For the OP's use case, setdar would be redundant. For other videos, it would force display to be 16:9,  
> **username_0**: Do I need to do something (download, etc) to use `libfdk_aac`? I changed `-c:a aac` to `-c:a libfdk_aac` and I get the error "unknown encoder 'libfdk_aac'".  
> **username_1**: Due to license incompatibility, binaries cannot be distributed with that library included. You'll have to compile ffmpeg yourself with that library. I use this [script](https://github.com/jb-alvarado/media-autobuild_suite) to autocompile ffmpeg. First run will take 4-5 hours on an i7. Further runs, 2 hours or so.  
> **username_3**: @username_1 what if when you run this command, you get the "width not divisible by 2" error?  

---

