[FFmpeg-devel] Controlling the Pixel Aspect Ratio (PAR)
Tony Strauss
tony
Mon Mar 14 18:39:36 CET 2011
I originally posted this to ffmpeg-user, but I'm now contemplating
writing a patch:
I need to break videos up into frames (.tga, TARGA format?frames).
These videos are uploaded by users and can come in a variety?of
formats. ?I can accomplish this with a command like:
ffmpeg -i movie.wmv -r 24 -f image2 images%05d.tga
I run into issues, however, when the pixel aspect ratio (PAR) of a
movie is not 1:1. ?For example, a movie with a resolution of
1440x1080, a PAR of 4:3, and thus an aspect resolution (DAR) of 16:9
results in incorrect .tga frames. ?The frames have resolution
1440x1080 and a PAR of 1:1. ?It's not clear whether ffmpeg's .tga
encoder understands pixel aspect resolution, but, in any case, I need
frames with a pixel aspect ratio of 1:1 for my purposes. As far as I
can tell, the only way to force ffmpeg to encode the frames with a PAR
of 1:1 is to specify the frame resolution.
For example:
============================================================
blackberry:~/bug tony$ ffprobe movie.wav
FFprobe version git-0f86fca, Copyright (c) 2007-2011 the FFmpeg developers
?built on Feb 21 2011 18:34:21 with gcc 4.2.1 (Apple Inc. build 5664)
?configuration: --enable-gpl --enable-nonfree --enable-pthreads
--enable-shared --disable-shared --disable-debug --disable-ffplay
--enable-avfilter --enable-avfilter --enable-postproc
--disable-indev=jack --enable-libx264 --enable-libfaac
--enable-libmp3lame --enable-libtheora --enable-libvorbis
--enable-libvpx --enable-libxvid --enable-libopencore-amrwb
--enable-version3 --enable-libopencore-amrnb --enable-librtmp
?libavutil ? ?50. 39. 0 / 50. 39. 0
?libavcodec ? 52.113. 1 / 52.113. 1
?libavformat ?52.102. 0 / 52.102. 0
?libavdevice ?52. ?2. 3 / 52. ?2. 3
?libavfilter ? 1. 76. 0 / ?1. 76. 0
?libswscale ? ?0. 12. 0 / ?0. 12. 0
?libpostproc ?51. ?2. 0 / 51. ?2. 0
[wmv3 @ 0x10181bc00] Extra data: 8 bits left, value: 0
Input #0, asf, from 'bug.wmv':
?Metadata:
? ?SfOriginalFPS ? : 299
? ?WMFSDKVersion ? : 11.0.5721.5265
? ?WMFSDKNeeded ? ?: 0.0.0.0000
? ?IsVBR ? ? ? ? ? : 0
?Duration: 00:00:09.68, start: 3.000000, bitrate: 7610 kb/s
? ?Stream #0.0(eng): Audio: wmav2, 48000 Hz, 2 channels, s16, 192 kb/s
? ?Stream #0.1(eng): Video: wmv3, yuv420p, 1440x1080, 8196 kb/s, PAR
4:3 DAR 16:9, 29.97 tbr, 1k tbn, 1k tbc
[wmv3 @ 0x10181bc00] Extra data: 8 bits left, value: 0
============================================================
I need the resulting frames to have a PAR of 1:1 and the same DAR of
16:9. ?I know that I can accomplish this by specifying a resolution to
ffmpeg on the command-line.
Down sampling the vertical resolution:
============================================================
blackberry:~/bug tony$ ffmpeg -i movie.wmv -s 1440x810 -r 24 -f image2
images%05d.tga
FFmpeg version git-41cdc1f, Copyright (c) 2000-2011 the FFmpeg developers
?built on Feb 18 2011 13:51:20 with gcc 4.2.1 (Apple Inc. build 5664)
?configuration: --enable-gpl --enable-nonfree --enable-pthreads
--enable-shared --disable-shared --disable-debug --disable-ffplay
--enable-avfilter --enable-avfilter --enable-postproc
--disable-indev=jack --enable-libx264 --enable-libfaac
--enable-libmp3lame --enable-libtheora --enable-libvorbis
--enable-libvpx --enable-libxvid --enable-libopencore-amrwb
--enable-version3 --enable-libopencore-amrnb --enable-librtmp
?libavutil ? ?50. 38. 0 / 50. 38. 0
?libavcodec ? 52.113. 1 / 52.113. 1
?libavformat ?52.100. 1 / 52.100. 1
?libavdevice ?52. ?2. 3 / 52. ?2. 3
?libavfilter ? 1. 76. 0 / ?1. 76. 0
?libswscale ? ?0. 12. 0 / ?0. 12. 0
?libpostproc ?51. ?2. 0 / 51. ?2. 0
[wmv3 @ 0x101824800] Extra data: 8 bits left, value: 0
Seems stream 1 codec frame rate differs from container frame rate:
1000.00 (1000/1) -> 29.97 (30000/1001)
Input #0, asf, from '../bug/bug.wmv':
?Metadata:
? ?SfOriginalFPS ? : 299
? ?WMFSDKVersion ? : 11.0.5721.5265
? ?WMFSDKNeeded ? ?: 0.0.0.0000
? ?IsVBR ? ? ? ? ? : 0
?Duration: 00:00:09.68, start: 3.000000, bitrate: 7610 kb/s
? ?Stream #0.0(eng): Audio: wmav2, 48000 Hz, 2 channels, s16, 192 kb/s
? ?Stream #0.1(eng): Video: wmv3, yuv420p, 1440x1080, 8196 kb/s, PAR
4:3 DAR 16:9, 29.97 tbr, 1k tbn, 1k tbc
[buffer @ 0x1013024e0] w:1440 h:1080 pixfmt:yuv420p
[scale @ 0x101301db0] w:1440 h:1080 fmt:yuv420p -> w:1440 h:810
fmt:bgr24 flags:0xa0000004
[wmv3 @ 0x101824800] Extra data: 8 bits left, value: 0
Output #0, image2, to 'images%05d.tga':
?Metadata:
? ?SfOriginalFPS ? : 299
? ?WMFSDKVersion ? : 11.0.5721.5265
? ?WMFSDKNeeded ? ?: 0.0.0.0000
? ?IsVBR ? ? ? ? ? : 0
? ?encoder ? ? ? ? : Lavf52.100.1
? ?Stream #0.0(eng): Video: targa, bgr24, 1440x810 [PAR 1:1 DAR 16:9],
q=2-31, 200 kb/s, 90k tbn, 24 tbc
Stream mapping:
?Stream #0.1 -> #0.0
Press [q] to stop encoding
frame= ?233 fps= 28 q=0.0 Lsize= ? ? ?-0kB time=9.71 bitrate=
-0.0kbits/s dup=0 drop=57
video:513478kB audio:0kB global headers:0kB muxing overhead -100.000004%
============================================================
Up sampling the horizontal resolution (to 1920x1080):
============================================================
blackberry:~/bug tony$ ffmpeg -i movie.wmv -s 1920x1080 -r 24 -f
image2 images%05d.tga
FFmpeg version git-41cdc1f, Copyright (c) 2000-2011 the FFmpeg developers
?built on Feb 18 2011 13:51:20 with gcc 4.2.1 (Apple Inc. build 5664)
?configuration: --enable-gpl --enable-nonfree --enable-pthreads
--enable-shared --disable-shared --disable-debug --disable-ffplay
--enable-avfilter --enable-avfilter --enable-postproc
--disable-indev=jack --enable-libx264 --enable-libfaac
--enable-libmp3lame --enable-libtheora --enable-libvorbis
--enable-libvpx --enable-libxvid --enable-libopencore-amrwb
--enable-version3 --enable-libopencore-amrnb --enable-librtmp
?libavutil ? ?50. 38. 0 / 50. 38. 0
?libavcodec ? 52.113. 1 / 52.113. 1
?libavformat ?52.100. 1 / 52.100. 1
?libavdevice ?52. ?2. 3 / 52. ?2. 3
?libavfilter ? 1. 76. 0 / ?1. 76. 0
?libswscale ? ?0. 12. 0 / ?0. 12. 0
?libpostproc ?51. ?2. 0 / 51. ?2. 0
[wmv3 @ 0x101824800] Extra data: 8 bits left, value: 0
Seems stream 1 codec frame rate differs from container frame rate:
1000.00 (1000/1) -> 29.97 (30000/1001)
Input #0, asf, from '../bug/bug.wmv':
?Metadata:
? ?SfOriginalFPS ? : 299
? ?WMFSDKVersion ? : 11.0.5721.5265
? ?WMFSDKNeeded ? ?: 0.0.0.0000
? ?IsVBR ? ? ? ? ? : 0
?Duration: 00:00:09.68, start: 3.000000, bitrate: 7610 kb/s
? ?Stream #0.0(eng): Audio: wmav2, 48000 Hz, 2 channels, s16, 192 kb/s
? ?Stream #0.1(eng): Video: wmv3, yuv420p, 1440x1080, 8196 kb/s, PAR
4:3 DAR 16:9, 29.97 tbr, 1k tbn, 1k tbc
[buffer @ 0x1013024e0] w:1440 h:1080 pixfmt:yuv420p
[scale @ 0x101301db0] w:1440 h:1080 fmt:yuv420p -> w:1920 h:1080
fmt:bgr24 flags:0xa0000004
[wmv3 @ 0x101824800] Extra data: 8 bits left, value: 0
Output #0, image2, to 'images%05d.tga':
?Metadata:
? ?SfOriginalFPS ? : 299
? ?WMFSDKVersion ? : 11.0.5721.5265
? ?WMFSDKNeeded ? ?: 0.0.0.0000
? ?IsVBR ? ? ? ? ? : 0
? ?encoder ? ? ? ? : Lavf52.100.1
? ?Stream #0.0(eng): Video: targa, bgr24, 1920x1080 [PAR 1:1 DAR
16:9], q=2-31, 200 kb/s, 90k tbn, 24 tbc
Stream mapping:
?Stream #0.1 -> #0.0
============================================================
While this works, it's a bit tricky to implement in the general case.
I need to force a PAR and a DAR on frames produced from a variety of
incoming video codecs and resolutions. ?There's going to have to be
some logic in my code that invokes ffmpeg that specifies a resolution
to ffmpeg to force the 1:1 PAR. Alternatively, what does everyone
think about my submitting a patch to ffmpeg containing an option to
force the PAR of the output frames?
This essentially would move the logic that I'm describing above into
ffmpeg, which would simplify my code that invokes ffmpeg. ?Does this
seem like a good idea?
Tony
More information about the ffmpeg-devel
mailing list