From patchwork Tue Dec 27 18:02:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 1947 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp1594369vsb; Tue, 27 Dec 2016 10:02:39 -0800 (PST) X-Received: by 10.194.174.229 with SMTP id bv5mr30146274wjc.21.1482861759706; Tue, 27 Dec 2016 10:02:39 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 140si47111212wmk.98.2016.12.27.10.02.34; Tue, 27 Dec 2016 10:02:39 -0800 (PST) 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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 12F2B689D6C; Tue, 27 Dec 2016 20:02:20 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from nef2.ens.fr (nef2.ens.fr [129.199.96.40]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 18D7D689937 for ; Tue, 27 Dec 2016 20:02:13 +0200 (EET) Received: from phare.normalesup.org (phare.normalesup.org [129.199.129.80]) by nef2.ens.fr (8.13.6/1.01.28121999) with ESMTP id uBRI2Fav003065 for ; Tue, 27 Dec 2016 19:02:15 +0100 (CET) Received: by phare.normalesup.org (Postfix, from userid 1001) id 47B61E00F9; Tue, 27 Dec 2016 19:02:15 +0100 (CET) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Tue, 27 Dec 2016 19:02:03 +0100 Message-Id: <20161227180210.23100-2-george@nsup.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20161227180210.23100-1-george@nsup.org> References: <20161227180210.23100-1-george@nsup.org> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (nef2.ens.fr [129.199.96.32]); Tue, 27 Dec 2016 19:02:15 +0100 (CET) Subject: [FFmpeg-devel] [PATCH 2/9] ffmpeg: use buffersink accessors. 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" Signed-off-by: Nicolas George --- ffmpeg.c | 46 ++++++++++++++++++++++++---------------------- ffmpeg_filter.c | 12 ++++++------ 2 files changed, 30 insertions(+), 28 deletions(-) Unchanged. diff --git a/ffmpeg.c b/ffmpeg.c index ec9da3e6e2..5f7699e150 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -1014,6 +1014,7 @@ static void do_video_out(OutputFile *of, AVPacket pkt; AVCodecContext *enc = ost->enc_ctx; AVCodecParameters *mux_par = ost->st->codecpar; + AVRational frame_rate; int nb_frames, nb0_frames, i; double delta, delta0; double duration = 0; @@ -1024,9 +1025,9 @@ static void do_video_out(OutputFile *of, if (ost->source_index >= 0) ist = input_streams[ost->source_index]; - if (filter->inputs[0]->frame_rate.num > 0 && - filter->inputs[0]->frame_rate.den > 0) - duration = 1/(av_q2d(filter->inputs[0]->frame_rate) * av_q2d(enc->time_base)); + frame_rate = av_buffersink_get_frame_rate(filter); + if (frame_rate.num > 0 && frame_rate.den > 0) + duration = 1/(av_q2d(frame_rate) * av_q2d(enc->time_base)); if(ist && ist->st->start_time != AV_NOPTS_VALUE && ist->st->first_dts != AV_NOPTS_VALUE && ost->frame_rate.num) duration = FFMIN(duration, 1/(av_q2d(ost->frame_rate) * av_q2d(enc->time_base))); @@ -1416,7 +1417,7 @@ static int reap_filters(int flush) av_log(NULL, AV_LOG_WARNING, "Error in av_buffersink_get_frame_flags(): %s\n", av_err2str(ret)); } else if (flush && ret == AVERROR_EOF) { - if (filter->inputs[0]->type == AVMEDIA_TYPE_VIDEO) + if (av_buffersink_get_type(filter) == AVMEDIA_TYPE_VIDEO) do_video_out(of, ost, NULL, AV_NOPTS_VALUE); } break; @@ -1427,25 +1428,26 @@ static int reap_filters(int flush) } if (filtered_frame->pts != AV_NOPTS_VALUE) { int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : of->start_time; + AVRational filter_tb = av_buffersink_get_time_base(filter); AVRational tb = enc->time_base; int extra_bits = av_clip(29 - av_log2(tb.den), 0, 16); tb.den <<= extra_bits; float_pts = - av_rescale_q(filtered_frame->pts, filter->inputs[0]->time_base, tb) - + av_rescale_q(filtered_frame->pts, filter_tb, tb) - av_rescale_q(start_time, AV_TIME_BASE_Q, tb); float_pts /= 1 << extra_bits; // avoid exact midoints to reduce the chance of rounding differences, this can be removed in case the fps code is changed to work with integers float_pts += FFSIGN(float_pts) * 1.0 / (1<<17); filtered_frame->pts = - av_rescale_q(filtered_frame->pts, filter->inputs[0]->time_base, enc->time_base) - + av_rescale_q(filtered_frame->pts, filter_tb, enc->time_base) - av_rescale_q(start_time, AV_TIME_BASE_Q, enc->time_base); } //if (ost->source_index >= 0) // *filtered_frame= *input_streams[ost->source_index]->decoded_frame; //for me_threshold - switch (filter->inputs[0]->type) { + switch (av_buffersink_get_type(filter)) { case AVMEDIA_TYPE_VIDEO: if (!ost->frame_aspect_ratio.num) enc->sample_aspect_ratio = filtered_frame->sample_aspect_ratio; @@ -3149,19 +3151,19 @@ static int init_output_stream_encode(OutputStream *ost) switch (enc_ctx->codec_type) { case AVMEDIA_TYPE_AUDIO: - enc_ctx->sample_fmt = ost->filter->filter->inputs[0]->format; + enc_ctx->sample_fmt = av_buffersink_get_format(ost->filter->filter); if (dec_ctx) enc_ctx->bits_per_raw_sample = FFMIN(dec_ctx->bits_per_raw_sample, av_get_bytes_per_sample(enc_ctx->sample_fmt) << 3); - enc_ctx->sample_rate = ost->filter->filter->inputs[0]->sample_rate; - enc_ctx->channel_layout = ost->filter->filter->inputs[0]->channel_layout; - enc_ctx->channels = avfilter_link_get_channels(ost->filter->filter->inputs[0]); + enc_ctx->sample_rate = av_buffersink_get_sample_rate(ost->filter->filter); + enc_ctx->channel_layout = av_buffersink_get_channel_layout(ost->filter->filter); + enc_ctx->channels = av_buffersink_get_channels(ost->filter->filter); enc_ctx->time_base = (AVRational){ 1, enc_ctx->sample_rate }; break; case AVMEDIA_TYPE_VIDEO: enc_ctx->time_base = av_inv_q(ost->frame_rate); if (!(enc_ctx->time_base.num && enc_ctx->time_base.den)) - enc_ctx->time_base = ost->filter->filter->inputs[0]->time_base; + enc_ctx->time_base = av_buffersink_get_time_base(ost->filter->filter); if ( av_q2d(enc_ctx->time_base) < 0.001 && video_sync_method != VSYNC_PASSTHROUGH && (video_sync_method == VSYNC_CFR || video_sync_method == VSYNC_VSCFR || (video_sync_method == VSYNC_AUTO && !(oc->oformat->flags & AVFMT_VARIABLE_FPS)))){ av_log(oc, AV_LOG_WARNING, "Frame rate very high for a muxer not efficiently supporting it.\n" @@ -3172,27 +3174,27 @@ static int init_output_stream_encode(OutputStream *ost) AV_TIME_BASE_Q, enc_ctx->time_base); - enc_ctx->width = ost->filter->filter->inputs[0]->w; - enc_ctx->height = ost->filter->filter->inputs[0]->h; + enc_ctx->width = av_buffersink_get_w(ost->filter->filter); + enc_ctx->height = av_buffersink_get_h(ost->filter->filter); enc_ctx->sample_aspect_ratio = ost->st->sample_aspect_ratio = ost->frame_aspect_ratio.num ? // overridden by the -aspect cli option av_mul_q(ost->frame_aspect_ratio, (AVRational){ enc_ctx->height, enc_ctx->width }) : - ost->filter->filter->inputs[0]->sample_aspect_ratio; + av_buffersink_get_sample_aspect_ratio(ost->filter->filter); if (!strncmp(ost->enc->name, "libx264", 7) && enc_ctx->pix_fmt == AV_PIX_FMT_NONE && - ost->filter->filter->inputs[0]->format != AV_PIX_FMT_YUV420P) + av_buffersink_get_format(ost->filter->filter) != AV_PIX_FMT_YUV420P) av_log(NULL, AV_LOG_WARNING, "No pixel format specified, %s for H.264 encoding chosen.\n" "Use -pix_fmt yuv420p for compatibility with outdated media players.\n", - av_get_pix_fmt_name(ost->filter->filter->inputs[0]->format)); + av_get_pix_fmt_name(av_buffersink_get_format(ost->filter->filter))); if (!strncmp(ost->enc->name, "mpeg2video", 10) && enc_ctx->pix_fmt == AV_PIX_FMT_NONE && - ost->filter->filter->inputs[0]->format != AV_PIX_FMT_YUV420P) + av_buffersink_get_format(ost->filter->filter) != AV_PIX_FMT_YUV420P) av_log(NULL, AV_LOG_WARNING, "No pixel format specified, %s for MPEG-2 encoding chosen.\n" "Use -pix_fmt yuv420p for compatibility with outdated media players.\n", - av_get_pix_fmt_name(ost->filter->filter->inputs[0]->format)); - enc_ctx->pix_fmt = ost->filter->filter->inputs[0]->format; + av_get_pix_fmt_name(av_buffersink_get_format(ost->filter->filter))); + enc_ctx->pix_fmt = av_buffersink_get_format(ost->filter->filter); if (dec_ctx) enc_ctx->bits_per_raw_sample = FFMIN(dec_ctx->bits_per_raw_sample, av_pix_fmt_desc_get(enc_ctx->pix_fmt)->comp[0].depth); @@ -3275,8 +3277,8 @@ static int init_output_stream(OutputStream *ost, char *error, int error_len) !av_dict_get(ost->encoder_opts, "ab", NULL, 0)) av_dict_set(&ost->encoder_opts, "b", "128000", 0); - if (ost->filter && ost->filter->filter->inputs[0]->hw_frames_ctx) { - ost->enc_ctx->hw_frames_ctx = av_buffer_ref(ost->filter->filter->inputs[0]->hw_frames_ctx); + if (ost->filter && av_buffersink_get_hw_frames_ctx(ost->filter->filter)) { + ost->enc_ctx->hw_frames_ctx = av_buffer_ref(av_buffersink_get_hw_frames_ctx(ost->filter->filter)); if (!ost->enc_ctx->hw_frames_ctx) return AVERROR(ENOMEM); } diff --git a/ffmpeg_filter.c b/ffmpeg_filter.c index 006401476e..1daca7732e 100644 --- a/ffmpeg_filter.c +++ b/ffmpeg_filter.c @@ -1079,15 +1079,15 @@ int configure_filtergraph(FilterGraph *fg) * make sure they stay the same if the filtergraph is reconfigured later */ for (i = 0; i < fg->nb_outputs; i++) { OutputFilter *ofilter = fg->outputs[i]; - AVFilterLink *link = ofilter->filter->inputs[0]; + AVFilterContext *sink = ofilter->filter; - ofilter->format = link->format; + ofilter->format = av_buffersink_get_format(sink); - ofilter->width = link->w; - ofilter->height = link->h; + ofilter->width = av_buffersink_get_w(sink); + ofilter->height = av_buffersink_get_h(sink); - ofilter->sample_rate = link->sample_rate; - ofilter->channel_layout = link->channel_layout; + ofilter->sample_rate = av_buffersink_get_sample_rate(sink); + ofilter->channel_layout = av_buffersink_get_channel_layout(sink); } fg->reconfiguration = 1;