From patchwork Mon Feb 4 11:05:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lennart Blanco X-Patchwork-Id: 11966 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 7132B447FB8 for ; Mon, 4 Feb 2019 13:14:00 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4C77468AB11; Mon, 4 Feb 2019 13:14:00 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f173.google.com (mail-lj1-f173.google.com [209.85.208.173]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AFCD068A93D for ; Mon, 4 Feb 2019 13:13:53 +0200 (EET) Received: by mail-lj1-f173.google.com with SMTP id s5-v6so11130728ljd.12 for ; Mon, 04 Feb 2019 03:13:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=gEe9VMiHxNEjG4eSB13ZslLqvc6hut33IbRDTm0mtzo=; b=WmpJNXO7baNG0EasJEx/2e+8myOXcJTuol34b10GMEtEOSD1/UVQ1zRZ1BsT0tNhsz 6Ma7NskYgT+Y9LdzGFZQVkljNOZFZ/Q0zfPRFdxlvJDsdUL+oOXIoaTs670f8g/yhfUY x6KBjDUhp5zVN4SfT9rh6269V/TlmjMjVpemhPfGpqp73TRy55EZlj5aoVmYQm3c1385 CouURo7uYg+ZNxBL6McBISX4Ok4l/iwdHBa5nr7kHU5iWrgjVwBjARPDXSXm/HbLC/gp 1OM8HVFUaR7FfIF8Tu/xGaYI2GvErlQ39RYm1uI/JLY9NILubNP95t7mkyI4GBwb9pou 1e6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=gEe9VMiHxNEjG4eSB13ZslLqvc6hut33IbRDTm0mtzo=; b=g/wwzKdJgZ1Jky8MtD83KPywhN462vZ2uT2VTTgOoZIvL/Leo6u0p5EHT0+uYtKT08 cd/qrLHUzaAqR64YMvzeBI/0bsi6TMa6SQntR7VpDC6Fl/dKY9r6dVlMoazy/UCY716+ FJUpA0NQvmyLxJVFm9pFgZNVUKStrUZx/x+pz0rGYyGaXRdy0VgqLGEkIeKRiqC4E4Jv EcHuc1LziEmRl3e6gUlPOHfvRaK7YSAH2E+ZvxCTJg/HNHh6Cbsfv41wUk4B2Pc8UxjS 6VGhZRxO9QJWyDRjVjEIpCdMc6QdwmzN04q92291YrNfJEWN8ODu6iS16vZ6jnI/S6hu e9Kw== X-Gm-Message-State: AJcUukfq61HpUIoLZiFqq9d+B7aXF9uo6Z0KTmtsjNNLUCzMYl4ZETpA NXJG92y7KJKoJMJpKCLcpaKIJ1HNw6pnr7iL5lpVm7F7 X-Google-Smtp-Source: ALg8bN5EcZ1LwnPtm9YtrbBmdcA1suIdq5nD3TRIclFCu/FwZs7z0VbLHhgdyN9fTbELgTuk5/TyeVsGid7XaX5UPG4= X-Received: by 2002:a2e:9cd5:: with SMTP id g21-v6mr38816611ljj.48.1549278363169; Mon, 04 Feb 2019 03:06:03 -0800 (PST) MIME-Version: 1.0 From: Lennart Blanco Date: Mon, 4 Feb 2019 12:05:51 +0100 Message-ID: To: ffmpeg-devel@ffmpeg.org X-Content-Filtered-By: Mailman/MimeDel 2.1.20 Subject: [FFmpeg-devel] [PATCH] doc/examples: port muxing example to new send/receive API 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Hi Noticed that the example code for muxing uses depricated API. This is my attempt to port the doc/examples/muxing.c to use the avcodec_send_frame() and avcodec_receive_packet() API. Regards, Lennart From 2dce8373cb7adfd3228759bfa5ff80ebcd9116db Mon Sep 17 00:00:00 2001 From: Lennart Blanco Date: Wed, 30 Jan 2019 12:26:54 +0100 Subject: [PATCH] doc/examples: port muxing example to new send/receive API Replaces calls to the depricated avcodec_encode_audio2() and avcodec_encode_video2() function with calls to avcodec_send_frame()/avcodec_receive_packet() pair. Fixes the depricated warning/error while compiling muxing example. --- doc/examples/muxing.c | 76 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 52 insertions(+), 24 deletions(-) diff --git a/doc/examples/muxing.c b/doc/examples/muxing.c index 08da98e..3f3948d 100644 --- a/doc/examples/muxing.c +++ b/doc/examples/muxing.c @@ -303,7 +303,10 @@ static AVFrame *get_audio_frame(OutputStream *ost) } /* - * encode one audio frame and send it to the muxer + * send one audio frame to the encoder, + * get one encoded packet, if available, + * and send it to the muxer + * * return 1 when encoding is finished, 0 otherwise */ static int write_audio_frame(AVFormatContext *oc, OutputStream *ost) @@ -349,22 +352,34 @@ static int write_audio_frame(AVFormatContext *oc, OutputStream *ost) ost->samples_count += dst_nb_samples; } - ret = avcodec_encode_audio2(c, &pkt, frame, &got_packet); - if (ret < 0) { - fprintf(stderr, "Error encoding audio frame: %s\n", av_err2str(ret)); + ret = avcodec_send_frame(c, frame); + if (ret < 0 && ret != AVERROR_EOF) { + fprintf(stderr, "Error sending a frame for encoding %s\n", av_err2str(ret)); exit(1); } - if (got_packet) { - ret = write_frame(oc, &c->time_base, ost->st, &pkt); - if (ret < 0) { - fprintf(stderr, "Error while writing audio frame: %s\n", - av_err2str(ret)); - exit(1); - } + /* try to get encoded packet */ + ret = avcodec_receive_packet(c, &pkt); + if (ret == AVERROR(EAGAIN)) + return 0; + else if (ret == AVERROR_EOF) + /* done encoding */ + return 1; + else if (ret < 0) { + fprintf(stderr, "Error during encoding\n"); + exit(1); + } + + /* write packet package to the file */ + ret = write_frame(oc, &c->time_base, ost->st, &pkt); + if (ret < 0) { + fprintf(stderr, "Error while writing video frame: %s\n", av_err2str(ret)); + exit(1); } - return (frame || got_packet) ? 0 : 1; + av_packet_unref(&pkt); + + return 0; } /**************************************************************/ @@ -501,7 +516,10 @@ static AVFrame *get_video_frame(OutputStream *ost) } /* - * encode one video frame and send it to the muxer + * send one video frame to the encoder, + * get one encoded packet, if available, + * and send it to the muxer + * * return 1 when encoding is finished, 0 otherwise */ static int write_video_frame(AVFormatContext *oc, OutputStream *ost) @@ -514,29 +532,39 @@ static int write_video_frame(AVFormatContext *oc, OutputStream *ost) c = ost->enc; + /* send new frame to the encoder */ frame = get_video_frame(ost); + ret = avcodec_send_frame(c, frame); - av_init_packet(&pkt); - - /* encode the image */ - ret = avcodec_encode_video2(c, &pkt, frame, &got_packet); - if (ret < 0) { - fprintf(stderr, "Error encoding video frame: %s\n", av_err2str(ret)); + if (ret < 0 && ret != AVERROR_EOF) { + fprintf(stderr, "Error sending a frame for encoding %s\n", av_err2str(ret)); exit(1); } - if (got_packet) { - ret = write_frame(oc, &c->time_base, ost->st, &pkt); - } else { - ret = 0; + av_init_packet(&pkt); + + /* try to get encoded packet */ + ret = avcodec_receive_packet(c, &pkt); + if (ret == AVERROR(EAGAIN)) + return 0; + else if (ret == AVERROR_EOF) + /* done encoding */ + return 1; + else if (ret < 0) { + fprintf(stderr, "Error during encoding\n"); + exit(1); } + /* write packet package to the file */ + ret = write_frame(oc, &c->time_base, ost->st, &pkt); if (ret < 0) { fprintf(stderr, "Error while writing video frame: %s\n", av_err2str(ret)); exit(1); } - return (frame || got_packet) ? 0 : 1; + av_packet_unref(&pkt); + + return 0; } static void close_stream(AVFormatContext *oc, OutputStream *ost) -- 2.7.4