Fixing pixel aspect ratio from NTSC footage

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
kereilly
Posts: 9
Joined: 2015-09-09T14:38:19-07:00
Authentication code: 1151

Fixing pixel aspect ratio from NTSC footage

Post by kereilly »

I am working with stills from mpeg NTSC footage that I extract with ffmpeg. the pixel resolution is 720x480 but they are rectangular pixels not square. This becomes an issue with some other programs i use, they want a square pixel aspect ratio. I know video players will compensate and playback this mpeg footage as 640x480 (in square pixels) while keeping its aspect ratio 4:3. However if i resize in imagemagick to 640x480 the picture gets squashed and my other program still complains of non-square pixels. Is their a function to resize rectangle pixels to square in imagemagick? no luck searching for this. Thanks for the help
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Fixing pixel aspect ratio from NTSC footage

Post by snibgo »

ffmpeg probably has an option to give square pixels or, more generally, to change the aspect ratios of pixels.
kereilly wrote:However if i resize in imagemagick to 640x480 the picture gets squashed and my other program still complains of non-square pixels.
This doesn't make sense to me. Perhaps your image file contains meta-data that describes pixel aspect ratios. It would be helpful if you posted the IM command you used, and the input and output images. And what version IM are you using, on what platform?
snibgo's IM pages: im.snibgo.com
PandoraBox
Posts: 23
Joined: 2011-04-10T14:08:11-07:00
Authentication code: 8675308

Re: Fixing pixel aspect ratio from NTSC footage

Post by PandoraBox »

Pixels you must mean pictures xD

From a 16:9 to a 4:3 you can either crop your image to get your 4:3 image value or calculate and center your image on a black square of a 4:3 ratio.

A quick search with google gives this topic.

viewtopic.php?t=23192
Best of luck.

PandoraBox
kereilly
Posts: 9
Joined: 2015-09-09T14:38:19-07:00
Authentication code: 1151

Re: Fixing pixel aspect ratio from NTSC footage

Post by kereilly »

PandoraBox wrote:Pixels you must mean pictures xD

A quick search with google gives this topic.

viewtopic.php?t=23192
Best of luck.

PandoraBox
No i mean Pixel aspect ratio not Display aspect ratio
https://en.wikipedia.org/wiki/Pixel_aspect_ratio

Everything i do will stay in 4:3 for the most part. However NTSC pixels for SD are not square they are rectangle and that is my problem.
snibgo wrote:ffmpeg probably has an option to give square pixels or, more generally, to change the aspect ratios of pixels.
I'm going to start to look into ffmpeg exporting stills with square aspect ratio. Probably the best way to go about doing it. But for now i'm running mac os 10.10.2
Version: ImageMagick 6.9.0-0 Q16 x86_64 2015-07-27 http://www.imagemagick.org
snibgo wrote:This doesn't make sense to me. Perhaps your image file contains meta-data that describes pixel aspect ratios. It would be helpful if you posted the IM command you used, and the input and output images. And what version IM are you using, on what platform?
The imagemagick input was simply "convert source1.png -resize 640x480 output1.png" However I was not right when i said this command squashes the image. The image already was squashed,due to the pixel aspect ratio being different i guess, and this command didn't correct it as expected. It still is distorted. However by doing "convert source1.png -resize 640x480! output1.png" I now get an image that does not have distortion. I needed the !. This image now looks good but it still has a non-square pixel aspect ratio.

Here is the problem i'm trying to solve, I"m doing a lot more processing on lots of images to isolate text. I feed the end result into an OCR program, gocr. That program spits out an error: "pngtopnm: warning - non-square pixels; to fix do a 'pamscale -yscale nan' " I've looked into this and it stems from, real obvious here, the pixels in the image file not being square. I can't just feed in an option for gocr "pamscale -yscale nan" because gocr is using some other program that spits this error out. I only get this from images that were ripped from DVD's. I'm thinking their is probably a way in imagemagick to specify square pixels. I'm guessing that it knows the pixel aspect ratio from the original image and its preserving that in the resized one.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Fixing pixel aspect ratio from NTSC footage

Post by fmw42 »

I do not think IM knows about pixel aspect ratio, except if that is some parameter in the header. However, as far as I know, IM has no automatic means to correct it. I think it is just being passed in the header. So your other program is still reading it. Have you tried using -strip to remove all the meta data in your command above. What format images are you using?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Fixing pixel aspect ratio from NTSC footage

Post by snibgo »

In "-resize 640x480!", the "!" makes the final size exactly 640x480. Without the "!", it will keep the original image aspect ratio (to the nearest pixel), so one of the dimensions won't be what you asked for.

IM operations generally work the same in the x- and y-directions, on the assumption that pixels are square. The "resolution" metadata might say the pixels aren't square, but IM mostly doesn't use that metadata. "identify" will show the resolution. If it is wrong, change it with "-density".
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Fixing pixel aspect ratio from NTSC footage

Post by fmw42 »

Seems to me that changing the density will not help viewing or displaying the image, only printing. Correct me if I am wrong.

Also if you have 4:3 aspect pixels and if the display is treating them as 1:1, then the equivalent 1:1 image should be achieved by a resize to more horizontal pixels (1:1 pixels) by -resize 133x100% (or 960x480), not fewer. Again, I am not an expert on non-square pixels from video.

Even if I have it backwards, then your original 720 pixels at 4:3 aspect should then become 720*3/4 = 540
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Fixing pixel aspect ratio from NTSC footage

Post by snibgo »

@kereilly: We are guessing. If you post at least example, we won't need to guess as much.
snibgo's IM pages: im.snibgo.com
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Fixing pixel aspect ratio from NTSC footage

Post by glennrp »

fmw42 wrote:I do not think IM knows about pixel aspect ratio, except if that is some parameter in the header.[...] What format images are you using?
A previous message in this thread said PNG. In PNG files, it's the "pHYs" chunk that provides the resolution or pixel aspect ratio. If a pHYs chunk is present in the input PNG, ImageMagick will read and preserve it.
Post Reply