Opened 6 years ago

Last modified 6 years ago

#1766 new defect

Can't encode MPEG-2 at more than ~3Mb/s

Reported by: agusdallalba Owned by:
Priority: normal Component: undetermined
Version: git-master Keywords: mpeg2video dvd
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug: I'm trying to convert a 720p25 video to DVD-spec 6500kbps MPEG2, but the output is <3Mb/s instead. The subjective quality is not that good, there are blocks in the background and the picture lacks sharpness. I'm using ffmpeg version git-2012-09-26-299c0b3.

The source video is a remuxed Sherlock.S01E01.720p.BluRay?.x264-AVCHD, that can be easily found in P2P sites. With some guidance I can try encoding the original BluRay?, but ripping it on linux has proven itself way too difficult for me and I figured it would be the same.

I originally used a much more complicated command line, but the issue is still there with the stripped-down ffmpeg -i "$1" -target pal-dvd -b:v 6450k -an -pass 1/2 "$1".mpg -report

I've attached ffmpeg's reports and the two-pass log, please tell me if you need anything else, I'll try to reply as soon as I can. Thanks!

Attachments (12)

report_firtspass.log.gz (203.0 KB) - added by agusdallalba 6 years ago.
report_secondpass.log.gz (226.6 KB) - added by agusdallalba 6 years ago.
Sherlock S01E01 sample.mkv (2.4 MB) - added by agusdallalba 6 years ago.
ffmpeg-20120927-122348.log (375.0 KB) - added by agusdallalba 6 years ago.
out.mpg (296.0 KB) - added by agusdallalba 6 years ago.
Output for Sherlock S01E01 sample.mkv
out.mpg.png (138.1 KB) - added by agusdallalba 6 years ago.
Enhanced frame from out.mpg
outframe26.jpg (18.4 KB) - added by agusdallalba 6 years ago.
Untouched still from out.mpg.
sourceframe26.png (639.4 KB) - added by agusdallalba 6 years ago.
Untouched frame from the sample, PNG format.
sourceframe26_scaled.jpg (19.6 KB) - added by agusdallalba 6 years ago.
Untouched frame from the sample, JPEG quality 0, quite blocky.
sourceframe26_scaled.2.jpg (19.6 KB) - added by agusdallalba 6 years ago.
Scaled frame from the sample, JPEG quality 0, very blocky.
sourceframe26.jpg (53.5 KB) - added by agusdallalba 6 years ago.
Untouched frame from the sample, JPEG quality 0, quite blocky.
sourceframe26_scaled.png (291.6 KB) - added by agusdallalba 6 years ago.
Scaled frame from the sample for comparison, PNG format.

Change History (19)

Changed 6 years ago by agusdallalba

Changed 6 years ago by agusdallalba

comment:1 Changed 6 years ago by cehoyos

  • Keywords changed from mpeg2video, dvd to mpeg2video dvd
  • Version changed from unspecified to git-master

You could compare the output file size with the following:
$ ffmpeg -i Sherlock\ S01E01.mp4 -s 720x576 -qscale 2 -acodec ac3 -ab 448k out.mpg

If you still see the blocks and other quality issues, try to cut the relevant part from the original sample with:
$ ffmpeg -ss xxx -i Sherlock\ S01E01.mp4 -vcodec copy -t yyy out.h264
and provide the sample (if it does not show the same visual problems)

Changed 6 years ago by agusdallalba

Changed 6 years ago by agusdallalba

comment:2 Changed 6 years ago by agusdallalba

out.mpg is 2242MB long, averaging 3393 kb/s for video + audio. However ffprobe says

Input #0, mpeg, from 'out.mpg':
  Duration: 01:28:05.76, start: 0.994667, bitrate: 3393 kb/s
    Stream #0:0[0x1e0]: Video: mpeg1video, yuv420p, 720x576 [SAR 1:1 DAR 5:4], 104857 kb/s, 25 fps, 25 tbr, 90k tbn, 25 tbc
    Stream #0:1[0x80]: Audio: ac3, 48000 Hz, 5.1(side), s16, 448 kb/s

Note the 104857 kb/s in the first stream.

