Opened 5 years ago

Closed 5 years ago

#1997 closed defect (fixed)

setdar/setsar on muxing to mkv can produce files with wrong aspect ratio on 32 bit

Reported by: kahphi Owned by:
Priority: minor Component: avformat
Version: git-master Keywords: mkv
Cc: Blocked By:
Blocking: Reproduced by developer: yes
Analyzed by developer: yes

Description

I want to transcode mp4 files (with wrong DAR=5:4 and SAR=1:1) into webm using ffmpeg and thereby set the aspect ratios to DAR=4:3 and SAR=16:15.

This works well on a machine with Ubuntu 12.04 64 bit and also on Centos 6.
However I am running Ubuntu 12.04 32bit on the production machine and exactly this setup produces erroneous files with SAR=212:199 and DAR=265:199 on the very same input.
The ffmpeg console output thereby contains the correct values (DAR=4:3 and SAR=16:15) for the produced vp8 stream but ffprobe tells the afore-mentioned values.
The result was the same for an uncompressed avi with no values for DAR/SAR. Using setsar=16:15 and both setdar and setsar does not make a difference.

I tried Ffmpeg versions 1.0, 1.0.1 and the current one from git with the same result.

Differences on the other machines are:
Ubuntu 64 bit: nothing but the runtime environment.
Centos: more recent libogg (1.3.0), libvorbis (1.3.3) but older gcc (GCC) 4.4.6 20120305 (Red Hat 4.4.6-4)

I already tried both libvpx from the Ubuntu repository (1.0.0.1) and the current git version (1.1.0) built upon

./configure --extra-cflags="-fPIC" --enable-pic --enable-shared

How to reproduce:

% /usr/local/bin/ffmpeg -v debug -i mp4_test.mp4 -vcodec libvpx -acodec libvorbis -vf setdar=4:3 -f webm out_mp4-webm_setdaronly.webm
ffmpeg version 1.0 Copyright (c) 2000-2012 the FFmpeg developers
  built on Dec  3 2012 17:02:53 with gcc 4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5)
  configuration: --prefix=/usr/local/ --enable-shared --enable-avfilter --enable-libvorbis --enable-pthreads --enable-libvpx --enable-gpl --enable-pic
  libavutil      51. 73.101 / 51. 73.101
  libavcodec     54. 59.100 / 54. 59.100
  libavformat    54. 29.104 / 54. 29.104
  libavdevice    54.  2.101 / 54.  2.101
  libavfilter     3. 17.100 /  3. 17.100
  libswscale      2.  1.101 /  2.  1.101
  libswresample   0. 15.100 /  0. 15.100
  libpostproc    52.  0.100 / 52.  0.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x8516500] Format mov,mp4,m4a,3gp,3g2,mj2 probed with size=2048 and score=100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x8516500] ISO: File Type Major Brand: isom
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x8516500] File position before avformat_find_stream_info() is 7551734
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x8516500] All info found
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x8516500] File position after avformat_find_stream_info() is 34562
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'mp4_test.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    creation_time   : 1970-01-01 00:00:00
    encoder         : Umile Encoder 3
  Duration: 00:00:10.40, start: 0.000000, bitrate: 5809 kb/s
    Stream #0:0(und), 1, 1/25: Video: mpeg4 (Simple Profile) (mp4v / 0x7634706D), yuv420p, 720x576 [SAR 1:1 DAR 5:4], 1/25, 5612 kb/s, 25 fps, 25 tbr, 25 tbn, 25 tbc
    Metadata:
      creation_time   : 1970-01-01 00:00:00
      handler_name    : VideoHandler
    Stream #0:1(und), 1, 1/48000: Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, s16, 192 kb/s
    Metadata:
      creation_time   : 1970-01-01 00:00:00
      handler_name    : SoundHandler
