Opened 4 years ago

Last modified 4 years ago

#6358 open enhancement

ffmpeg requires constant output dimensions

Reported by: 01sas Owned by:
Priority: wish Component: ffmpeg
Version: git-master Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: yes
Analyzed by developer: no


Summary of the bug:
I have a video recorded from TV (DVB) and this video has a different SAR other the time. Like when advertisement or some modern TV show is shown then SAR is 64:45 which gives image with 16:9 aspect ratio but when some old TV show is shown then SAR is 16:15 which gives image with 4:3 aspect ratio. I want to convert this video to a sequence of images one per second and I want image to have a valid resolution according to SAR with correct aspect ratio.

The first problem which I face is that ffmpeg does not take SAR into account when generate images. I solve this problem using video filter, like this: -vf "scale=iw:ih/sar:eval=frame".

But after that I face a problem which I don't know how to solve: ffmpeg generate images with always the same resolution and does not change it in respect to changed scale. In my case it simply crop image when aspect ratio is 4:3. In logs it is visible that scaler calculate resolution correctly but output images always has the same resolution as for first image which is a problem.

How to reproduce:

% ffmpeg -i test.ts -vf "scale=iw:ih/sar:eval=frame,fps=1" -qscale:v 6 "frames/out%03d.jpg"
ffmpeg version 3.2.4-1~16.04.york1 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 5.4.1 (Ubuntu 5.4.1-5ubuntu2~16.04.york1) 20170210
  configuration: --prefix=/usr --extra-version='1~16.04.york1' --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libebur128 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
  libavutil      55. 34.101 / 55. 34.101
  libavcodec     57. 64.101 / 57. 64.101
  libavformat    57. 56.101 / 57. 56.101
  libavdevice    57.  1.100 / 57.  1.100
  libavfilter     6. 65.100 /  6. 65.100
  libavresample   3.  1.  0 /  3.  1.  0
  libswscale      4.  2.100 /  4.  2.100
  libswresample   2.  3.100 /  2.  3.100
  libpostproc    54.  1.100 / 54.  1.100
Input #0, mpegts, from 'test.ts':
  Duration: 00:01:00.14, start: 1.400000, bitrate: 8223 kb/s
  Program 1 
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: mpeg2video (Main), 1 reference frame ([2][0][0][0] / 0x0002), yuv420p(tv, top first, left), 720x576 [SAR 64:45 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
    Stream #0:1[0x101](deu): Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, 5.1(side), fltp, 448 kb/s
[Parsed_scale_0 @ 0x55a718d39480] w:iw h:ih/sar flags:'bicubic' interl:0
[Parsed_fps_1 @ 0x55a718d39f20] fps=1/1
[graph 0 input from stream 0:0 @ 0x55a718d39da0] w:720 h:576 pixfmt:yuv420p tb:1/90000 fr:25/1 sar:64/45 sws_param:flags=2
[swscaler @ 0x55a718d3af40] deprecated pixel format used, make sure you did set range correctly
[Parsed_scale_0 @ 0x55a718d39480] w:720 h:576 fmt:yuv420p sar:64/45 -> w:720 h:405 fmt:yuvj420p sar:1/1 flags:0x4
Output #0, image2, to 'out%03d.jpg':
    encoder         : Lavf57.56.101
    Stream #0:0: Video: mjpeg, 1 reference frame, yuvj420p(pc, left), 720x405 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 1 fps, 1 tbn, 1 tbc
      encoder         : Lavc57.64.101 mjpeg
    Side data:
      cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
Stream mapping:
  Stream #0:0 -> #0:0 (mpeg2video (native) -> mjpeg (native))
Press [q] to stop, [?] for help
[mpegts @ 0x55a718cf04a0] Correcting start time by 178733
[swscaler @ 0x55a718ee4560] deprecated pixel format used, make sure you did set range correctly
[Parsed_scale_0 @ 0x55a718d39480] w:720 h:576 fmt:yuv420p sar:16/15 -> w:720 h:540 fmt:yuvj420p sar:1/1 flags:0x4
No more output streams to write to, finishing.56.00 bitrate=N/A speed= 9.3x    
frame=   61 fps=9.7 q=6.0 Lsize=N/A time=00:01:01.00 bitrate=N/A speed= 9.7x    
video:1537kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Input file #0 (test.ts):
  Input stream #0:0 (video): 1497 packets read (53746648 bytes); 1494 frames decoded; 
  Input stream #0:1 (audio): 0 packets read (0 bytes); 
  Total: 1497 packets (53746648 bytes) demuxed
Output file #0 (out%03d.jpg):
  Output stream #0:0 (video): 61 frames encoded; 61 packets muxed (1573461 bytes); 
  Total: 61 packets (1573461 bytes) muxed
[Parsed_fps_1 @ 0x55a718d39f20] 1494 frames in, 61 frames out; 1433 frames dropped, 0 frames duplicated.

Attachments (2)

ffmpeg-20170428-184536.log (93.8 KB ) - added by 01sas 4 years ago.
test2_cut.ts (2.4 MB ) - added by Carl Eugen Hoyos 4 years ago.

Change History (6)

by 01sas, 4 years ago

Attachment: ffmpeg-20170428-184536.log added

by Carl Eugen Hoyos, 4 years ago

Attachment: test2_cut.ts added

comment:1 by Carl Eugen Hoyos, 4 years ago

Priority: normalwish
Reproduced by developer: set
Status: newopen
Summary: Video to images functionality does not take SAR into accountffmpeg requires constant output dimensions
Type: defectenhancement
Version: 3.2.4git-master

For future tickets: Please remember to always test current FFmpeg git head.

Even if the output format allows changing dimensions, ffmpeg forces the same dimension for the whole duration of the output video stream (while output aspect ratio change is allowed). I don't think this is related to aspect ratio (although input with changing aspect ratio allows to reproduce the issue, as does input with changing dimenstions). The filter chain works fine as can be tested with ffplay.

comment:2 by Nicolas George, 4 years ago

To complement the previous comment:

Most images format do not contain provisions to store the aspect ratio, they all more or less implicitly assume square pixels.

in reply to:  2 comment:3 by Carl Eugen Hoyos, 4 years ago

Replying to Cigaes:

Most images format do not contain provisions to store the aspect ratio

At least jpg, png, tif and dpx do. Targa and j2k allow it, it isn't supported by FFmpeg for these two though.

comment:4 by 01sas, 4 years ago

First of all thanks for your answers, guys.

Second: I can confirm that filter chains works fine in this case according to results which I can see.

Third: sorry for misunderstanding I was not talking about setting SAR into saved image, square pixels is just fine. I just want the output image stream to reflect possible change in aspect ratio and image to be stored with correct resolution. For command and test video fragment which I attached to ticket I expect that first two images will be with resolution 720x405 and the rest should be with resolution 720x540.

Last edited 4 years ago by 01sas (previous) (diff)
Note: See TracTickets for help on using tickets.