From patchwork Tue Jan 14 23:42:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Gaullier X-Patchwork-Id: 17342 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 79E8544BC5B for ; Wed, 15 Jan 2020 01:42:23 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4BDDD68A8F1; Wed, 15 Jan 2020 01:42:23 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smtp-2.arkena.net (smtp-2.arkena.net [95.81.173.75]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 62E9968A57E for ; Wed, 15 Jan 2020 01:42:17 +0200 (EET) Received: from secu2 (unknown [10.180.103.10]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-2.arkena.net (Postfix) with ESMTPSA id 47y6SS3vqbzHh98; Tue, 14 Jan 2020 23:42:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=cji.paris; s=20150421; t=1579045336; bh=v/e7hu5ziSHWGzNdPREMz8wQPHLEMCYtPXsWBWD06aA=; h=From:To:Cc:Subject:Date:Message-Id; b=Dzf69QJ7mzqTku7/zRvu7E167ay+C7gqnLajgRQnmPVWyqzAQZM3USEDRwS8WATmU mc0lZsHK4VJtQ8EjHEGWKa8aZRoUt9kH69X2lgSdfjGZm5ZbDuizYGOwhabCZG93ra DbKYwBIrGzyTmHK6IAxWVL1XeO3hb5nY2hOc3/IU= Received: from arkena.com (unknown [172.16.3.159]) by secu2 (Postfix) with ESMTP id 435603FA6D; Wed, 15 Jan 2020 00:42:18 +0100 (CET) From: Nicolas Gaullier To: ffmpeg-devel@ffmpeg.org Date: Wed, 15 Jan 2020 00:42:11 +0100 Message-Id: <20200114234213.3224-2-nicolas.gaullier@cji.paris> X-Mailer: git-send-email 2.14.1.windows.1 In-Reply-To: <20200114234213.3224-1-nicolas.gaullier@cji.paris> References: <20200114234213.3224-1-nicolas.gaullier@cji.paris> Subject: [FFmpeg-devel] [PATCH v7 1/3] avformat/utils: Make find_stream_info get side data from codec context 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: Nicolas Gaullier MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This will allow probing input coded side data, and also forwarding them to the output. --- libavformat/utils.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/libavformat/utils.c b/libavformat/utils.c index f3d71642c3..cc9898681a 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -3596,6 +3596,21 @@ static int extract_extradata(AVStream *st, const AVPacket *pkt) return 0; } +static int add_coded_side_data(AVStream *st, AVCodecContext *avctx) +{ + int i; + + for (i = 0; i < avctx->nb_coded_side_data; i++) { + const AVPacketSideData *sd_src = &avctx->coded_side_data[i]; + uint8_t *dst_data; + dst_data = av_stream_new_side_data(st, sd_src->type, sd_src->size); + if (!dst_data) + return AVERROR(ENOMEM); + memcpy(dst_data, sd_src->data, sd_src->size); + } + return 0; +} + int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) { int i, count = 0, ret = 0, j; @@ -4135,6 +4150,9 @@ FF_ENABLE_DEPRECATION_WARNINGS ret = avcodec_parameters_from_context(st->codecpar, st->internal->avctx); if (ret < 0) goto find_stream_info_err; + ret = add_coded_side_data(st, st->internal->avctx); + if (ret < 0) + goto find_stream_info_err; #if FF_API_LOWRES // The decoder might reduce the video size by the lowres factor. if (st->internal->avctx->lowres && orig_w) { From patchwork Tue Jan 14 23:42:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Gaullier X-Patchwork-Id: 17344 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 7384144BC5B for ; Wed, 15 Jan 2020 01:42:25 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 636D368AC3B; Wed, 15 Jan 2020 01:42:25 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smtp-2.arkena.net (smtp-2.arkena.net [95.81.173.75]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6D87068A607 for ; Wed, 15 Jan 2020 01:42:17 +0200 (EET) Received: from secu2 (unknown [10.180.103.10]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-2.arkena.net (Postfix) with ESMTPSA id 47y6ST0lFszHh99; Tue, 14 Jan 2020 23:42:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=cji.paris; s=20150421; t=1579045337; bh=eJjfU+qpfX3wLgaD3E+Lu5fIi48o8n73kN1Q4rejqwg=; h=From:To:Cc:Subject:Date:Message-Id; b=hAqVq4id/0eLTVr+w4IZZgpM/seBiGQPsVgHDgddx5eqG5JexwwAisFOym+wODUsI qf5vkZERkjbz/QFhWrWfVsaChIUc7wVAde/4cg5UKib/Rt+aAiOSqfzIiGvbGCo8IQ urQlsRWs9fdOCzsSN9LAvI7ZfKxab9cLmXRdJ+7Y= Received: from arkena.com (unknown [172.16.3.159]) by secu2 (Postfix) with ESMTP id 9D2443FA6D; Wed, 15 Jan 2020 00:42:18 +0100 (CET) From: Nicolas Gaullier To: ffmpeg-devel@ffmpeg.org Date: Wed, 15 Jan 2020 00:42:12 +0100 Message-Id: <20200114234213.3224-3-nicolas.gaullier@cji.paris> X-Mailer: git-send-email 2.14.1.windows.1 In-Reply-To: <20200114234213.3224-1-nicolas.gaullier@cji.paris> References: <20200114234213.3224-1-nicolas.gaullier@cji.paris> Subject: [FFmpeg-devel] [PATCH v7 2/3] avcodec/utils: Fix ff_add_cpb_side_data() add twice 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: Nicolas Gaullier MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Makes it behave similarly to av_stream_add_side_data(). --- libavcodec/utils.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index ab48754a64..d9af6053bb 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -1978,6 +1978,11 @@ AVCPBProperties *ff_add_cpb_side_data(AVCodecContext *avctx) AVPacketSideData *tmp; AVCPBProperties *props; size_t size; + int i; + + for (i = 0; i < avctx->nb_coded_side_data; i++) + if (avctx->coded_side_data[i].type == AV_PKT_DATA_CPB_PROPERTIES) + return (AVCPBProperties *)avctx->coded_side_data[i].data; props = av_cpb_properties_alloc(&size); if (!props) From patchwork Tue Jan 14 23:42:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Gaullier X-Patchwork-Id: 17345 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 1F9CD44BC5B for ; Wed, 15 Jan 2020 01:42:26 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 11A7368AC2C; Wed, 15 Jan 2020 01:42:26 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smtp-2.arkena.net (smtp-2.arkena.net [95.81.173.75]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CAA2368A67D for ; Wed, 15 Jan 2020 01:42:17 +0200 (EET) Received: from secu2 (unknown [10.180.103.10]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-2.arkena.net (Postfix) with ESMTPSA id 47y6ST3HHfzHh9B; Tue, 14 Jan 2020 23:42:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=cji.paris; s=20150421; t=1579045337; bh=vtKwrSEzPPyHoydghulzTD0sWXq9FDSpHG5SumdClrM=; h=From:To:Cc:Subject:Date:Message-Id; b=A1vF79ohUUwD34ibUf3sDUEbSHeQp3U+G/6yXjG/aXcW+PX+9nQHf2qGXiNLqGunr Wv9tYbrsPKpXA/Ujrst0H2zN+WvoP9pX5vSKSUzp1cxtQrCmiEVVmpF598S8YECph9 X34W6fNmUcsdAsJrHiz591w7eahxSJ1e1ERCrs/o= Received: from arkena.com (unknown [172.16.3.159]) by secu2 (Postfix) with ESMTP id 3155C3FA6D; Wed, 15 Jan 2020 00:42:19 +0100 (CET) From: Nicolas Gaullier To: ffmpeg-devel@ffmpeg.org Date: Wed, 15 Jan 2020 00:42:13 +0100 Message-Id: <20200114234213.3224-4-nicolas.gaullier@cji.paris> X-Mailer: git-send-email 2.14.1.windows.1 In-Reply-To: <20200114234213.3224-1-nicolas.gaullier@cji.paris> References: <20200114234213.3224-1-nicolas.gaullier@cji.paris> Subject: [FFmpeg-devel] [PATCH v7 3/3] avcodec/mpeg12dec: Add CPB coded side data 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: Nicolas Gaullier MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This fixes mpeg2video stream copies to mpeg muxer like this: ffmpeg -i xdcamhd.mxf -c:v copy output.mpg --- libavcodec/mpeg12dec.c | 7 +++++++ tests/ref/fate/mxf-probe-d10 | 3 +++ tests/ref/fate/ts-demux | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c index 17f9495a1d..48ac14fafa 100644 --- a/libavcodec/mpeg12dec.c +++ b/libavcodec/mpeg12dec.c @@ -1398,6 +1398,7 @@ static void mpeg_decode_sequence_extension(Mpeg1Context *s1) MpegEncContext *s = &s1->mpeg_enc_ctx; int horiz_size_ext, vert_size_ext; int bit_rate_ext; + AVCPBProperties *cpb_props; skip_bits(&s->gb, 1); /* profile and level esc*/ s->avctx->profile = get_bits(&s->gb, 3); @@ -1429,6 +1430,12 @@ static void mpeg_decode_sequence_extension(Mpeg1Context *s1) ff_dlog(s->avctx, "sequence extension\n"); s->codec_id = s->avctx->codec_id = AV_CODEC_ID_MPEG2VIDEO; + if (cpb_props = ff_add_cpb_side_data(s->avctx)) { + cpb_props->buffer_size = FFMAX(cpb_props->buffer_size, s->avctx->rc_buffer_size); + if (s->bit_rate != 0x3FFFF*400) + cpb_props->max_bitrate = FFMAX(cpb_props->max_bitrate, s->bit_rate); + } + if (s->avctx->debug & FF_DEBUG_PICT_INFO) av_log(s->avctx, AV_LOG_DEBUG, "profile: %d, level: %d ps: %d cf:%d vbv buffer: %d, bitrate:%"PRId64"\n", diff --git a/tests/ref/fate/mxf-probe-d10 b/tests/ref/fate/mxf-probe-d10 index ab564467b5..317d4ae4c5 100644 --- a/tests/ref/fate/mxf-probe-d10 +++ b/tests/ref/fate/mxf-probe-d10 @@ -50,6 +50,9 @@ DISPOSITION:clean_effects=0 DISPOSITION:attached_pic=0 DISPOSITION:timed_thumbnails=0 TAG:file_package_umid=0x060A2B340101010501010D1313000000AE86B200913105800000080046A54011 +[SIDE_DATA] +side_data_type=CPB properties +[/SIDE_DATA] [/STREAM] [STREAM] index=1 diff --git a/tests/ref/fate/ts-demux b/tests/ref/fate/ts-demux index eb13ecc684..cdf34d6af0 100644 --- a/tests/ref/fate/ts-demux +++ b/tests/ref/fate/ts-demux @@ -15,7 +15,7 @@ 1, 5760, 5760, 2880, 1536, 0xbab5129c 1, 8640, 8640, 2880, 1536, 0x602f034b, S=1, 1, 0x00bd00bd 1, 11520, 11520, 2880, 906, 0x69cdcbcd -0, 32037, 36541, 1501, 114336, 0x37a215a8, S=1, 1, 0x00e000e0 +0, 32037, 36541, 1501, 114336, 0x37a215a8, S=2, 1, 0x00e000e0, 24, 0x663d0b52 0, 33538, 33538, 1501, 12560, 0xb559a3d4, F=0x0, S=1, 1, 0x00e000e0 0, 35040, 35040, 1501, 12704, 0x2614adf4, F=0x0, S=1, 1, 0x00e000e0 0, 36541, 41046, 1501, 51976, 0x9ff1dbfe, F=0x0, S=1, 1, 0x00e000e0