FFmpeg complained a lot during the transcode about with [mpeg1video @ 0x1d56f40] warning, clipping 1 dct coefficients to -255..255

I've attached the full report and a short enough sample that is considerably blocky after after the transcode on my setup, particularly in the background.

comment:3 Changed 6 years ago by cehoyos

I tested the following:
$ ffmpeg -i Sherlock\ S01E01\ sample.mkv -target pal-dvd -b:v 6450k -pass 1 out.mpg
$ ffmpeg -i Sherlock\ S01E01\ sample.mkv -target pal-dvd -b:v 6450k -pass 2 out.mpg

I don't see any quality issues with out.mpg.
Please provide an input sample that allows to reproduce quality issues for the output file.

Concerning the bitrate: Please understand that you cannot reach 6k for every input sample, if you encode with -qscale 2 you should see the approximate maximum file size.

comment:4 Changed 6 years ago by agusdallalba

Using your exact command line with ffmpeg version git-2012-10-06-293e542 outputs a blocky background with heavy banding in my setup. I'll attach my out.mpg and a frame from it enhanced to show the banding that, while is not very visible in a well lit room, pops out in a darkened living room.

Changed 6 years ago by agusdallalba

Output for Sherlock S01E01 sample.mkv

Changed 6 years ago by agusdallalba

Enhanced frame from out.mpg

comment:5 Changed 6 years ago by cehoyos

I can reproduce the banding with out.mpg.png but not with out.mpg.
How did you produce the png? Could you compare with:
$ ffmpeg -i out.mpg out%2d.png
or, since there may be quality loss when encoding from yuv420p (mpg) to rgb (png):
$ ffmpeg -i out.mpg -qscale 2 out%2d.jpg

comment:6 Changed 6 years ago by agusdallalba

To produce out.mpg.png I extracted a frame with mplayer (in PNG) and then did a levels adjustment in The GIMP to bring out the banding, although It's clearly visible without the enhancement anyway. It's an artifact I'd expect to have at such a low bitrate, but I was aiming for the best quality I could get in a DVD5.

To discard a decoding issue I tested the file in Windows Media Player, VLC, and a standalone DVD player, and the blockiness is there in the three of them.

Changed 6 years ago by agusdallalba

Untouched still from out.mpg.

comment:7 Changed 6 years ago by agusdallalba

I just tried to extract a jpg still from the source, and it showed the same kind of blockiness in the jpg output. PNG, on the other side, was perfect.

ffmpeg -v 9 -loglevel 99 -i Sherlock\ S01E01\ sample.mkv -ss 1 -vframes 1 -qscale 0 sourceframe26.jpg
ffmpeg version 1.0 Copyright (c) 2000-2012 the FFmpeg developers
  built on Sep 29 2012 11:22:50 with gcc 4.7.1 (GCC) 20120721 (prerelease)
  configuration: --prefix=/usr --enable-libmp3lame --enable-libvorbis --enable-libxvid --enable-libx264 --enable-libvpx --enable-libtheora --enable-libgsm --enable-libspeex --enable-postproc --enable-shared --enable-x11grab --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libschroedinger --enable-libopenjpeg --enable-librtmp --enable-libpulse --enable-libv4l2 --enable-gpl --enable-version3 --enable-runtime-cpudetect --disable-debug --disable-static
  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
[matroska,webm @ 0x1e3e240] Format matroska,webm probed with size=2048 and score=100
st:0 removing common factor 1000000 from timebase
[matroska,webm @ 0x1e3e240] File position before avformat_find_stream_info() is 1586
[h264 @ 0x1e41120] Using externally provided dimensions
[h264 @ 0x1e41120] no picture 
[matroska,webm @ 0x1e3e240] All info found
[matroska,webm @ 0x1e3e240] File position after avformat_find_stream_info() is 1908009
Input #0, matroska,webm, from 'Sherlock S01E01 sample.mkv':
  Metadata:
    -- CUT --
    ENCODER         : Lavf54.28.101
  Duration: 00:00:00.76, start: 0.000000, bitrate: 26954 kb/s
    Stream #0:0(eng), 45, 1/1000: Video: h264 (High), yuv420p, 1280x720, 1/50, SAR 1:1 DAR 16:9, 25 fps, 25 tbr, 1k tbn, 50 tbc (default)
    Metadata:
      CREATION_TIME   : 2010-08-28 16:03:10
      LANGUAGE        : eng
      HANDLER_NAME    : VideoHandler
