From patchwork Mon Sep 26 17:39:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 731 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.66 with SMTP id o63csp2038598vsd; Mon, 26 Sep 2016 10:42:40 -0700 (PDT) X-Received: by 10.28.217.136 with SMTP id q130mr16700109wmg.131.1474911760702; Mon, 26 Sep 2016 10:42:40 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id y77si9474289wme.72.2016.09.26.10.42.38; Mon, 26 Sep 2016 10:42:40 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1C281689B79; Mon, 26 Sep 2016 20:42:14 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-oi0-f66.google.com (mail-oi0-f66.google.com [209.85.218.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B3272689B79 for ; Mon, 26 Sep 2016 20:42:06 +0300 (EEST) Received: by mail-oi0-f66.google.com with SMTP id a62so14037696oib.1 for ; Mon, 26 Sep 2016 10:42:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:in-reply-to:references; bh=0WcxKhZ5KlP6mUxLLO4o7Wy+XiZwHMmRujFwkBoUcDA=; b=oxSerQVmUuX3gyuZN+jcg+mGGhd+UgPImCoPizuN/h2K3Vv8ppw0KlO+GDFOMcb6tW pZN6Vf2Bk1BGepcS0k7+F/A6CRojKHr/4dd7s9bQwz6fOAU/J1BJ26KekEizCy4mPhbZ 4yLduT5ULsAUv1jPAxtraS+LzRVUzCoDLjs44cxOcVnaiEAcIOw2FL0WJi8pVNYoof8v P2LIrtTT+dhTCzLCH11V7qOnP5x6XCZ8awcZc4Rp+I1b6qyb5XZKU5uExfpoCpfsLcZH gNdHPphYrfCGrnWaI63XwxjFCHqHNRfLN0TD8xiEIlTkkRyG97UK5UO7ZHf2ImyYLa37 vZ2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=0WcxKhZ5KlP6mUxLLO4o7Wy+XiZwHMmRujFwkBoUcDA=; b=KqKL/e7VBeSxxqklXm5C5z6hvdkPYnh23qOvBcVS9QkMrUyT+B08QXN20gNy+SJLcl bV/fk/UvhyuwhAIsPvAN9LmjHgJaS3MYQ1LrdFUqjYcIwoIsgV9KQzm2U8R7ffTjBUdS MAnF3GJK8HXZTEzR51hWcxu4N4o+ZKsiY9YGGvN2yQtezCQrSEzm5ylWEPR+BDarfIQ9 FBPCZLA0Tp9hipA+2ZpmvkPWrHPKRuj/qPFErFlDvaF64n0Kz3+l6e8A77+PNai1DeDE LlkzpI4c7kYxVl6KCkPvhCg2x2131uUF7QAr5ltlock7heJ64wc1NzVeZCnGXThrIq0k VFWA== X-Gm-Message-State: AE9vXwP+toL/kkYM/KR4JsIWtqAGzfgFk+GesxCGIR5p4LDdWYKaZAEOR5Bz8oy5oL7+jw== X-Received: by 10.202.78.21 with SMTP id c21mr28165830oib.158.1474911742471; Mon, 26 Sep 2016 10:42:22 -0700 (PDT) Received: from localhost.localdomain ([181.22.11.145]) by smtp.gmail.com with ESMTPSA id 92sm2127662otg.41.2016.09.26.10.42.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 26 Sep 2016 10:42:22 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Mon, 26 Sep 2016 14:39:13 -0300 Message-Id: <20160926173913.976-2-jamrial@gmail.com> X-Mailer: git-send-email 2.9.1 In-Reply-To: <20160926173913.976-1-jamrial@gmail.com> References: <20160926173913.976-1-jamrial@gmail.com> Subject: [FFmpeg-devel] [PATCH 2/2] ffmpeg: stop using AVStream.codec on stream copy 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This commit is based on commit 35c8580 from Anton Khirnov which was skipped in b8945c4. The avcodec_copy_context() call in the encode path is left in place for now as AVStream.codec is apparently still required even after porting ffmpeg to the new bsf API. Signed-off-by: James Almer --- ffmpeg.c | 25 ++++++++++++------------- ffmpeg.h | 1 + ffmpeg_opt.c | 12 +----------- 3 files changed, 14 insertions(+), 24 deletions(-) diff --git a/ffmpeg.c b/ffmpeg.c index df55a49..bbde63b 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -516,6 +516,7 @@ static void ffmpeg_cleanup(int ret) av_dict_free(&ost->encoder_opts); av_parser_close(ost->parser); + avcodec_free_context(&ost->parser_avctx); av_freep(&ost->forced_keyframes); av_expr_free(ost->forced_keyframes_pexpr); @@ -1899,7 +1900,7 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p && ost->st->codecpar->codec_id != AV_CODEC_ID_MPEG2VIDEO && ost->st->codecpar->codec_id != AV_CODEC_ID_VC1 ) { - int ret = av_parser_change(ost->parser, ost->st->codec, + int ret = av_parser_change(ost->parser, ost->parser_avctx, &opkt.data, &opkt.size, pkt->data, pkt->size, pkt->flags & AV_PKT_FLAG_KEY); @@ -2723,9 +2724,7 @@ static int init_output_stream(OutputStream *ost, char *error, int error_len) exit_program(1); } /* - * FIXME: this is only so that the bitstream filters and parsers (that still - * work with a codec context) get the parameter values. - * This should go away with the new BSF/parser API. + * FIXME: ost->st->codec should't be needed here anymore. */ ret = avcodec_copy_context(ost->st->codec, ost->enc_ctx); if (ret < 0) @@ -2757,15 +2756,11 @@ static int init_output_stream(OutputStream *ost, char *error, int error_len) ost->st->time_base = av_add_q(ost->enc_ctx->time_base, (AVRational){0, 1}); ost->st->codec->codec= ost->enc_ctx->codec; } else if (ost->stream_copy) { - // copy timebase while removing common factors - ost->st->time_base = av_add_q(ost->st->codec->time_base, (AVRational){0, 1}); - /* - * FIXME: this is only so that the bitstream filters and parsers (that still - * work with a codec context) get the parameter values. - * This should go away with the new BSF/parser API. + * FIXME: will the codec context used by the parser during streamcopy + * This should go away with the new parser API. */ - ret = avcodec_parameters_to_context(ost->st->codec, ost->st->codecpar); + ret = avcodec_parameters_to_context(ost->parser_avctx, ost->st->codecpar); if (ret < 0) return ret; } @@ -3007,12 +3002,13 @@ static int transcode_init(void) ost->frame_rate = ist->framerate; ost->st->avg_frame_rate = ost->frame_rate; - ost->st->time_base = ist->st->time_base; - ret = avformat_transfer_internal_stream_timing_info(oc->oformat, ost->st, ist->st, copy_tb); if (ret < 0) return ret; + // copy timebase while removing common factors + ost->st->time_base = av_add_q(av_stream_get_codec_timebase(ost->st), (AVRational){0, 1}); + if (ist->st->nb_side_data) { ost->st->side_data = av_realloc_array(NULL, ist->st->nb_side_data, sizeof(*ist->st->side_data)); @@ -3038,6 +3034,9 @@ static int transcode_init(void) } ost->parser = av_parser_init(par_dst->codec_id); + ost->parser_avctx = avcodec_alloc_context3(NULL); + if (!ost->parser_avctx) + return AVERROR(ENOMEM); switch (par_dst->codec_type) { case AVMEDIA_TYPE_AUDIO: diff --git a/ffmpeg.h b/ffmpeg.h index b7f8b7a..0d01d2b 100644 --- a/ffmpeg.h +++ b/ffmpeg.h @@ -477,6 +477,7 @@ typedef struct OutputStream { int keep_pix_fmt; AVCodecParserContext *parser; + AVCodecContext *parser_avctx; /* stats */ // combined size of all the packets written diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c index 73da546..0dd06a7 100644 --- a/ffmpeg_opt.c +++ b/ffmpeg_opt.c @@ -2300,6 +2300,7 @@ loop_end: avio_read(pb, attachment, len); ost = new_attachment_stream(o, oc, -1); + ost->stream_copy = 0; ost->attachment_filename = o->attachments[i]; ost->st->codecpar->extradata = attachment; ost->st->codecpar->extradata_size = len; @@ -2309,17 +2310,6 @@ loop_end: avio_closep(&pb); } - for (i = nb_output_streams - oc->nb_streams; i < nb_output_streams; i++) { //for all streams of this output file - AVDictionaryEntry *e; - ost = output_streams[i]; - - if ((ost->stream_copy || ost->attachment_filename) - && (e = av_dict_get(o->g->codec_opts, "flags", NULL, AV_DICT_IGNORE_SUFFIX)) - && (!e->key[5] || check_stream_specifier(oc, ost->st, e->key+6))) - if (av_opt_set(ost->st->codec, "flags", e->value, 0) < 0) - exit_program(1); - } - if (!oc->nb_streams && !(oc->oformat->flags & AVFMT_NOSTREAMS)) { av_dump_format(oc, nb_output_files - 1, oc->filename, 1); av_log(NULL, AV_LOG_ERROR, "Output file #%d does not contain any stream\n", nb_output_files - 1);