From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 1496A47254 for ; Sat, 2 Sep 2023 15:20:14 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7A5AF68C7BA; Sat, 2 Sep 2023 18:19:45 +0300 (EEST) Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D933268C7AD for ; Sat, 2 Sep 2023 18:19:38 +0300 (EEST) Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-31adc5c899fso2689909f8f.2 for ; Sat, 02 Sep 2023 08:19:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693667977; x=1694272777; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=adnY1sCbPKu+WLPcXb47tNpPDEAqeFFPHwvAcAPULyo=; b=Au8+LPszvGg2TEvAqEUd0U6niEfp0a436o/TIfPfhZCKG3NosZX3u2tr9Y3H7pkRgh I6gQYOLCo0yKQqFfUj075liH+Qa+aF3Nf1IQuJ6sSvhIM2o2u+M31JY0NYnO+xj0Oqex 337GtDjvoxFC1oAO57pUY7fybUPgSaqk4DTR3R1Ut5cFM85G1yfWHg2PPGHM3Cfxlodn dLFG3OrjQP0nKvpxsql74sR8f1L8U/Mz0y64km+wlVuYdjtaVSpU4kHqQ8EZ7wmgSLQ3 bi1PAw0qkbJyOKodjhytuqlF2OaFFXY7inWvI2rlxZYh1HaRFrJROFZKXXdUsHTSuwUt L0jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693667977; x=1694272777; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=adnY1sCbPKu+WLPcXb47tNpPDEAqeFFPHwvAcAPULyo=; b=Q2703gnFq6cALEf3E3b0Uy91V/NCLEQDY2coD4M+muVFbkAyW5FGA33EG9U/3u4duh JNLZIv7I+0pVhLK53sLTNahOJkAvhRLBGXf/ijk7RFVRgj5KNq01i+hmsuucyt9P28Dt QyDp4iFtG7q1p+31Ms4kBlWgzFziMDl7b09G00lyFcqO6FvW4Z1DHVByf9u0E7s9hWUf MFVv2mKEWgM0wTADlY3ux+Sk6VTqyWPfrAN8mgwglv8zydeJvHA4O372bgs9eTP5B9Bt scHQtb8y89FkJ2//t7U3Wr+FZfOeJoQ5Fc2re0KNvov3lflJQmWZOCfnVsEFY23EPoBo 6RbA== X-Gm-Message-State: AOJu0Yy56exbgi+eeHk1YL8UdhVx31XFRkGfe1I1GxmGsKaxCA05pcm9 QF/EwcJCh/fxUBs8lkw3BK8tpLZ+M28= X-Google-Smtp-Source: AGHT+IFQNumhQCeTDRrP3MuQ/6djUipetDb26+w5qew3lcpMEll6K0Oe/sjEQqnGUzcSMf83LaN8wg== X-Received: by 2002:a5d:4ec1:0:b0:314:3740:7f69 with SMTP id s1-20020a5d4ec1000000b0031437407f69mr3730592wrv.37.1693667976944; Sat, 02 Sep 2023 08:19:36 -0700 (PDT) Received: from mariano ([82.84.194.139]) by smtp.gmail.com with ESMTPSA id m6-20020adfa3c6000000b0031f300a4c26sm3664679wrb.93.2023.09.02.08.19.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Sep 2023 08:19:32 -0700 (PDT) Received: by mariano (Postfix, from userid 1000) id 44CCABFCE0; Sat, 2 Sep 2023 17:19:31 +0200 (CEST) From: Stefano Sabatini To: FFmpeg development discussions and patches Date: Sat, 2 Sep 2023 17:19:13 +0200 Message-Id: <20230902151921.1712373-4-stefasab@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230902151921.1712373-1-stefasab@gmail.com> References: <20230902151921.1712373-1-stefasab@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 03/11] doc/examples/transcode: apply style fixes X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Stefano Sabatini Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --- doc/examples/transcode.c | 97 +++++++++++++++++++++------------------- 1 file changed, 50 insertions(+), 47 deletions(-) diff --git a/doc/examples/transcode.c b/doc/examples/transcode.c index ed6ac9fa03..81a88dd577 100644 --- a/doc/examples/transcode.c +++ b/doc/examples/transcode.c @@ -82,19 +82,23 @@ static int open_input_file(const char *filename) AVStream *stream = ifmt_ctx->streams[i]; const AVCodec *dec = avcodec_find_decoder(stream->codecpar->codec_id); AVCodecContext *codec_ctx; + if (!dec) { av_log(NULL, AV_LOG_ERROR, "Failed to find decoder for stream #%u\n", i); return AVERROR_DECODER_NOT_FOUND; } + codec_ctx = avcodec_alloc_context3(dec); if (!codec_ctx) { - av_log(NULL, AV_LOG_ERROR, "Failed to allocate the decoder context for stream #%u\n", i); + av_log(NULL, AV_LOG_ERROR, + "Failed to allocate the decoder context for stream #%u\n", i); return AVERROR(ENOMEM); } + ret = avcodec_parameters_to_context(codec_ctx, stream->codecpar); if (ret < 0) { - av_log(NULL, AV_LOG_ERROR, "Failed to copy decoder parameters to input decoder context " - "for stream #%u\n", i); + av_log(NULL, AV_LOG_ERROR, + "Failed to copy decoder parameters to input decoder context for stream #%u\n", i); return ret; } @@ -103,8 +107,7 @@ static int open_input_file(const char *filename) codec_ctx->pkt_timebase = stream->time_base; /* Reencode video & audio and remux subtitles etc. */ - if (codec_ctx->codec_type == AVMEDIA_TYPE_VIDEO - || codec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) { + if (codec_ctx->codec_type == AVMEDIA_TYPE_VIDEO || codec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) { if (codec_ctx->codec_type == AVMEDIA_TYPE_VIDEO) codec_ctx->framerate = av_guess_frame_rate(ifmt_ctx, stream, NULL); /* Open decoder */ @@ -141,7 +144,6 @@ static int open_output_file(const char *filename) return AVERROR_UNKNOWN; } - for (i = 0; i < ifmt_ctx->nb_streams; i++) { out_stream = avformat_new_stream(ofmt_ctx, NULL); if (!out_stream) { @@ -152,8 +154,7 @@ static int open_output_file(const char *filename) in_stream = ifmt_ctx->streams[i]; dec_ctx = stream_ctx[i].dec_ctx; - if (dec_ctx->codec_type == AVMEDIA_TYPE_VIDEO - || dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) { + if (dec_ctx->codec_type == AVMEDIA_TYPE_VIDEO || dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) { /* in this example, we choose transcoding to same codec */ encoder = avcodec_find_encoder(dec_ctx->codec_id); if (!encoder) { @@ -241,8 +242,8 @@ static int open_output_file(const char *filename) return 0; } -static int init_filter(FilteringContext* fctx, AVCodecContext *dec_ctx, - AVCodecContext *enc_ctx, const char *filter_spec) +static int init_filter(FilteringContext *fctx, AVCodecContext *dec_ctx, + AVCodecContext *enc_ctx, const char *filter_spec) { char args[512]; int ret = 0; @@ -269,29 +270,29 @@ static int init_filter(FilteringContext* fctx, AVCodecContext *dec_ctx, } snprintf(args, sizeof(args), - "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d", - dec_ctx->width, dec_ctx->height, dec_ctx->pix_fmt, - dec_ctx->pkt_timebase.num, dec_ctx->pkt_timebase.den, - dec_ctx->sample_aspect_ratio.num, - dec_ctx->sample_aspect_ratio.den); + "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d", + dec_ctx->width, dec_ctx->height, dec_ctx->pix_fmt, + dec_ctx->time_base.num, dec_ctx->time_base.den, + dec_ctx->sample_aspect_ratio.num, + dec_ctx->sample_aspect_ratio.den); ret = avfilter_graph_create_filter(&buffersrc_ctx, buffersrc, "in", - args, NULL, filter_graph); + args, NULL, filter_graph); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Cannot create buffer source\n"); goto end; } ret = avfilter_graph_create_filter(&buffersink_ctx, buffersink, "out", - NULL, NULL, filter_graph); + NULL, NULL, filter_graph); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Cannot create buffer sink\n"); goto end; } ret = av_opt_set_bin(buffersink_ctx, "pix_fmts", - (uint8_t*)&enc_ctx->pix_fmt, sizeof(enc_ctx->pix_fmt), - AV_OPT_SEARCH_CHILDREN); + (uint8_t*)&enc_ctx->pix_fmt, sizeof(enc_ctx->pix_fmt), + AV_OPT_SEARCH_CHILDREN); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Cannot set output pixel format\n"); goto end; @@ -308,45 +309,46 @@ static int init_filter(FilteringContext* fctx, AVCodecContext *dec_ctx, if (dec_ctx->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) av_channel_layout_default(&dec_ctx->ch_layout, dec_ctx->ch_layout.nb_channels); + av_channel_layout_describe(&dec_ctx->ch_layout, buf, sizeof(buf)); snprintf(args, sizeof(args), - "time_base=%d/%d:sample_rate=%d:sample_fmt=%s:channel_layout=%s", - dec_ctx->pkt_timebase.num, dec_ctx->pkt_timebase.den, dec_ctx->sample_rate, - av_get_sample_fmt_name(dec_ctx->sample_fmt), - buf); + "time_base=%d/%d:sample_rate=%d:sample_fmt=%s:channel_layout=%s", + dec_ctx->time_base.num, dec_ctx->time_base.den, dec_ctx->sample_rate, + av_get_sample_fmt_name(dec_ctx->sample_fmt), + buf); + ret = avfilter_graph_create_filter(&buffersrc_ctx, buffersrc, "in", - args, NULL, filter_graph); + args, NULL, filter_graph); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Cannot create audio buffer source\n"); goto end; } ret = avfilter_graph_create_filter(&buffersink_ctx, buffersink, "out", - NULL, NULL, filter_graph); + NULL, NULL, filter_graph); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Cannot create audio buffer sink\n"); goto end; } ret = av_opt_set_bin(buffersink_ctx, "sample_fmts", - (uint8_t*)&enc_ctx->sample_fmt, sizeof(enc_ctx->sample_fmt), - AV_OPT_SEARCH_CHILDREN); + (uint8_t*)&enc_ctx->sample_fmt, sizeof(enc_ctx->sample_fmt), + AV_OPT_SEARCH_CHILDREN); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Cannot set output sample format\n"); goto end; } av_channel_layout_describe(&enc_ctx->ch_layout, buf, sizeof(buf)); - ret = av_opt_set(buffersink_ctx, "ch_layouts", - buf, AV_OPT_SEARCH_CHILDREN); + ret = av_opt_set(buffersink_ctx, "ch_layouts", buf, AV_OPT_SEARCH_CHILDREN); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Cannot set output channel layout\n"); goto end; } ret = av_opt_set_bin(buffersink_ctx, "sample_rates", - (uint8_t*)&enc_ctx->sample_rate, sizeof(enc_ctx->sample_rate), - AV_OPT_SEARCH_CHILDREN); + (uint8_t*)&enc_ctx->sample_rate, sizeof(enc_ctx->sample_rate), + AV_OPT_SEARCH_CHILDREN); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Cannot set output sample rate\n"); goto end; @@ -373,7 +375,7 @@ static int init_filter(FilteringContext* fctx, AVCodecContext *dec_ctx, } if ((ret = avfilter_graph_parse_ptr(filter_graph, filter_spec, - &inputs, &outputs, NULL)) < 0) + &inputs, &outputs, NULL)) < 0) goto end; if ((ret = avfilter_graph_config(filter_graph, NULL)) < 0) @@ -401,20 +403,21 @@ static int init_filters(void) return AVERROR(ENOMEM); for (i = 0; i < ifmt_ctx->nb_streams; i++) { + AVStream *st = ifmt_ctx->streams[i]; filter_ctx[i].buffersrc_ctx = NULL; filter_ctx[i].buffersink_ctx = NULL; filter_ctx[i].filter_graph = NULL; - if (!(ifmt_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO - || ifmt_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)) - continue; + if (!(st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO || + st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)) + continue; - if (ifmt_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) filter_spec = "null"; /* passthrough (dummy) filter for video */ else filter_spec = "anull"; /* passthrough (dummy) filter for audio */ ret = init_filter(&filter_ctx[i], stream_ctx[i].dec_ctx, - stream_ctx[i].enc_ctx, filter_spec); + stream_ctx[i].enc_ctx, filter_spec); if (ret) return ret; @@ -477,8 +480,7 @@ static int filter_encode_write_frame(AVFrame *frame, unsigned int stream_index) av_log(NULL, AV_LOG_INFO, "Pushing decoded frame to filters\n"); /* push the decoded frame into the filtergraph */ - ret = av_buffersrc_add_frame_flags(filter->buffersrc_ctx, - frame, 0); + ret = av_buffersrc_add_frame_flags(filter->buffersrc_ctx, frame, 0); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Error while feeding the filtergraph\n"); return ret; @@ -487,8 +489,7 @@ static int filter_encode_write_frame(AVFrame *frame, unsigned int stream_index) /* pull filtered frames from the filtergraph */ while (1) { av_log(NULL, AV_LOG_INFO, "Pulling filtered frame from filters\n"); - ret = av_buffersink_get_frame(filter->buffersink_ctx, - filter->filtered_frame); + ret = av_buffersink_get_frame(filter->buffersink_ctx, filter->filtered_frame); if (ret < 0) { /* if no more frames for output - returns AVERROR(EAGAIN) * if flushed and no more frames for output - returns AVERROR_EOF @@ -499,7 +500,7 @@ static int filter_encode_write_frame(AVFrame *frame, unsigned int stream_index) break; } - filter->filtered_frame->time_base = av_buffersink_get_time_base(filter->buffersink_ctx);; + filter->filtered_frame->time_base = av_buffersink_get_time_base(filter->buffersink_ctx); filter->filtered_frame->pict_type = AV_PICTURE_TYPE_NONE; ret = encode_write_frame(stream_index, 0); av_frame_unref(filter->filtered_frame); @@ -512,8 +513,7 @@ static int filter_encode_write_frame(AVFrame *frame, unsigned int stream_index) static int flush_encoder(unsigned int stream_index) { - if (!(stream_ctx[stream_index].enc_ctx->codec->capabilities & - AV_CODEC_CAP_DELAY)) + if (!(stream_ctx[stream_index].enc_ctx->codec->capabilities & AV_CODEC_CAP_DELAY)) return 0; av_log(NULL, AV_LOG_INFO, "Flushing stream #%u encoder\n", stream_index); @@ -546,8 +546,7 @@ int main(int argc, char **argv) if ((ret = av_read_frame(ifmt_ctx, packet)) < 0) break; stream_index = packet->stream_index; - av_log(NULL, AV_LOG_DEBUG, "Demuxer gave frame of stream_index %u\n", - stream_index); + av_log(NULL, AV_LOG_DEBUG, "Demuxer gave frame of stream_index %u\n", stream_index); if (filter_ctx[stream_index].filter_graph) { StreamContext *stream = &stream_ctx[stream_index]; @@ -636,8 +635,12 @@ end: av_packet_free(&packet); for (i = 0; i < ifmt_ctx->nb_streams; i++) { avcodec_free_context(&stream_ctx[i].dec_ctx); - if (ofmt_ctx && ofmt_ctx->nb_streams > i && ofmt_ctx->streams[i] && stream_ctx[i].enc_ctx) + + if (ofmt_ctx && ofmt_ctx->nb_streams > i && + ofmt_ctx->streams[i] && + stream_ctx[i].enc_ctx) avcodec_free_context(&stream_ctx[i].enc_ctx); + if (filter_ctx && filter_ctx[i].filter_graph) { avfilter_graph_free(&filter_ctx[i].filter_graph); av_packet_free(&filter_ctx[i].enc_pkt); -- 2.34.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".