Please use -q:a or -q:v, -qscale is ambiguous
[buffer @ 0x2262480] Setting entry with key 'video_size' to value '1280x720'
[buffer @ 0x2262480] Setting entry with key 'pix_fmt' to value '0'
[buffer @ 0x2262480] Setting entry with key 'time_base' to value '1/1000'
[buffer @ 0x2262480] Setting entry with key 'pixel_aspect' to value '1/1'
[buffer @ 0x2262480] Setting entry with key 'sws_param' to value 'flags=2'
[buffer @ 0x2262480] Setting entry with key 'frame_rate' to value '25/1'
[graph 0 input from stream 0:0 @ 0x1e43460] w:1280 h:720 pixfmt:yuv420p tb:1/1000 fr:25/1 sar:1/1 sws_param:flags=2
[format @ 0x2275e40] auto-inserting filter 'auto-inserted scaler 0' between the filter 'Parsed_null_0' and the filter 'format'
[auto-inserted scaler 0 @ 0x2310b00] picking yuvj420p out of 2 ref:yuv420p alpha:0
[auto-inserted scaler 0 @ 0x2310b00] w:1280 h:720 fmt:yuv420p sar:1/1 -> w:1280 h:720 fmt:yuvj420p sar:1/1 flags:0x4
[mjpeg @ 0x2212c20] detected 4 logical cores
[mjpeg @ 0x1e79640] intra_quant_bias = 96 inter_quant_bias = 0
[mjpeg @ 0x1e92240] intra_quant_bias = 96 inter_quant_bias = 0
[mjpeg @ 0x1fe2ea0] intra_quant_bias = 96 inter_quant_bias = 0
[mjpeg @ 0x202c360] intra_quant_bias = 96 inter_quant_bias = 0
[mjpeg @ 0x2212c20] intra_quant_bias = 96 inter_quant_bias = 0
[h264 @ 0x1e41120] detected 4 logical cores
Output #0, image2, to 'sourceframe26.jpg':
  Metadata:
    -- CUT --
    encoder         : Lavf54.29.104
    Stream #0:0(eng), 0, 1/90000: Video: mjpeg, yuvj420p, 1280x720 [SAR 1:1 DAR 16:9], 1/25, q=2-31, 200 kb/s, 90k tbn, 25 tbc (default)
    Metadata:
      CREATION_TIME   : 2010-08-28 16:03:10
      LANGUAGE        : eng
      HANDLER_NAME    : VideoHandler
Stream mapping:
  Stream #0:0 -> #0:0 (h264 -> mjpeg)
Press [q] to stop, [?] for help
[h264 @ 0x25e45e0] Using externally provided dimensions
[h264 @ 0x25e45e0] no picture 
[h264 @ 0x2629420] no picture 
No more output streams to write to, finishing.
frame=    1 fps=0.0 q=0.0 Lsize=       0kB time=00:00:00.04 bitrate=   0.0kbits/s    
video:54kB audio:0kB subtitle:0 global headers:0kB muxing overhead -100.000000%
[AVIOContext @ 0x1e46900] Statistics: 1936179 bytes read, 0 seeks
ffmpeg -v 9 -loglevel 99 -i Sherlock\ S01E01\ sample.mkv -ss 1 -s 720x576 -vframes 1 -qscale 0 sourceframe26_scaled.png
ffmpeg version 1.0 Copyright (c) 2000-2012 the FFmpeg developers
  built on Sep 29 2012 11:22:50 with gcc 4.7.1 (GCC) 20120721 (prerelease)
  configuration: --prefix=/usr --enable-libmp3lame --enable-libvorbis --enable-libxvid --enable-libx264 --enable-libvpx --enable-libtheora --enable-libgsm --enable-libspeex --enable-postproc --enable-shared --enable-x11grab --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libschroedinger --enable-libopenjpeg --enable-librtmp --enable-libpulse --enable-libv4l2 --enable-gpl --enable-version3 --enable-runtime-cpudetect --disable-debug --disable-static
  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
