From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 240254E1E3 for ; Wed, 14 Jan 2026 14:55:49 +0000 (UTC) Authentication-Results: ffbox; dkim=fail (body hash mismatch (got b'WNZm5+0FC+2o8FSSRPI6S3Nh0MITc9f5s01yqmiXuN0=', expected b'ZliQKkb/jW2ph7UaO5c5jTlNRvwjIao8RcYt/iKaW0k=')) header.d=ffmpeg.org header.i=@ffmpeg.org header.a=rsa-sha256 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1768402539; h=mime-version : to : date : message-id : reply-to : subject : list-id : list-archive : list-archive : list-help : list-owner : list-post : list-subscribe : list-unsubscribe : from : cc : content-type : content-transfer-encoding : from; bh=WNZm5+0FC+2o8FSSRPI6S3Nh0MITc9f5s01yqmiXuN0=; b=jZkjJZbP/k95N2kcwfrZFXLBdWZv04i1rVPnzWA97SjDjZTsKGy99DH8Tg8fGZTbbZrcy 3VZkwVyntINL+9h6e0rVSdgRP8p/Soehwg+aDBdd/Cgvzp1pEmM7Ox6XfQOkHvm82uQrNDo MqQI9OCEKvldyKYq1pZBEhTRt1RhqpFQ5z2cq9rj2SpbkkrpP8KMVCF08zN7T+jglIv3sSe GalxKW7/L++dNQ+aY+xJs2nKv4uik06GRYrcsmaXd+rogPLtEu9/ujaJXriYcM+ZEZVma0n lnLJIGS7aDu71WfOzkNofrKZFv9nDZmSSDnXKQxBpUgwfpiLePixOzVVDq2Q== Received: from [172.20.0.4] (unknown [172.20.0.4]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 53254690E13; Wed, 14 Jan 2026 16:55:39 +0200 (EET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=ffmpeg.org; s=arc; t=1768402525; b=P9h2H18oNeT3a6D/hdxyBHA7VoYv2iZGFCNWZ1Yk5g+pkgepFB1CFro7V+q/Xa1xmje0X vE2GWZQDHanNZ/3Suh3lsNQWRN2I2CCO2plXWjTJ7q6TV49qEIauuvC1KYpQoqomqUkKvj5 3/1I+iUk0EmOf0FqbDYzlqndSmx9OlzCRMuqhYVYSDMzNeHX6V25swipeWqDPV7eUYUDOL0 5fNEKqGLzRCbq6EAM1z72f4lylOfO/nC3sl89i6x8p6+xQmmxjdoC3FPkWLScvf6LuX589+ M+weln16wccCLkE8dGkAI4YkkjktRdqe6rdI6XQ247KIkVWB8ptvllE5/l1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=ffmpeg.org; s=arc; t=1768402525; h=from : sender : reply-to : subject : date : message-id : to : cc : mime-version : content-type : content-transfer-encoding : content-id : content-description : resent-date : resent-from : resent-sender : resent-to : resent-cc : resent-message-id : in-reply-to : references : list-id : list-help : list-unsubscribe : list-subscribe : list-post : list-owner : list-archive; bh=8vRSBH6o9qT2cxGoQXC2T041vhmHoE6OwBKyln4pG+s=; b=c0ML3wTg/jHM0zKb3gMTnR0aitC6pSCggTl2o0Z8/3YjsSK4MKCG1ZIoNLUsnHmV8FWyD i4n71sdpZDdvfQRze+rlyAkHF3/4VpbKEEBUauETWjReF5yUBCnku2TLl1xuPmwG8IMtB2j PaRlFgR3tVkSVw6RlBDkea+tnKBjuDuE4ApC+6vj7YQAVbXYLje9UgzXNl6lxzAswJmj1N6 zRf9Ka7UniarMhzvTmu9hhpcI6vNVM/4dR86A7OfJQ9ypmk/FeLZU212rFHm0sMOCf4C6Z3 ywmXY7P2vp8+HOFs0mUfPxmmXupUTI4FEu1ZMnZac/NZidCBtlCtLn5CfZrQ== ARC-Authentication-Results: i=1; ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none; dmarc=pass header.from=ffmpeg.org policy.dmarc=quarantine Authentication-Results: ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none (Message is not ARC signed); dmarc=pass (Used From Domain Record) header.from=ffmpeg.org policy.dmarc=quarantine DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1768402516; h=content-type : mime-version : content-transfer-encoding : from : to : reply-to : subject : date : from; bh=ZliQKkb/jW2ph7UaO5c5jTlNRvwjIao8RcYt/iKaW0k=; b=zBO73l4glSnc0i5Lq7xkvRaWxzcC4mNMT96aq6czZ7HNe7bY6y6PZDmM1jX1B3YB7Z1KE kCa52hgQjnF+8SoucaesAx4UFPMiLkv31r3dIgGS0s2ItV3cOX04x2Fa23q+TVlQdvmTpef e1Q51R6CPPzWnUWzM4RFOQ1B5u4zPmBVzjnH3PICiV4cAlYiybLc2C4sHosAWwd1NEnb1jK reFIYshWMu9DYaxUa7cbZ2Z50cndPwbB7xpDm6SKBJi2kW7wy0XTjdPgxeeLFKPYC5qOkeG ky0VtL15jzgckksXw2Zp+c98OtGPo7Bx+eWqXKn1bhGFQqFyYa/Axgh5D02Q== Received: from f7c34508609e (code.ffmpeg.org [188.245.149.3]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id D3A9768F579 for ; Wed, 14 Jan 2026 16:55:16 +0200 (EET) MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Date: Wed, 14 Jan 2026 14:55:16 -0000 Message-ID: <176840251704.25.6593341864695668571@4457048688e7> Message-ID-Hash: TZVKFXEPECQLXTGTRM4D2XKO62MNQDSQ X-Message-ID-Hash: TZVKFXEPECQLXTGTRM4D2XKO62MNQDSQ X-MailFrom: code@ffmpeg.org X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-ffmpeg-devel.ffmpeg.org-0; header-match-ffmpeg-devel.ffmpeg.org-1; header-match-ffmpeg-devel.ffmpeg.org-2; header-match-ffmpeg-devel.ffmpeg.org-3; emergency; member-moderation X-Mailman-Version: 3.3.10 Precedence: list Reply-To: FFmpeg development discussions and patches Subject: [FFmpeg-devel] [PR] libavcodec/hevc: Identify field paired HEVC content (PR #21467) List-Id: FFmpeg development discussions and patches Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: colekas via ffmpeg-devel Cc: colekas Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Archived-At: List-Archive: List-Post: PR #21467 opened by colekas URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21467 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21467.patch Some HEVC codecs can generate field paired HEVC content that libavcodec identifies as just TOP or BOT fields when the data for the frame is stored in the resulting AVFrame structure. In the decoder identify when the content is encoded as field pairs so upstream applications can maybe weave the two fields into a full frame. See https://github.com/Intel-Media-SDK/MediaSDK/blob/master/doc/mediasdk_hevc_interlace_whitepaper.md for details. >>From 797727c8ccd08c75b431ec409a650e2301f6ca88 Mon Sep 17 00:00:00 2001 From: Christopher Olekas Date: Wed, 14 Jan 2026 09:50:56 -0500 Subject: [PATCH] libavcodec/hevc: Identify field paired HEVC content Some HEVC codecs can generate field paired HEVC content that libavcodec identifies as just TOP or BOT fields when the data for the frame is stored in the resulting AVFrame structure. In the decoder identify when the content is encoded as field pairs so upstream applications can maybe weave the two fields into a full frame. See https://github.com/Intel-Media-SDK/MediaSDK/blob/master/doc/mediasdk_hevc_interlace_whitepaper.md for details. --- libavcodec/avcodec.c | 5 +++++ libavcodec/defs.h | 2 ++ libavcodec/hevc/parser.c | 12 ++++++++++++ libavcodec/hevc/sei.c | 13 ++++++++----- libavcodec/hevc/sei.h | 3 +++ 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c index de4e083db1..7fdaf9d42f 100644 --- a/libavcodec/avcodec.c +++ b/libavcodec/avcodec.c @@ -587,6 +587,11 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode) field_order = "top coded first (swapped)"; else if (enc->field_order == AV_FIELD_BT) field_order = "bottom coded first (swapped)"; + else if (enc->field_order == AV_FIELD_PAIRED_TB) + field_order = "field paired top first"; + else if (enc->field_order == AV_FIELD_PAIRED_BT) + field_order = "field paired bottom first"; + av_bprintf(&bprint, "%s, ", field_order); } diff --git a/libavcodec/defs.h b/libavcodec/defs.h index b13e983b13..c31ff9cd80 100644 --- a/libavcodec/defs.h +++ b/libavcodec/defs.h @@ -215,6 +215,8 @@ enum AVFieldOrder { AV_FIELD_BB, ///< Bottom coded first, bottom displayed first AV_FIELD_TB, ///< Top coded first, bottom displayed first AV_FIELD_BT, ///< Bottom coded first, top displayed first + AV_FIELD_PAIRED_TB, ///< Top fields are paired with next bottom fields + AV_FIELD_PAIRED_BT, ///< Bottom fields are paired with next top fields }; /** diff --git a/libavcodec/hevc/parser.c b/libavcodec/hevc/parser.c index 62bcd91172..2d41aac4e7 100644 --- a/libavcodec/hevc/parser.c +++ b/libavcodec/hevc/parser.c @@ -70,6 +70,18 @@ static int hevc_parse_slice_header(AVCodecParserContext *s, H2645NAL *nal, first_slice_in_pic_flag = get_bits1(gb); s->picture_structure = sei->picture_timing.picture_struct; s->field_order = sei->picture_timing.picture_struct; + /* HEVC field coding has the following table + Top Field paired with previous Bottom Field: 9 (AV_FIELD_PAIRED_BT) + Top Field paired with next Bottom Field: 10 (AV_FIELD_PAIRED_TB) + Bottom Field paired with previous Top Field: 11 (AV_FIELD_PAIRED_TB) + Bottom Field paired with next Top Field: 12 (AV_FIELD_PAIRED_BT) + */ + if (sei->picture_timing.hevc_picture_struct == 9 || sei->picture_timing.hevc_picture_struct == 12) { + s->field_order = AV_FIELD_PAIRED_BT; + } + else if (sei->picture_timing.hevc_picture_struct == 10 || sei->picture_timing.hevc_picture_struct == 11) { + s->field_order = AV_FIELD_PAIRED_TB; + } if (IS_IRAP_NAL(nal)) { s->key_frame = 1; diff --git a/libavcodec/hevc/sei.c b/libavcodec/hevc/sei.c index 5fd4e763b3..b95959a095 100644 --- a/libavcodec/hevc/sei.c +++ b/libavcodec/hevc/sei.c @@ -59,21 +59,24 @@ static int decode_nal_sei_pic_timing(HEVCSEI *s, GetBitContext *gb, return AVERROR_INVALIDDATA; if (sps->vui.frame_field_info_present_flag) { - int pic_struct = get_bits(gb, 4); + h->hevc_picture_struct = get_bits(gb, 4); h->picture_struct = AV_PICTURE_STRUCTURE_UNKNOWN; - if (pic_struct == 2 || pic_struct == 10 || pic_struct == 12) { + if (h->hevc_picture_struct == 2 || h->hevc_picture_struct == 10 || h->hevc_picture_struct == 12) { av_log(logctx, AV_LOG_DEBUG, "BOTTOM Field\n"); h->picture_struct = AV_PICTURE_STRUCTURE_BOTTOM_FIELD; - } else if (pic_struct == 1 || pic_struct == 9 || pic_struct == 11) { + } else if (h->hevc_picture_struct == 1 || h->hevc_picture_struct == 9 || h->hevc_picture_struct == 11) { av_log(logctx, AV_LOG_DEBUG, "TOP Field\n"); h->picture_struct = AV_PICTURE_STRUCTURE_TOP_FIELD; - } else if (pic_struct == 7) { + } else if (h->hevc_picture_struct == 7) { av_log(logctx, AV_LOG_DEBUG, "Frame/Field Doubling\n"); h->picture_struct = HEVC_SEI_PIC_STRUCT_FRAME_DOUBLING; - } else if (pic_struct == 8) { + } else if (h->hevc_picture_struct == 8) { av_log(logctx, AV_LOG_DEBUG, "Frame/Field Tripling\n"); h->picture_struct = HEVC_SEI_PIC_STRUCT_FRAME_TRIPLING; } + + h->source_scan_type = get_bits(gb, 2); + h->duplicate_flag = get_bits1(gb); } return 0; diff --git a/libavcodec/hevc/sei.h b/libavcodec/hevc/sei.h index 2fcd0e8d57..2d6e8a909c 100644 --- a/libavcodec/hevc/sei.h +++ b/libavcodec/hevc/sei.h @@ -51,7 +51,10 @@ typedef struct HEVCSEIFramePacking { } HEVCSEIFramePacking; typedef struct HEVCSEIPictureTiming { + int hevc_picture_struct; int picture_struct; + int source_scan_type; + int duplicate_flag; } HEVCSEIPictureTiming; typedef struct HEVCSEIAlternativeTransfer { -- 2.49.1 _______________________________________________ ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org