From patchwork Mon Aug 16 13:07:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 29569 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp2026074iov; Mon, 16 Aug 2021 06:07:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJylZNskazofdcckSuShKAUbSzQYEjNC8ian8EHUj6Z3dW+nz5qmlnStJ+YrbhwZK8V3Kan+ X-Received: by 2002:a17:907:105d:: with SMTP id oy29mr15974034ejb.531.1629119246667; Mon, 16 Aug 2021 06:07:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629119246; cv=none; d=google.com; s=arc-20160816; b=GKfCzbcZe8AT7jVhKLlSILyt5H72T7VA0tfhw4COjz9nn+zHgyXOy6kuMLWCF8r+mV obD14P9V5/0UIURORCcUKH6fxtzGpj0iPr10KvKXFd+ZxGIlV/5n7yUYzm7G6HBDjrXv 8kXZBpny39XrgGX7IC/0jQHyfm//xVjCFg5GQb5E5hq25yOmNBqNPmO8Lf00kr9GFvww McigyOMcdTC5oNTQMge+Db/VRchs+o5KNx/3xO6DdSlec1Km56eNIhb4M/w7ie73K/ic 7iuvFSYPTUqQ05t3LKoW8U4+hl2bddwvD2dNlz1Qxmeh1Z3tBd1ULOvvoYnsamZUuXRh GNTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=JyTe7SDbRzedUc6lXHpc/KBfV+zP3rrpevd6V+NYGdo=; b=MyC8D34ou5/GrrVkSLN9BY4yfD8Lsh1PMcLWKD2gc7y3b76tqU4w+iRDZSik1CFddw wS5BGypFBWnIWl3vwL6MhHWTfVgMuBBhz9pqrtJk4JlcjdF7WXUozLoP+B5PVxAas36/ iW+UW+uzoz+w0q/CmoSwTijup9b3bwntkjJg0UyrNTJQ1+jmK8smk6YjwVM2K0TOMTLe UGTzA9cUZf8z0v6d4/xyUSG7J0BkZUeXlQjIJKQGkLUdvYnNaWPcKHRBgphS0zO2UdWk CPIXkzktzJcM16CNGdNu802+c8jm5YFZWCH1Yt5RVtRBm8D6yepy1UW/DGcDV6ZBPqUZ W+qQ== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id s1si10071868edt.182.2021.08.16.06.07.26; Mon, 16 Aug 2021 06:07:26 -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; 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 06E1568A41C; Mon, 16 Aug 2021 16:07:23 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from nef.ens.fr (nef2.ens.fr [129.199.96.40]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3EEB96899AB for ; Mon, 16 Aug 2021 16:07:16 +0300 (EEST) X-ENS-nef-client: 129.199.129.80 ( name = phare.normalesup.org ) Received: from phare.normalesup.org (phare.normalesup.org [129.199.129.80]) by nef.ens.fr (8.14.4/1.01.28121999) with ESMTP id 17GD7FoD017518 for ; Mon, 16 Aug 2021 15:07:15 +0200 Received: by phare.normalesup.org (Postfix, from userid 1001) id 59429EB5BC; Mon, 16 Aug 2021 15:07:15 +0200 (CEST) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Mon, 16 Aug 2021 15:07:13 +0200 Message-Id: <20210816130713.28457-1-george@nsup.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (nef.ens.fr [129.199.96.32]); Mon, 16 Aug 2021 15:07:15 +0200 (CEST) Subject: [FFmpeg-devel] [PATCH] dox/examples/encode_video: add explanations in comments. 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: MHmAb0GYlVXv Signed-off-by: Nicolas George --- doc/examples/encode_video.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/doc/examples/encode_video.c b/doc/examples/encode_video.c index 908eb203d5..939ed68324 100644 --- a/doc/examples/encode_video.c +++ b/doc/examples/encode_video.c @@ -155,12 +155,25 @@ int main(int argc, char **argv) for (i = 0; i < 25; i++) { fflush(stdout); - /* make sure the frame data is writable */ + /* Make sure the frame data is writable. + On the first round, the frame is fresh from av_frame_get_buffer() + and therefore we know it is writable. + But on the next rounds, encode() will have called + avcodec_send_frame(), and the codec may have kept a reference to + the frame in its internal structures, that makes the frame + unwritable. + av_frame_make_writable() checks that and allocates a new buffer + for the frame only if necessary. + */ ret = av_frame_make_writable(frame); if (ret < 0) exit(1); - /* prepare a dummy image */ + /* Prepare a dummy image. + In real code, this is where you would have your own logic for + filling the frame. FFmpeg does not care what you put in the + frame. + */ /* Y */ for (y = 0; y < c->height; y++) { for (x = 0; x < c->width; x++) { @@ -185,7 +198,12 @@ int main(int argc, char **argv) /* flush the encoder */ encode(c, NULL, pkt, f); - /* add sequence end code to have a real MPEG file */ + /* Add sequence end code to have a real MPEG file. + It makes only sense because this tiny examples writes packets + directly. This is called "elementary stream" and only works for some + codecs. To create a valid file, you usually need to write packets + into a proper file format or protocol; see muxing.c. + */ if (codec->id == AV_CODEC_ID_MPEG1VIDEO || codec->id == AV_CODEC_ID_MPEG2VIDEO) fwrite(endcode, 1, sizeof(endcode), f); fclose(f);