[Parsed_setdar_0 @ 0x851e920] a:4/3
[buffer @ 0x852ef20] Setting entry with key 'video_size' to value '720x576'
[buffer @ 0x852ef20] Setting entry with key 'pix_fmt' to value '0'
[buffer @ 0x852ef20] Setting entry with key 'time_base' to value '1/25'
[buffer @ 0x852ef20] Setting entry with key 'pixel_aspect' to value '1/1'
[buffer @ 0x852ef20] Setting entry with key 'sws_param' to value 'flags=2'
[buffer @ 0x852ef20] Setting entry with key 'frame_rate' to value '25/1'
[graph 0 input from stream 0:0 @ 0x853e5c0] w:720 h:576 pixfmt:yuv420p tb:1/25 fr:25/1 sar:1/1 sws_param:flags=2
[Parsed_setdar_0 @ 0x851e920] w:720 h:576 -> dar:4/3 sar:16/15
[abuffer @ 0x853e040] Setting entry with key 'time_base' to value '1/48000'
[abuffer @ 0x853e040] Setting entry with key 'sample_rate' to value '48000'
[abuffer @ 0x853e040] Setting entry with key 'sample_fmt' to value 's16'
[abuffer @ 0x853e040] Setting entry with key 'channel_layout' to value '0x3'
[graph 1 input from stream 0:1 @ 0x853dd40] tb:1/48000 samplefmt:s16 samplerate:48000 chlayout:0x3
[aformat @ 0x853d8e0] Setting entry with key 'sample_fmts' to value 'flt'
[audio format for output stream 0:1 @ 0x853d840] auto-inserting filter 'auto-inserted resampler 0' between the filter 'Parsed_anull_0' and the filter 'audio format for output stream 0:1'
[auto-inserted resampler 0 @ 0x8514c60] chl:stereo fmt:s16 r:48000Hz -> chl:stereo fmt:flt r:48000Hz
[libvpx @ 0x853ed80] v1.1.0
[libvpx @ 0x853ed80] --extra-cflags=-fPIC --enable-pic --enable-shared
[libvpx @ 0x853ed80] vpx_codec_enc_cfg
[libvpx @ 0x853ed80] generic settings
  g_usage:                      0
  g_threads:                    0
  g_profile:                    0
  g_w:                          320
  g_h:                          240
  g_timebase:                   {1/30}
  g_error_resilient:            0
  g_pass:                       0
  g_lag_in_frames:              0
[libvpx @ 0x853ed80] rate control settings
  rc_dropframe_thresh:          0
  rc_resize_allowed:            0
  rc_resize_up_thresh:          60
  rc_resize_down_thresh:        30
  rc_end_usage:                 0
  rc_twopass_stats_in:          (nil)(0)
  rc_target_bitrate:            256
[libvpx @ 0x853ed80] quantizer settings
  rc_min_quantizer:             4
  rc_max_quantizer:             63
[libvpx @ 0x853ed80] bitrate tolerance
  rc_undershoot_pct:            100
  rc_overshoot_pct:             100
[libvpx @ 0x853ed80] decoder buffer model
  rc_buf_sz:                    6000
  rc_buf_initial_sz:            4000
  rc_buf_optimal_sz:            5000
[libvpx @ 0x853ed80] 2 pass rate control settings
  rc_2pass_vbr_bias_pct:        50
  rc_2pass_vbr_minsection_pct:  0
  rc_2pass_vbr_maxsection_pct:  400
[libvpx @ 0x853ed80] keyframing settings
  kf_mode:                      1
  kf_min_dist:                  0
  kf_max_dist:                  128
[libvpx @ 0x853ed80] 
[libvpx @ 0x853ed80] vpx_codec_enc_cfg
[libvpx @ 0x853ed80] generic settings
  g_usage:                      0
  g_threads:                    0
  g_profile:                    0
  g_w:                          720
  g_h:                          576
  g_timebase:                   {1/25}
  g_error_resilient:            0
  g_pass:                       0
  g_lag_in_frames:              25
[libvpx @ 0x853ed80] rate control settings
  rc_dropframe_thresh:          0
  rc_resize_allowed:            0
  rc_resize_up_thresh:          60
  rc_resize_down_thresh:        30
  rc_end_usage:                 0
  rc_twopass_stats_in:          (nil)(0)
  rc_target_bitrate:            200
[libvpx @ 0x853ed80] quantizer settings
  rc_min_quantizer:             4
  rc_max_quantizer:             63
[libvpx @ 0x853ed80] bitrate tolerance
  rc_undershoot_pct:            100
  rc_overshoot_pct:             100
[libvpx @ 0x853ed80] decoder buffer model
  rc_buf_sz:                    6000
  rc_buf_initial_sz:            4000
  rc_buf_optimal_sz:            5000
[libvpx @ 0x853ed80] 2 pass rate control settings
  rc_2pass_vbr_bias_pct:        50
  rc_2pass_vbr_minsection_pct:  0
  rc_2pass_vbr_maxsection_pct:  400
[libvpx @ 0x853ed80] keyframing settings
  kf_mode:                      1
  kf_min_dist:                  0
  kf_max_dist:                  128
