From patchwork Mon Jun 15 14:27:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 20419 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 9280B449931 for ; Mon, 15 Jun 2020 17:27:30 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 713DB68B566; Mon, 15 Jun 2020 17:27:30 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A3ACD68B282 for ; Mon, 15 Jun 2020 17:27:23 +0300 (EEST) Received: by mail-pg1-f194.google.com with SMTP id v14so2673726pgl.1 for ; Mon, 15 Jun 2020 07:27:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=C7xGZnJbAo6cDMsgmXXOjMI/rznChN1lu6dW3RZjFPo=; b=b46DGZzaxBtDdD/FB/4QjIJsXRgMc8I6DPNUWOIe9iqRAIQp8dtAjoXHTwVlZC5SXU zymTf05aYWOEXA93shCKWy4S6DnD5es2TEVSQu216oe7cbEN25XkFQYtcFHfwdWYnfI8 43gDcb/YD9MoDlfie+cnHcQ0ZVQyqSLNvr4qq4BOOxvAaKbAcXURTSfAd4m39Zj//HxO PsWY1TDAxQhR2hLt96+DGCszw69LxcHTF4KcreRXYFyBIYjXwdnlL3WPiZpm126rlErB JBBuRZ8Opw2kYvIx7BxBVMEIDWmgMenzEprdNNvURfGON+HEAT3MbOOaCBI1uHBEby0z 9SYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=C7xGZnJbAo6cDMsgmXXOjMI/rznChN1lu6dW3RZjFPo=; b=lY04DRWnQ9YHgLu+JgaM3Hwb5GKaqJpbnSr8mdMshMJ4BmgPOgptxbOLU8zVePbeWl yEnyg8mFoBgzl2aXr7l19dEQRROyiBZGrmjmro9XwKv0DtTIbwpZXHxsf/2HPx9dvsR5 kodNjpIgyD7IHJYBJUBjBz7vx3Q5S15dB3uGoZjjuJOmCHgky+F7i0WsVmItkAyNQbqg 3GvKwldfVXD7A+SEMeDZB149JjeyPGiP7L4DkVaKULDtgSwY8sbVDxpfdaHPfktfzRbC fB9QgwuWBJaBXgZn79gHEfi12B+KUu+w6oasYDzvIiCfvPkn+stU2AVpljUuNLSLbax3 zSBQ== X-Gm-Message-State: AOAM5339q1kE7S8+0+aJV+deZ0AerrV1Bz6mqahAp8G7LO9U5FA8gAsb p8i5A1v6gUCx2lUAnm9ZIQRix+yP X-Google-Smtp-Source: ABdhPJxtbFq8mjPMTb9E47f+ykEr6ih4OEXYFXQ+1IxrDlDbojTx1ERBU/eLe5TzeIuGnhlkyxjUcQ== X-Received: by 2002:a63:b506:: with SMTP id y6mr21278593pge.107.1592231241529; Mon, 15 Jun 2020 07:27:21 -0700 (PDT) Received: from vpn2.localdomain ([161.117.202.209]) by smtp.gmail.com with ESMTPSA id u61sm13437547pjb.7.2020.06.15.07.27.19 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Jun 2020 07:27:20 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Mon, 15 Jun 2020 22:27:13 +0800 Message-Id: <1592231234-6049-1-git-send-email-lance.lmwang@gmail.com> X-Mailer: git-send-email 1.8.3.1 Subject: [FFmpeg-devel] [PATCH 1/2] avcodec/hevc_sei: support HEVC timecode decode X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Limin Wang MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Limin Wang Signed-off-by: Limin Wang --- libavcodec/hevc_sei.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ libavcodec/hevc_sei.h | 21 +++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c index 1736891..6d484b5 100644 --- a/libavcodec/hevc_sei.c +++ b/libavcodec/hevc_sei.c @@ -306,6 +306,53 @@ static int decode_nal_sei_alternative_transfer(HEVCSEIAlternativeTransfer *s, Ge return 0; } +static int decode_nal_sei_timecode(HEVCSEITimeCode *s, GetBitContext *gb) +{ + s->num_clock_ts = get_bits(gb, 2) & 3; + + for (int i = 0; i < s->num_clock_ts; i++) { + s->clock_timestamp_flag[i] = get_bits(gb, 1); + + if (s->clock_timestamp_flag[i]) { + s->units_field_based_flag[i] = get_bits(gb, 1); + s->counting_type[i] = get_bits(gb, 5); + s->full_timestamp_flag[i] = get_bits(gb, 1); + s->discontinuity_flag[i] = get_bits(gb, 1); + s->cnt_dropped_flag[i] = get_bits(gb, 1); + + s->n_frames[i] = get_bits(gb, 9); + + if (s->full_timestamp_flag[i]) { + s->seconds_value[i] = av_clip(get_bits(gb, 6), 0, 59); + s->minutes_value[i] = av_clip(get_bits(gb, 6), 0, 59); + s->hours_value[i] = av_clip(get_bits(gb, 6), 0, 59); + } else { + s->seconds_flag[i] = get_bits(gb, 1); + if (s->seconds_flag[i]) { + s->seconds_value[i] = av_clip(get_bits(gb, 6), 0, 59); + s->minutes_flag[i] = get_bits(gb, 1); + if (s->minutes_flag[i]) { + s->minutes_value[i] = av_clip(get_bits(gb, 6), 0, 59); + s->hours_flag[i] = get_bits(gb, 1); + if (s->hours_flag[i]) { + s->hours_value[i] = av_clip(get_bits(gb, 6), 0, 59); + } + } + } + } + + s->time_offset_length[i] = get_bits(gb, 5); + if (s->time_offset_length[i] > 0) { + s->time_offset_value[i] = get_bits(gb, s->time_offset_length[i]); + } + } + } + + s->present = 1; + return 0; +} + + static int decode_nal_sei_prefix(GetBitContext *gb, void *logctx, HEVCSEI *s, const HEVCParamSets *ps, int type, int size) { @@ -330,6 +377,8 @@ static int decode_nal_sei_prefix(GetBitContext *gb, void *logctx, HEVCSEI *s, return decode_nal_sei_user_data_unregistered(&s->unregistered, gb, size); case HEVC_SEI_TYPE_ALTERNATIVE_TRANSFER_CHARACTERISTICS: return decode_nal_sei_alternative_transfer(&s->alternative_transfer, gb); + case HEVC_SEI_TYPE_TIME_CODE: + return decode_nal_sei_timecode(&s->timecode, gb); default: av_log(logctx, AV_LOG_DEBUG, "Skipped PREFIX SEI %d\n", type); skip_bits_long(gb, 8 * size); diff --git a/libavcodec/hevc_sei.h b/libavcodec/hevc_sei.h index 3618d16..5ee7a47 100644 --- a/libavcodec/hevc_sei.h +++ b/libavcodec/hevc_sei.h @@ -115,6 +115,26 @@ typedef struct HEVCSEIAlternativeTransfer { int preferred_transfer_characteristics; } HEVCSEIAlternativeTransfer; +typedef struct HEVCSEITimeCode { + int present; + uint8_t num_clock_ts; + uint8_t clock_timestamp_flag[3]; + uint8_t units_field_based_flag[3]; + uint8_t counting_type[3]; + uint8_t full_timestamp_flag[3]; + uint8_t discontinuity_flag[3]; + uint8_t cnt_dropped_flag[3]; + uint16_t n_frames[3]; + uint8_t seconds_value[3]; + uint8_t minutes_value[3]; + uint8_t hours_value[3]; + uint8_t seconds_flag[3]; + uint8_t minutes_flag[3]; + uint8_t hours_flag[3]; + uint8_t time_offset_length[3]; + int32_t time_offset_value[3]; +} HEVCSEITimeCode; + typedef struct HEVCSEI { HEVCSEIPictureHash picture_hash; HEVCSEIFramePacking frame_packing; @@ -126,6 +146,7 @@ typedef struct HEVCSEI { HEVCSEIContentLight content_light; int active_seq_parameter_set_id; HEVCSEIAlternativeTransfer alternative_transfer; + HEVCSEITimeCode timecode; } HEVCSEI; struct HEVCParamSets; From patchwork Mon Jun 15 14:27:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 20420 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 7AE57449931 for ; Mon, 15 Jun 2020 17:27:32 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5E1DA68B5D8; Mon, 15 Jun 2020 17:27:32 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 570FC68B4FB for ; Mon, 15 Jun 2020 17:27:26 +0300 (EEST) Received: by mail-pf1-f193.google.com with SMTP id z63so6962885pfb.1 for ; Mon, 15 Jun 2020 07:27:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=T8JZKVWzRakP5nfC6PNqfo08HorKUHaX2wCeEg4S4nE=; b=jQYetOOLLqEJEHDEySpt/Okut5DPlaHrf5zFcyhjWIJxQ3Cmnwk60HyFoQqPaooUQQ WLpBI2yxIjRqdNGiqi/TpkUx389c56IO1KKsRfiGA2dlEO358pt05YmY9t34p2Go7cmI KVJ7938qdprDvYYmRj07P/yXgpoLIWJ8DoxL2rFjzntEnttjmpYRoNH5SXmbHupn0pND ktA3O063ht9OQfwzzFZKaoixhLV2se/gI91FdADvFAlfqnQtAIwCJNcXMF5DuGmo71Ny 2p6x60BLOJGk1anr0AUsdLgdtMAgapExvB03JogPx1swlF0XmAP5V53445Zbv15VlPN4 8NRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=T8JZKVWzRakP5nfC6PNqfo08HorKUHaX2wCeEg4S4nE=; b=C/ynB3CamL9MifgjLExLZgJRG4V4/Ql7veEWJioLV7Vx4TxcPL4flBw7Vj5XkeF2A3 MvuzgeVdRAeh/l0hi0kxeRi6ivvWOwu+ViYz4Ii/gZR+NhUHqtjPiGUSqU5dQlvNhSFF 74NbhlUmPMqBpwrwIK+qs8wtOx21UscvxB9zDTVKDT+xOe9+3n3Ajpm8ojmXyWwku++G VEyr1oCKHIdh04q6xOtNtd+v8gcoc6r/O6JmZgCCtOynjpYRf6Mdp3OXJFAGMI+nIjI2 +n9I+ecD+hJz5fb3IvxGWkCUaGNmHFkvRCLV25nxfnUR2D+jkLZ86hAZ4naCN2eLtqO3 qBgg== X-Gm-Message-State: AOAM531JsuoMfsBG2jzOQqrrthMIvG/CiN58zidYNFOxO9atJBdHHBWK GGf2o+yxB7+h6IiCzdwrcdfHYiHg X-Google-Smtp-Source: ABdhPJzhnDOk1x18p/4dFy6E5Lj2dYYtqzFVpYEVQ1KrMeMjHkq/lHVx3mqDd7+g9LA5czOKDP3VzA== X-Received: by 2002:aa7:9093:: with SMTP id i19mr22738320pfa.152.1592231244280; Mon, 15 Jun 2020 07:27:24 -0700 (PDT) Received: from vpn2.localdomain ([161.117.202.209]) by smtp.gmail.com with ESMTPSA id u61sm13437547pjb.7.2020.06.15.07.27.22 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Jun 2020 07:27:23 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Mon, 15 Jun 2020 22:27:14 +0800 Message-Id: <1592231234-6049-2-git-send-email-lance.lmwang@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1592231234-6049-1-git-send-email-lance.lmwang@gmail.com> References: <1592231234-6049-1-git-send-email-lance.lmwang@gmail.com> Subject: [FFmpeg-devel] [PATCH 2/2] avcodec/hevcdec: create AVFrame side data from HEVC timecodes like H.264 X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Limin Wang MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Limin Wang Signed-off-by: Limin Wang --- libavcodec/hevcdec.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c index c9e28f5..39abbb9 100644 --- a/libavcodec/hevcdec.c +++ b/libavcodec/hevcdec.c @@ -2808,6 +2808,50 @@ static int set_side_data(HEVCContext *s) } s->sei.unregistered.nb_buf_ref = 0; + if (s->sei.timecode.present) { + uint32_t tc = 0; + uint32_t *tc_sd; + AVFrameSideData *tcside = av_frame_new_side_data(out, AV_FRAME_DATA_S12M_TIMECODE, + sizeof(uint32_t) * 4); + if (!tcside) + return AVERROR(ENOMEM); + + tc_sd = (uint32_t*)tcside->data; + tc_sd[0] = s->sei.timecode.num_clock_ts; + + for (int i = 0; i < tc_sd[0]; i++) { + uint32_t frames; + + /* For SMPTE 12-M timecodes, frame count is a special case if > 30 FPS. + See SMPTE ST 12-1:2014 Sec 12.1 for more info. */ + if (av_cmp_q(s->avctx->framerate, (AVRational) {30, 1}) == 1) { + frames = s->sei.timecode.n_frames[i] / 2; + if (s->sei.timecode.n_frames[i] % 2 == 1) { + if (av_cmp_q(s->avctx->framerate, (AVRational) {50, 1}) == 0) + tc |= (1 << 7); + else + tc |= (1 << 23); + } + } else { + frames = s->sei.timecode.n_frames[i]; + } + + tc |= s->sei.timecode.cnt_dropped_flag[i] << 30; + tc |= (frames / 10) << 28; + tc |= (frames % 10) << 24; + tc |= (s->sei.timecode.seconds_value[i] / 10) << 20; + tc |= (s->sei.timecode.seconds_value[i] % 10) << 16; + tc |= (s->sei.timecode.minutes_value[i] / 10) << 12; + tc |= (s->sei.timecode.minutes_value[i] % 10) << 8; + tc |= (s->sei.timecode.hours_value[i] / 10) << 4; + tc |= (s->sei.timecode.hours_value[i] % 10); + + tc_sd[i + 1] = tc; + } + + s->sei.timecode.num_clock_ts = 0; + } + return 0; }