From patchwork Tue Mar 28 11:48:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Bouron X-Patchwork-Id: 3144 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.44.195 with SMTP id s186csp565180vss; Tue, 28 Mar 2017 03:48:13 -0700 (PDT) X-Received: by 10.28.209.75 with SMTP id i72mr13060740wmg.31.1490698093882; Tue, 28 Mar 2017 03:48:13 -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 f16si4233411wrf.268.2017.03.28.03.48.13; Tue, 28 Mar 2017 03:48:13 -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 sp=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 468A66898A7; Tue, 28 Mar 2017 13:47:48 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr0-f178.google.com (mail-wr0-f178.google.com [209.85.128.178]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B7171689258 for ; Tue, 28 Mar 2017 13:47:41 +0300 (EEST) Received: by mail-wr0-f178.google.com with SMTP id l43so98071918wre.1 for ; Tue, 28 Mar 2017 03:48:04 -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=3t1Of+MDhbbSJRhpwflr+rnglag+kO4WGR6jg2wHBfI=; b=WC2IQzEgks1p2WabZ3J9DRocG5yCvsvUzdPrsNUWTAvNxqU5F/R6/ZeKQ4o6PEKaCv f2l3fqNkN/0mOi4+1Bi3XiamyB5btIsdIi96YJvJpWW87XEFvDgaf1WA3h+W/YjpySIl /trAp900fJIQuFn4ULM8On32A15rCh961B/9dSiWGM+PR1Q1csY1KF6m5Ygb6dtViwQM tJ10xpcueNH/RawBm8Jxis3sgAXTCQwLTho5uPmXyxRLiVwlxmpYSfeXMh0Z7sGJyliT nKAPchgyu4+enxdL6reG3CDWjpUR+M6VsTaebElqa+Ohc5KhTUiVGKQUyFU1Qa9RQz7R /Ylw== 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=3t1Of+MDhbbSJRhpwflr+rnglag+kO4WGR6jg2wHBfI=; b=kYePaWQBNiJnHppBT5XEGE7a3c9uWy9B4OWx5aP/2Il2Yo/f02eBvv4SG3k61Vff34 zyECFfWC77Ca37fuoNBuJt5sG4nTiwL8J3EKEgdk+kvTuX1eeAqz1VhoJm2CfAUontp5 i74xVJD6sfBh768K59tYKPjh9l3VBPbO/igCnG1A2WDA0PvaLz5IPQknRMN1vBU/FVio 2JS8oJAlOQZd9+UXQNrQBMS4v87Fwu3i9IxNT73jY8UHKWopEbaonzKN3mLddN2+QPxU sproIVMTOk5iMYtaFB8AbnbG9eFFmdbI+TxZH2MCal1Rdb7P340EkSjxpG2dRtvuA9D2 HWFA== X-Gm-Message-State: AFeK/H1oshL4fcKdUgvkd0eGxTrd1rFTMrTxJasj0SrcCvtn5M5ji3kOMA3TZqYusgiuIA== X-Received: by 10.28.93.65 with SMTP id r62mr4038193wmb.77.1490698083592; Tue, 28 Mar 2017 03:48:03 -0700 (PDT) Received: from boken.gopro.lcl (LPuteaux-656-1-74-135.w80-12.abo.wanadoo.fr. [80.12.80.135]) by smtp.gmail.com with ESMTPSA id j32sm2197748wre.7.2017.03.28.03.48.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Mar 2017 03:48:03 -0700 (PDT) From: Matthieu Bouron To: ffmpeg-devel@ffmpeg.org Date: Tue, 28 Mar 2017 13:48:02 +0200 Message-Id: <20170328114802.10626-1-matthieu.bouron@gmail.com> X-Mailer: git-send-email 2.12.0 Subject: [FFmpeg-devel] [PATCH] doc/examples/extract_mvs: switch to codecpar 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: Matthieu Bouron MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" --- doc/examples/extract_mvs.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/doc/examples/extract_mvs.c b/doc/examples/extract_mvs.c index 975189c77d..09c3d32389 100644 --- a/doc/examples/extract_mvs.c +++ b/doc/examples/extract_mvs.c @@ -69,8 +69,7 @@ static int decode_packet(int *got_frame, int cached) return decoded; } -static int open_codec_context(int *stream_idx, - AVFormatContext *fmt_ctx, enum AVMediaType type) +static int open_codec_context(AVFormatContext *fmt_ctx, enum AVMediaType type) { int ret; AVStream *st; @@ -84,18 +83,29 @@ static int open_codec_context(int *stream_idx, av_get_media_type_string(type), src_filename); return ret; } else { - *stream_idx = ret; - st = fmt_ctx->streams[*stream_idx]; + int stream_idx = ret; + st = fmt_ctx->streams[stream_idx]; /* find decoder for the stream */ - dec_ctx = st->codec; - dec = avcodec_find_decoder(dec_ctx->codec_id); + dec = avcodec_find_decoder(st->codecpar->codec_id); if (!dec) { fprintf(stderr, "Failed to find %s codec\n", av_get_media_type_string(type)); return AVERROR(EINVAL); } + dec_ctx = avcodec_alloc_context3(dec); + if (!dec_ctx) { + fprintf(stderr, "Failed to allocate codec\n"); + return AVERROR(EINVAL); + } + + ret = avcodec_parameters_to_context(dec_ctx, st->codecpar); + if (ret < 0) { + fprintf(stderr, "Failed to copy codec parameters to codec context\n"); + return ret; + } + /* Init the video decoder */ av_dict_set(&opts, "flags2", "+export_mvs", 0); if ((ret = avcodec_open2(dec_ctx, dec, &opts)) < 0) { @@ -103,6 +113,10 @@ static int open_codec_context(int *stream_idx, av_get_media_type_string(type)); return ret; } + + video_stream_idx = stream_idx; + video_stream = fmt_ctx->streams[video_stream_idx]; + video_dec_ctx = dec_ctx; } return 0; @@ -130,10 +144,7 @@ int main(int argc, char **argv) exit(1); } - if (open_codec_context(&video_stream_idx, fmt_ctx, AVMEDIA_TYPE_VIDEO) >= 0) { - video_stream = fmt_ctx->streams[video_stream_idx]; - video_dec_ctx = video_stream->codec; - } + open_codec_context(fmt_ctx, AVMEDIA_TYPE_VIDEO); av_dump_format(fmt_ctx, 0, src_filename, 0); @@ -178,7 +189,7 @@ int main(int argc, char **argv) } while (got_frame); end: - avcodec_close(video_dec_ctx); + avcodec_free_context(&video_dec_ctx); avformat_close_input(&fmt_ctx); av_frame_free(&frame); return ret < 0;