[libvpx @ 0x853ed80] 
[libvpx @ 0x853ed80] vpx_codec_control
[libvpx @ 0x853ed80]   VP8E_SET_CPUUSED:             3
[libvpx @ 0x853ed80]   VP8E_SET_ARNR_MAXFRAMES:      0
[libvpx @ 0x853ed80]   VP8E_SET_ARNR_STRENGTH:       3
[libvpx @ 0x853ed80]   VP8E_SET_ARNR_TYPE:           3
[libvpx @ 0x853ed80]   VP8E_SET_NOISE_SENSITIVITY:   0
[libvpx @ 0x853ed80]   VP8E_SET_TOKEN_PARTITIONS:    0
[libvpx @ 0x853ed80]   VP8E_SET_STATIC_THRESHOLD:    0
[libvpx @ 0x853ed80]   VP8E_SET_CQ_LEVEL:            0
[libvpx @ 0x853ed80] Using deadline: 1000000
[mpeg4 @ 0x851cee0] detected 2 logical cores
Output #0, webm, to 'out_mp4-webm_setdaronly.webm':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf54.29.104
    Stream #0:0(und), 0, 1/1000: Video: vp8, yuv420p, 720x576 [SAR 16:15 DAR 4:3], 1/25, q=-1--1, 200 kb/s, 1k tbn, 25 tbc
    Metadata:
      creation_time   : 1970-01-01 00:00:00
      handler_name    : VideoHandler
    Stream #0:1(und), 0, 1/1000: Audio: vorbis, 48000 Hz, stereo, flt
    Metadata:
      creation_time   : 1970-01-01 00:00:00
      handler_name    : SoundHandler
Stream mapping:
  Stream #0:0 -> #0:0 (mpeg4 -> libvpx)
  Stream #0:1 -> #0:1 (aac -> libvorbis)
Press [q] to stop, [?] for help
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x8516500] demuxer injecting skip 1024
[aac @ 0x851dbe0] skip 1024 samples due to side data
[aac @ 0x851dbe0] skip whole frame, skip left: 0
[libvorbis @ 0x852e420] Que input is backward in time
[webm @ 0x853e6c0] Writing block at offset 4481, size 35867, pts 0, dts 0, duration 40, flags 128
[webm @ 0x853e6c0] Writing block at offset 40356, size 40, pts 21, dts 21, duration 3, flags 128
[webm @ 0x853e6c0] Writing block at offset 40402, size 222, pts 24, dts 24, duration 12, flags 128
[webm @ 0x853e6c0] Writing block at offset 40631, size 208, pts 36, dts 36, duration 21, flags 128
...

FFprobe:

% /usr/local/bin/ffprobe -print_format json -show_format -show_streams out_mp4-webm_setdaronly.webm 
ffprobe version 1.0 Copyright (c) 2007-2012 the FFmpeg developers
  built on Dec  3 2012 17:02:53 with gcc 4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5)
  configuration: --prefix=/usr/local/ --enable-shared --enable-avfilter --enable-libvorbis --enable-pthreads --enable-libvpx --enable-gpl --enable-pic
  libavutil      51. 73.101 / 51. 73.101
  libavcodec     54. 59.100 / 54. 59.100
  libavformat    54. 29.104 / 54. 29.104
  libavdevice    54.  2.101 / 54.  2.101
  libavfilter     3. 17.100 /  3. 17.100
  libswscale      2.  1.101 /  2.  1.101
  libswresample   0. 15.100 /  0. 15.100
  libpostproc    52.  0.100 / 52.  0.100
{
Input #0, matroska,webm, from 'out_mp4-webm_setdaronly.webm':
  Duration: 00:00:11.33, start: 0.000000, bitrate: 273 kb/s
    Stream #0:0: Video: vp8, yuv420p, 720x576, SAR 212:199 DAR 265:199, 25 fps, 25 tbr, 1k tbn, 1k tbc (default)
    Stream #0:1: Audio: vorbis, 48000 Hz, stereo, s16 (default)
    "streams": [
        {
            "index": 0,
            "codec_name": "vp8",
            "codec_long_name": "On2 VP8",
            "codec_type": "video",
            "codec_time_base": "1/1000",
            "codec_tag_string": "[0][0][0][0]",
            "codec_tag": "0x0000",
            "width": 720,
            "height": 576,
            "has_b_frames": 0,
            "sample_aspect_ratio": "212:199",
            "display_aspect_ratio": "265:199",
            "pix_fmt": "yuv420p",
            "level": -99,
            "r_frame_rate": "25/1",
            "avg_frame_rate": "25/1",
            "time_base": "1/1000",
            "start_pts": 0,
            "start_time": "0.000000"
        },
        {
            "index": 1,
            "codec_name": "vorbis",
            "codec_long_name": "Vorbis",
            "codec_type": "audio",
            "codec_time_base": "1/48000",
            "codec_tag_string": "[0][0][0][0]",
            "codec_tag": "0x0000",
            "sample_fmt": "s16",
            "sample_rate": "48000",
            "channels": 2,
            "bits_per_sample": 0,
            "r_frame_rate": "0/0",
            "avg_frame_rate": "0/0",
            "time_base": "1/1000",
            "start_pts": 0,
            "start_time": "0.000000"
        }
    ],
    "format": {
        "filename": "out_mp4-webm_setdaronly.webm",
        "nb_streams": 2,
        "format_name": "matroska,webm",
        "format_long_name": "Matroska / WebM",
        "start_time": "0.000000",
        "duration": "11.332000",
        "size": "387786",
        "bit_rate": "273763"
    }
}