[matroska,webm @ 0xd88240] Format matroska,webm probed with size=2048 and score=100
st:0 removing common factor 1000000 from timebase
[matroska,webm @ 0xd88240] File position before avformat_find_stream_info() is 1586
[h264 @ 0xd8b120] Using externally provided dimensions
[h264 @ 0xd8b120] no picture 
[matroska,webm @ 0xd88240] All info found
[matroska,webm @ 0xd88240] File position after avformat_find_stream_info() is 1908009
Input #0, matroska,webm, from 'Sherlock S01E01 sample.mkv':
  Metadata:
    -- CUT --
    ENCODER         : Lavf54.28.101
  Duration: 00:00:00.76, start: 0.000000, bitrate: 26954 kb/s
    Stream #0:0(eng), 45, 1/1000: Video: h264 (High), yuv420p, 1280x720, 1/50, SAR 1:1 DAR 16:9, 25 fps, 25 tbr, 1k tbn, 50 tbc (default)
    Metadata:
      CREATION_TIME   : 2010-08-28 16:03:10
      LANGUAGE        : eng
      HANDLER_NAME    : VideoHandler
Please use -q:a or -q:v, -qscale is ambiguous
[buffer @ 0x11ac480] Setting entry with key 'video_size' to value '1280x720'
[buffer @ 0x11ac480] Setting entry with key 'pix_fmt' to value '0'
[buffer @ 0x11ac480] Setting entry with key 'time_base' to value '1/1000'
[buffer @ 0x11ac480] Setting entry with key 'pixel_aspect' to value '1/1'
[buffer @ 0x11ac480] Setting entry with key 'sws_param' to value 'flags=2'
[buffer @ 0x11ac480] Setting entry with key 'frame_rate' to value '25/1'
[graph 0 input from stream 0:0 @ 0xd8d460] w:1280 h:720 pixfmt:yuv420p tb:1/1000 fr:25/1 sar:1/1 sws_param:flags=2
[scaler for output stream 0:0 @ 0x1182200] picking rgb24 out of 7 ref:yuv420p alpha:0
[scaler for output stream 0:0 @ 0x1182200] w:1280 h:720 fmt:yuv420p sar:1/1 -> w:720 h:576 fmt:rgb24 sar:64/45 flags:0x4
[png @ 0x115cc20] detected 4 logical cores
[h264 @ 0xd8b120] detected 4 logical cores
Output #0, image2, to 'sourceframe26_scaled.png':
  Metadata:
    -- CUT --
    encoder         : Lavf54.29.104
    Stream #0:0(eng), 0, 1/90000: Video: png, rgb24, 720x576 [SAR 64:45 DAR 16:9], 1/25, q=2-31, 200 kb/s, 90k tbn, 25 tbc (default)
    Metadata:
      CREATION_TIME   : 2010-08-28 16:03:10
      LANGUAGE        : eng
      HANDLER_NAME    : VideoHandler
Stream mapping:
  Stream #0:0 -> #0:0 (h264 -> png)
Press [q] to stop, [?] for help
[h264 @ 0xe746c0] Using externally provided dimensions
[h264 @ 0xe746c0] no picture 
[h264 @ 0xeb9020] no picture 
No more output streams to write to, finishing.
frame=    1 fps=0.0 q=0.0 Lsize=       0kB time=00:00:00.04 bitrate=   0.0kbits/s    
video:309kB audio:0kB subtitle:0 global headers:0kB muxing overhead -100.000000%
[AVIOContext @ 0xd90900] Statistics: 1936179 bytes read, 0 seeks

Changed 6 years ago by agusdallalba

Untouched frame from the sample, PNG format.

Changed 6 years ago by agusdallalba

Untouched frame from the sample, JPEG quality 0, quite blocky.

Changed 6 years ago by agusdallalba

Scaled frame from the sample, JPEG quality 0, very blocky.

Changed 6 years ago by agusdallalba

Untouched frame from the sample, JPEG quality 0, quite blocky.

Changed 6 years ago by agusdallalba

Scaled frame from the sample for comparison, PNG format.

Note: See TracTickets for help on using tickets.