Opened 4 years ago

Last modified 9 months ago

#4141 open enhancement

HEVC: 1920x1080i file decoded as 1920x540p

Reported by: Underground78 Owned by:
Priority: wish Component: avcodec
Version: git-master Keywords: hevc
Cc: Blocked By:
Blocking: Reproduced by developer: yes
Analyzed by developer: no

Description

Summary of the bug:
It seems ffmpeg is decoding this sample as 1920x540 progressive instead of 1920x1080 interlaced.

How to reproduce:

ffmpeg version N-67999-gd0879a9 Copyright (c) 2000-2014 the FFmpeg developers
  built on Nov 25 2014 11:37:18 with gcc 4.9.2 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-decklink --enable-zlib
  libavutil      54. 15.100 / 54. 15.100
  libavcodec     56. 13.100 / 56. 13.100
  libavformat    56. 15.100 / 56. 15.100
  libavdevice    56.  3.100 / 56.  3.100
  libavfilter     5.  2.103 /  5.  2.103
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
[hevc @ 02a52aa0] Could not find ref with POC 72
[hevc @ 02a52aa0] Could not find ref with POC 68
[hevc @ 02a52aa0] Could not find ref with POC 64
Input #0, mpeg, from 'Service 5 (T2 Test) (2014-11-26 01-39-13-695).mpg':
  Duration: 00:00:04.69, start: 50223.448456, bitrate: 3204 kb/s
    Stream #0:0[0x1e0]: Video: hevc (Main), yuv420p(tv), 1920x540, 25 fps, 25 tbr, 90k tbn, 25 tbc
    Stream #0:1[0x80]: Audio: eac3, 48000 Hz, stereo, fltp, 192 kb/s

Change History (9)

comment:1 Changed 4 years ago by robert_s

Is it possible that the H.265/HEVC decoder in ffmpeg cannot handle interlaced content yet? I do not see the progressive_source_flag, interlaced_source_flag or frame_only_constraint flag being evaluated anywhere in the source code...

The "pic_height_in_luma_samples" being 544 seems to be right, as according to page 8 of ITU-T H.265/AVC:

"NOTE – A picture may be either a frame or a field."

So a 1080i stream, encoded in H.265/HEVC as 1088i, a field = picture would indeed have a height of 544 luma samples.

comment:2 Changed 4 years ago by heleppkes

The progressive_source_flag or interlaced_source_flag are only hints on the origin of the material, not an actual indicator that the video is encoded as interlaced fields.

The only field of interest is the field_seq_flag in the VUI, and the picture timing SEIs, which are not being used to combine fields back into frame as it is (but they are parsed).

comment:3 follow-up: Changed 4 years ago by robert_s

Thanks for the pointer to the flag that matters, I was a bit confused which of the flags it was.

So the assumption was correct that support for interlaced HEVC streams is not (fully) implemented yet and the observed behavior is to be expected from the current implementation?

comment:4 in reply to: ↑ 3 Changed 4 years ago by cehoyos

  • Keywords hevc added
  • Priority changed from normal to wish
  • Reproduced by developer set
  • Status changed from new to open
  • Type changed from defect to enhancement

Replying to robert_s:

So the assumption was correct that support for interlaced HEVC streams is not (fully) implemented yet and the observed behavior is to be expected from the current implementation?

The reference decoder does the same as FFmpeg.

comment:5 Changed 4 years ago by robert_s

Taking a closer look at the sample stream, it appears that field_seq_flag is 1 in the VUI, but the SEI indicates pic_struct = 3, for which Table D.2 of H.265 says "field_seq_flag shall be 0"...

What does "pic_struct = 3" actually mean? That one picture is both top and bottom field, i.e. that the "deinterlaced" output would have every line of the picture doubled?

How would that be implemented in ffmpeg? Can that output method be specified in AVFrame, or does the decoder need to do this before passing the AVFrame?

I found that H.264 has the same value for pic_struct, so I looked at the H.264 decoder sources how pic_struct = 3 is handled there, but it doesn't seem to do anything other than indicate interlaced content. Am I missing something or does the H.264 decoder also not support this pic_struct value properly yet?

comment:6 follow-up: Changed 4 years ago by heleppkes

if field_seq_flag is 1 and pic_struct is 3, then the encode is invalid, as it does not conform to the specification which doesn't allow this combination.

As I understand it, 3 and 4 are meant for cases where both fields are in one frame (weaved), and you don't need to do more than to indicate interlaced and field order in ffmpeg, as thats what the API expects anyway.

Last edited 4 years ago by heleppkes (previous) (diff)

comment:7 in reply to: ↑ 6 Changed 4 years ago by robert_s

Replying to heleppkes:

if field_seq_flag is 1 and pic_struct is 3, then the encode is invalid, as it does not conform to the specification which doesn't allow this combination.

I wonder how well that would actually work. Without field_seq_flag indicated in the SPS, the decoder would not know the output size of the video until it gets a SEI message...

Replying to heleppkes:

As I understand it, 3 and 4 are meant for cases where both fields are in one frame (weaved), and you don't need to do more than to indicate interlaced and field order in ffmpeg, as thats what the API expects anyway.

So I assume the decoder needs to do the following if pic_struct == 3:

  1. Decode picture
  2. Stretch decoded picture vertically by doubling each line
  3. Set frame->top_field_first = 1 (would be 0 for pic_struct == 4)
  4. Set frame->interlaced_frame = 1

Is that the way, or is there some way the decoder can omit step 2 and tell ffmpeg to do the line doubling instead...?

Last edited 4 years ago by robert_s (previous) (diff)

comment:8 Changed 2 years ago by cehoyos

  • Component changed from undetermined to avcodec

I remuxed the sample with FFmpeg to mpegts and a Samsung hardware decoder plays the sample in full resolution, so I believe this should be fixed.

Note: See TracTickets for help on using tickets.