Change History (15)

comment:1 Changed 5 years ago by cehoyos

  • Keywords mkv added; webm libvpx setdar setsar removed

Maybe I am missing something, but isn't 16/15 ~ 212/199 and 4/3 ~ 265/199 ?

Changed 5 years ago by kahphi

Changed 5 years ago by kahphi

Changed 5 years ago by kahphi

comment:2 Changed 5 years ago by cehoyos

Is this reproducible with current git head? I ask because you wrote that is also fails with current git head, but your output indicates you tested 1.0.1.

Please provide mp4_test.mp4

comment:3 Changed 5 years ago by kahphi

You are right, it is approximately the same. Nevertheless, I am confused that the given input is approximated.

The behavior also shows when using the git head version for both mkv packaging (using vcodec mpeg4) and webm.

I also uploaded a sample to the Mplayer ftp: ffmpeg_ticket_1997.mp4

comment:4 Changed 5 years ago by cehoyos

  • Analyzed by developer set
  • Component changed from undetermined to avformat
  • Reproduced by developer set
  • Status changed from new to open
  • Summary changed from setdar/setsar on webm transcoding produces files with wrong aspect ratio on Ubuntu 12.04 32 bit to setdar/setsar on muxing to mkv can produce files with wrong aspect ratio on 32 bit
  • Version changed from 1.0 to git-master

Reproducible without external libraries:

$ ./ffmpeg -i tests/lena.pnm -s 720x576 -vf setdar=5:4 -vcodec flv1 out.mkv
$ ./ffmpeg -i out.mkv -vf setdar=4:3 -vcodec flv1 out2.mkv

If ffmpeg was compiled with -m64, the resulting file out2.mkv has MATROSKA_ID_VIDEODISPLAYWIDTH set to 768 and DAR is 4:3. If ffmpeg was compiled with -m32, out2.mkv has MATROSKA_ID_VIDEODISPLAYWIDTH set to 767 (and DAR is 265:199) because d_width in mkv_write_tracks() is calculated as 767.

$ ./ffmpeg -i out.mkv -vf setdar=4:3 -vcodec flv1 out32.mkv
ffmpeg version N-47576-g6777aa6 Copyright (c) 2000-2012 the FFmpeg developers
  built on Dec  7 2012 16:37:06 with gcc 4.7 (SUSE Linux)
  configuration: --cc='cc -m32'
  libavutil      52. 11.102 / 52. 11.102
  libavcodec     54. 79.100 / 54. 79.100
  libavformat    54. 47.100 / 54. 47.100
  libavdevice    54.  3.102 / 54.  3.102
  libavfilter     3. 25.101 /  3. 25.101
  libswscale      2.  1.103 /  2.  1.103
  libswresample   0. 17.102 /  0. 17.102
Input #0, matroska,webm, from 'out.mkv':
  Metadata:
    ENCODER         : Lavf54.47.100
  Duration: 00:00:00.04, start: 0.000000, bitrate: 6428 kb/s
    Stream #0:0: Video: flv1 (FLV1 / 0x31564C46), yuv420p, 720x576, SAR 1:1 DAR 5:4, 25 fps, 25 tbr, 1k tbn, 1k tbc (default)
[Parsed_setdar_0 @ 0x93a11e0] num:den syntax is deprecated, please use num/den or named options instead
Output #0, matroska, to 'out32.mkv':
  Metadata:
    encoder         : Lavf54.47.100
    Stream #0:0: Video: flv1 (FLV1 / 0x31564C46), yuv420p, 720x576 [SAR 16:15 DAR 4:3], q=2-31, 200 kb/s, 1k tbn, 25 tbc (default)
