I am trying to convert some old movie files to images (and later to reencode as h.264). The problem is that the resulting images are stretched vertically.
Here is the ffmpeg command:
ffmpeg -i preview.mpg -filter_complex "[0:v]fps=fps=1[onepersec]; [onepersec]scale=min(200\, iw):-2[rescaled]" -map "[rescaled]" -f image2 image%4d.jpg
I have a guess: the scale
filter as I use it ignores the display aspect ratio DAR
and simply scales the pixel values. I want the width of the images to be at most 200 pixels and the height can be whatever it needs to be as long as it looks right, i.e., not stretched.
How should I convert the movie file to get images (and re-encoded video) that do not look stretched?
Additional info about the video file:
In VLC it plays back looking ok. It looks like a normal 4:3 aspect ratio.
VLC displays the following in Current media information
> Codec
:
Stream 0
Type: Video
Codec: MPEG-1/2 Video (mpgv)
Resolution: 352x576
Frame rate: 25
Decoded format: Planar 4:2:0 YUV
Here is the output from running the above ffmpeg
command:
ffmpeg version git-2014-07-24-f753956 Copyright (c) 2000-2014 the FFmpeg developers
built on Jul 24 2014 13:39:56 with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-4)
configuration: --prefix=/home/somename/ffmpeg_build --extra-cflags=-I/home/somename/ffmpeg_build/include --extra-ldflags=-L/home/somename/ffmpeg_build/lib --bindir=/home/somename/bin --extra-libs=-ldl --enable-gpl --enable-nonfree --enable-libfdk_aac --enable-libmp3la
me --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libfreetype --enable-libspeex --enable-libtheora
libavutil 52. 92.101 / 52. 92.101
libavcodec 55. 69.100 / 55. 69.100
libavformat 55. 49.100 / 55. 49.100
libavdevice 55. 13.102 / 55. 13.102
libavfilter 4. 11.102 / 4. 11.102
libswscale 2. 6.100 / 2. 6.100
libswresample 0. 19.100 / 0. 19.100
libpostproc 52. 3.100 / 52. 3.100
Input #0, mpeg, from 'preview.mpg':
Duration: 00:14:23.59, start: 1.646067, bitrate: 2244 kb/s
Stream #0:0[0x1bf]: Data: dvd_nav_packet
Stream #0:1[0x1e0]: Video: mpeg2video (Main), yuv420p(tv), 352x576 [SAR 24:11 DAR 4:3], max. 2500 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc
Stream #0:2[0x80]: Audio: ac3, 48000 Hz, stereo, fltp, 256 kb/s
[swscaler @ 0x3f6fae0] deprecated pixel format used, make sure you did set range correctly
Output #0, image2, to 'image%4d.jpg':
Metadata:
encoder : Lavf55.49.100
Stream #0:0: Video: mjpeg, yuvj420p, 200x328 [SAR 164:75 DAR 4:3], q=2-31, 200 kb/s, 1 fps, 1 tbn, 1 tbc
Metadata:
encoder : Lavc55.69.100 mjpeg
Stream mapping:
Stream #0:1 (mpeg2video) -> fps
scale -> Stream #0:0 (mjpeg)
Press [q] to stop, [?] for help
frame= 41 fps=0.0 q=1.6 size=N/A time=00:00:41.00 bitrate=N/A ^Mframe= 80 fps= 79 q=1.6 size=N/A time=00:01:20.00 bitrate=N/A ^Mframe= 125 fps= 71 q=1.6 size=N/A time=00:02:05.00 bitrate=N/A ^Mframe= 156 fps= 69 q=1.6 size=N/A time=00:02:36.00 bitrate=N/A ^Mframe= 203 fps= 74 q=1.6 size=N/A time=00:03:23.00 bitrate=N/A ^Mframe= 248 fps= 76 q=1.6 size=N/A time=00:04:08.00 bitrate=N/A ^Mframe= 295 fps= 79 q=1.6 size=N/A time=00:04:55.00 bitrate=N/A ^Mframe= 336 fps= 79 q=1.6 size=N/A time=00:05:36.00 bitrate=N/A ^Mframe= 377 fps= 79 q=1.6 size=N/A time=00:06:17.00 bitrate=N/A ^Mframe= 424 fps= 81 q=1.6 size=N/A time=00:07:04.00 bitrate=N/A ^Mframe= 465 fps= 81 q=1.6 size=N/A time=00:07:45.00 bitrate=N/A ^Mframe= 508 fps= 81 q=1.6 size=N/A time=00:08:28.00 bitrate=N/A ^Mframe= 547 fps= 79 q=1.6 size=N/A time=00:09:07.00 bitrate=N/A ^Mframe= 580 fps= 78 q=1.6 size=N/A time=00:09:40.00 bitrate=N/A ^Mframe= 621 fps= 79 q=1.6 size=N/A time=00:10:21.00 bitrate=N/A ^Mframe= 665 fps= 79 q=1.6 size=N/A time=00:11:05.00 bitrate=N/A ^Mframe= 709 fps= 80 q=1.6 size=N/A time=00:11:49.00 bitrate=N/A ^Mframe= 746 fps= 79 q=1.6 size=N/A time=00:12:26.00 bitrate=N/A ^Mframe= 794 fps= 80 q=1.6 size=N/A time=00:13:14.00 bitrate=N/A
^Mframe= 833 fps= 80 q=1.6 size=N/A time=00:13:53.00 bitrate=N/A ^Mframe= 865 fps= 81 q=1.6 Lsize=N/A time=00:14:25.00 bitrate=N/A
video:11118kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Maybe I need to do something about [swscaler @ 0x3f6fae0] deprecated pixel format used, make sure you did set range correctly?
Here is output from mediainfo
:
$ mediainfo preview.mpg
General
Complete name : /[...]/preview.mpg
Format : MPEG-PS
File size : 231 MiB
Duration : 14mn 23s
Overall bit rate mode : Variable
Overall bit rate : 2 244 Kbps
Video
ID : 224 (0xE0)
Format : MPEG Video
Format version : Version 2
Format profile : Main@Main
Format settings, BVOP : Yes
Format settings, Matrix : Custom
Format settings, GOP : M=2, N=12
Duration : 14mn 23s
Bit rate mode : Variable
Bit rate : 1 943 Kbps
Maximum bit rate : 2 500 Kbps
Width : 352 pixels
Height : 576 pixels
Display aspect ratio : 4:3
Frame rate : 25.000 fps
Standard : PAL
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Interlaced
Scan order : Top Field First
Compression mode : Lossy
Bits/(Pixel*Frame) : 0.383
Time code of first frame : 00:00:00:12
Time code source : Group of pictures header
Stream size : 200 MiB (87%)
Audio
ID : 189 (0xBD)-128 (0x80)
Format : AC-3
Format/Info : Audio Coding 3
Mode extension : CM (complete main)
Format settings, Endianness : Big
Muxing mode : DVD-Video
Duration : 14mn 23s
Bit rate mode : Constant
Bit rate : 256 Kbps
Channel(s) : 2 channels
Channel positions : Front: L R
Sampling rate : 48.0 KHz
Bit depth : 16 bits
Compression mode : Lossy
Delay relative to video : -31ms
Stream size : 26.3 MiB (11%)
Menu
Here is output from ffprobe
:
$ ffprobe preview.mpg
ffprobe version git-2014-07-24-f753956 Copyright (c) 2007-2014 the FFmpeg developers
built on Jul 24 2014 13:39:56 with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-4)
configuration: --prefix=/home/sadmin/ffmpeg_build --extra-cflags=-I/home/somename/ffmpeg_build/include --extra-ldflags=-L/home/somename/ffmpeg_build/lib --bindir=/home/somename/bin --extra-libs=-ldl --enable-gpl --enable-nonfree --enable-libfdk_aac --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libfreetype --enable-libspeex --enable-libtheora
libavutil 52. 92.101 / 52. 92.101
libavcodec 55. 69.100 / 55. 69.100
libavformat 55. 49.100 / 55. 49.100
libavdevice 55. 13.102 / 55. 13.102
libavfilter 4. 11.102 / 4. 11.102
libswscale 2. 6.100 / 2. 6.100
libswresample 0. 19.100 / 0. 19.100
libpostproc 52. 3.100 / 52. 3.100
Input #0, mpeg, from 'preview.mpg':
Duration: 00:14:23.59, start: 1.646067, bitrate: 2244 kb/s
Stream #0:0[0x1bf]: Data: dvd_nav_packet
Stream #0:1[0x1e0]: Video: mpeg2video (Main), yuv420p(tv), 352x576 [SAR 24:11 DAR 4:3], max. 2500 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc
Stream #0:2[0x80]: Audio: ac3, 48000 Hz, stereo, fltp, 256 kb/s
Unsupported codec with id 1145979222 for input stream 0
$
Here the text Unsupported codec with id 1145979222 for input stream 0 is highlighted. I guess it is about Stream #0.0
(?) which I do not need.
Here is what I get for one of the images:
$ ffprobe image0001.jpg
ffprobe version git-2014-07-24-f753956 Copyright (c) 2007-2014 the FFmpeg developers
built on Jul 24 2014 13:39:56 with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-4)
configuration: --prefix=/home/somename/ffmpeg_build --extra-cflags=-I/home/somename/ffmpeg_build/include --extra-ldflags=-L/home/somename/ffmpeg_build/lib --bindir=/home/somename/bin --extra-libs=-ldl --enable-gpl --enable-nonfree --enable-libfdk_aac --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libfreetype --enable-libspeex --enable-libtheora
libavutil 52. 92.101 / 52. 92.101
libavcodec 55. 69.100 / 55. 69.100
libavformat 55. 49.100 / 55. 49.100
libavdevice 55. 13.102 / 55. 13.102
libavfilter 4. 11.102 / 4. 11.102
libswscale 2. 6.100 / 2. 6.100
libswresample 0. 19.100 / 0. 19.100
libpostproc 52. 3.100 / 52. 3.100
[mjpeg @ 0x24c7e40] ignoring invalid SAR: 164/75
Input #0, image2, from 'mov0001.jpg':
Duration: 00:00:00.04, start: 0.000000, bitrate: N/A
Stream #0:0: Video: mjpeg, yuvj420p(pc, bt470bg), 200x328, 25 tbr, 25 tbn, 25 tbc
Interesting here could be [mjpeg @ 0x24c7e40] ignoring invalid SAR: 164/75 but what does that mean?