Opened 13 years ago

Closed 12 years ago

#404 closed defect (needs_more_info)

Rounding error in scaling expression

Reported by: blaw Owned by:
Priority: normal Component: undetermined
Version: git Keywords: rouding scalling expression
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: yes

Description

Looks like the calculation in the scaling filter is not rounding properly.

This is the math I'm doing to convert all inputs to square pixels while maintaining aspect ratio.

-vf scale='iw:ow/dar',setsar=1:1

The input video is 352x480 with SAR of 20:11 and DAR of 4:3.

The output file becomes 352x263. But when I do the math it should be 352x264. And since 263 isn't divisible by 2, the output video has color artifacts at the bottom.

Here's my math (using windows calc):
ow = 352
dar = 4:3 = 1.3333333333333333333333333333333
352/1.3333333333333333333333333333333 = 264.00000000000000000000000000007

=================================================

*

  • Input Video *

*
Input #0, mpeg, from '/data/transcode/input/Code Violation_ Azarenka_Clijsters in Miami.mpg':

Duration: 00:01:16.70, start: 0.213367, bitrate: 2661 kb/s

Stream #0.0[0x1e0]: Video: mpeg2video (Main), yuv420p, 352x480 [SAR 20:11 DAR 4:3], 2714 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
Stream #0.1[0x80]: Audio: ac3, 48000 Hz, stereo, s16, 224 kb/s

[STREAM]
index=0
codec_name=mpeg2video
codec_long_name=MPEG-2 video
codec_type=video
codec_time_base=1001/60000
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
width=352
height=480
has_b_frames=1
sample_aspect_ratio=20:11
display_aspect_ratio=4:3
pix_fmt=yuv420p
level=8
id=0x1e0
r_frame_rate=30000/1001
avg_frame_rate=30000/1001
time_base=1/90000
start_time=0.213367
duration=76.576500
STREAM

*

  • Output Video *

*
Input #0, matroska,webm, from '/data/transcode/input/Code Violation_ Azarenka_Clijsters in Miami.mpg.webm':

Duration: 00:00:07.57, start: 0.000000, bitrate: N/A

Stream #0.0: Video: vp8, yuv420p, 352x263, SAR 1:1 DAR 352:263, 29.97 fps, 29.97 tbr, 1k tbn, 29.97 tbc (default)
Stream #0.1: Audio: vorbis, 44100 Hz, stereo, s16 (default)

[STREAM]
index=0
codec_name=vp8
codec_long_name=On2 VP8
codec_type=video
codec_time_base=1001/30000
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
width=352
height=263
has_b_frames=0
pix_fmt=yuv420p
level=-99
r_frame_rate=30000/1001
avg_frame_rate=1349849997/45039994
time_base=1/1000
start_time=0.000000
duration=N/A
STREAM

*

  • ffmpeg cmd *

*
WEBM_PROFILE="-vf yadif=0:-1:1,unsharp=3:3:1.0,scale='iw:ow/dar',setsar=1:1 -f webm -threads 0 -vcodec libvpx -g 360 -keyint_min 0 -vb 800k -qmin 1 -qmax 63 -quality good -slices 1 -vp8flags altref -acodec libvorbis -ac 2 -ab 128k -ar 44100"

ffmpeg -i <filename> $WEBM_PROFILE -y <filename>.webm

ffmpeg version 0.8.2.git, Copyright (c) 2000-2011 the FFmpeg developers

built on Aug 17 2011 15:52:09 with gcc 4.4.3
configuration: --enable-gpl --enable-version3 --enable-nonfree --enable-postproc --enable-libfaac --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-x11grab --enable-libmp3lame --enable-libvpx --enable-static
libavutil 51. 12. 0 / 51. 12. 0
libavcodec 53. 11. 0 / 53. 11. 0
libavformat 53. 7. 0 / 53. 7. 0
libavdevice 53. 3. 0 / 53. 3. 0
libavfilter 2. 32. 0 / 2. 32. 0
libswscale 2. 0. 0 / 2. 0. 0
libpostproc 51. 2. 0 / 51. 2. 0

Change History (2)

comment:1 by Stefano Sabatini, 13 years ago

Unreproducible here with the command (you need git of the day for testing it):

$ ffplay -f lavfi  "testsrc=s=352x480:sar=20/11,scale=iw:ow/dar"
ffplay version N-32028-g34c9975, Copyright (c) 2003-2011 the FFmpeg developers
  built on Aug 21 2011 15:27:17 with gcc 4.4.5
  configuration: --prefix=/home/stefano --enable-libx264 --enable-libxvid --enable-librtmp --disable-shared --enable-static --enable-debug=3 --enable-pthreads --enable-libvorbis --enable-avfilter --enable-gpl --enable-nonfree --enable-libmp3lame --enable-libtheora --enable-gpl --enable-x11grab --enable-libschroedinger --enable-libopenjpeg --enable-frei0r --enable-libopencv --disable-optimizations --disable-mmx --enable-libfreetype
  libavutil    51. 13. 0 / 51. 13. 0
  libavcodec   53. 11. 0 / 53. 11. 0
  libavformat  53.  9. 0 / 53.  9. 0
  libavdevice  53.  3. 0 / 53.  3. 0
  libavfilter   2. 34. 1 /  2. 34. 0
  libswscale    2.  0. 0 /  2.  0. 0
  libpostproc  51.  2. 0 / 51.  2. 0
[testsrc @ 0xa2c0790] size:352x480 rate:25/1 duration:-1.000000 sar:20/11
[scale @ 0xa28efe0] w:352 h:480 fmt:rgb24 -> w:352 h:264 fmt:yuv420p flags:0x2
[lavfi @ 0xa2bf8a0] Estimating duration from bitrate, this may be inaccurate
Input #0, lavfi, from 'testsrc=s=352x480:sar=20/11,scale=iw:ow/dar':
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0.0: Video: rawvideo, yuv420p, 352x264 [SAR 20:11 DAR 80:33], 25 tbr, 25 tbn, 25 tbc
   5.32 A-V:  0.000 s:0.0 aq=    0KB vq=  817KB sq=    0B f=0/0   0/0   

Please try and report, I guess it may be a platform-specific problem.
Even in this case, you can force the h value to be a multiple of the chroma vertical subsampling value, for example by setting scale=iw:floor(ow/dar/hsub)*hsub.

comment:2 by Stefano Sabatini, 12 years ago

Analyzed by developer: set
Resolution: needs_more_info
Status: newclosed

Please reopen if you have more information.

Note: See TracTickets for help on using tickets.