Stream mapping:
  Stream #0:0 -> #0:0 (flv -> flv)
Press [q] to stop, [?] for help
frame=    1 fps=0.0 q=5.0 Lsize=      31kB time=00:00:00.04 bitrate=6429.2kbits/s
video:31kB audio:0kB subtitle:0 global headers:0kB muxing overhead 1.963396%
$ ./ffmpeg -i out.mkv -vf setdar=4:3 -vcodec flv1 out64.mkv
ffmpeg version N-47576-g6777aa6 Copyright (c) 2000-2012 the FFmpeg developers
  built on Dec  7 2012 16:38:57 with gcc 4.7 (SUSE Linux)
  configuration: --cc='cc -m64'
  libavutil      52. 11.102 / 52. 11.102
  libavcodec     54. 79.100 / 54. 79.100
  libavformat    54. 47.100 / 54. 47.100
  libavdevice    54.  3.102 / 54.  3.102
  libavfilter     3. 25.101 /  3. 25.101
  libswscale      2.  1.103 /  2.  1.103
  libswresample   0. 17.102 /  0. 17.102
Input #0, matroska,webm, from 'out.mkv':
  Metadata:
    ENCODER         : Lavf54.47.100
  Duration: 00:00:00.04, start: 0.000000, bitrate: 6428 kb/s
    Stream #0:0: Video: flv1 (FLV1 / 0x31564C46), yuv420p, 720x576, SAR 1:1 DAR 5:4, 25 fps, 25 tbr, 1k tbn, 1k tbc (default)
[Parsed_setdar_0 @ 0x2584980] num:den syntax is deprecated, please use num/den or named options instead
Output #0, matroska, to 'out64.mkv':
  Metadata:
    encoder         : Lavf54.47.100
    Stream #0:0: Video: flv1 (FLV1 / 0x31564C46), yuv420p, 720x576 [SAR 16:15 DAR 4:3], q=2-31, 200 kb/s, 1k tbn, 25 tbc (default)
Stream mapping:
  Stream #0:0 -> #0:0 (flv -> flv)
Press [q] to stop, [?] for help
frame=    1 fps=0.0 q=5.0 Lsize=      31kB time=00:00:00.04 bitrate=6429.2kbits/s
video:31kB audio:0kB subtitle:0 global headers:0kB muxing overhead 1.963396%
$ ffmpeg -i out32.mkv -i out64.mkv
ffmpeg version N-47576-g6777aa6 Copyright (c) 2000-2012 the FFmpeg developers
  built on Dec  7 2012 16:40:58 with gcc 4.7 (SUSE Linux)
  configuration: --enable-gpl --disable-indev=jack
  libavutil      52. 11.102 / 52. 11.102
  libavcodec     54. 79.100 / 54. 79.100
  libavformat    54. 47.100 / 54. 47.100
  libavdevice    54.  3.102 / 54.  3.102
  libavfilter     3. 25.101 /  3. 25.101
  libswscale      2.  1.103 /  2.  1.103
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
Input #0, matroska,webm, from 'out32.mkv':
  Metadata:
    ENCODER         : Lavf54.47.100
  Duration: 00:00:00.04, start: 0.000000, bitrate: 6429 kb/s
    Stream #0:0: Video: flv1 (FLV1 / 0x31564C46), yuv420p, 720x576, SAR 212:199 DAR 265:199, 25 fps, 25 tbr, 1k tbn, 1k tbc (default)
Input #1, matroska,webm, from 'out64.mkv':
  Metadata:
    ENCODER         : Lavf54.47.100
  Duration: 00:00:00.04, start: 0.000000, bitrate: 6429 kb/s
    Stream #1:0: Video: flv1 (FLV1 / 0x31564C46), yuv420p, 720x576, SAR 16:15 DAR 4:3, 25 fps, 25 tbr, 1k tbn, 1k tbc (default)
At least one output file must be specified

comment:5 Changed 5 years ago by Cigaes

Does the following patch fix things for you?
http://ffmpeg.org/pipermail/ffmpeg-devel/2012-December/135431.html

(by the way, it would be nice to have an archive where patches could be extracted more easily)

comment:6 Changed 5 years ago by cehoyos

Yes, your patch fixes the problem on ia32.

comment:7 Changed 5 years ago by kahphi

The patch fixes it for me as well.

Thank you very much, gentlemen!

comment:8 Changed 5 years ago by cehoyos

  • Resolution set to fixed
  • Status changed from open to closed

Fixed by Cigaes.

Note: See TracTickets for help on using tickets.