From patchwork Mon Apr 4 11:30:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 35194 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c05:b0:7a:e998:b410 with SMTP id bw5csp1915486pzb; Mon, 4 Apr 2022 04:40:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxVq+AKHP2opSUdR9EXTTGaH2hzg7wNZc6s/o84Yn5NO4lJlGcmiFVbzJXaa9sV55dkGBSP X-Received: by 2002:a17:907:9493:b0:6e0:59f5:6705 with SMTP id dm19-20020a170907949300b006e059f56705mr10810889ejc.289.1649072413715; Mon, 04 Apr 2022 04:40:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649072413; cv=none; d=google.com; s=arc-20160816; b=ifiLgxJ5XdhcsbpCpx796R5ce0/zohSrZjRhHb07hR/33x5CaMgVqukvyEFrv+ZWdg 8EUHhQ4s8I2aK2lkg83+l4fKyTQHCXwyL7EDvXc7LvGmcntvTM3mKqGW75q2t7Afq6cY WPkNgCgYohjazayC83Bw4X8/JwP0TEpAPzzW+Xd+HsBli8q2drUSMMQHX4UNgcMxfShJ 2Mj5Is/WHUUtzhQFzociqZSTw5lOyr5YEfBxP50l1p8vvWMI1p6WLU40xv5o6YO1JApR iFmudbC/jyzREsFdErO5cwOgPX/lEP/OTYQ+oO5ix+Pv+cM2mMWEJo6XlKgpmk1KDFsh iMMg== 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:references:in-reply-to:message-id :date:to:from:delivered-to; bh=sFs9Yx+j73y+e+5evXXesAoWCOaH9/Do78BZufbqO9Q=; b=NYyopWXpi2T65iYKonI11gGyGnnLUbp8ypzsdxWxHwzoCkK40UEx4U+z9aNWQ006s6 bvVb6SlI46Am4JbO3CkoO3jrRUJ1rk7ckuOwLlM/6mP/j/WFrjzhlHemWIBgwi70VqOu TjRQneAwkA5Uqg0voXWZKqRBjFz5yYjaZdRHkxnXlR49d8ebiPCDnhHWYQJWrL9S3TZy CjXg1NEZqB8Wmn6Ftvceglce1KCn1vnKRD/w0JOnC3vZs+TNre4zCyhiHuyvbUZRctTd b/4S0MPEsTwgHqRMmnIl85e37h0I7+mBxDZ68q8olAjyy4cdPDEb0UUFZiouGGQJL2in Pjfg== 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 g14-20020a170906c18e00b006df76385c4dsi3042414ejz.237.2022.04.04.04.40.13; Mon, 04 Apr 2022 04:40: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; 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 3652468B382; Mon, 4 Apr 2022 14:37:57 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1356B68B34F for ; Mon, 4 Apr 2022 14:37:51 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id F0D2D24052D for ; Mon, 4 Apr 2022 13:37:47 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 5lnenK6eyWgr for ; Mon, 4 Apr 2022 13:37:47 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 066F42405F5 for ; Mon, 4 Apr 2022 13:37:42 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id 4BD9B3A0E7D; Mon, 4 Apr 2022 13:32:12 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Mon, 4 Apr 2022 13:30:34 +0200 Message-Id: <20220404113037.13070-47-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220404113037.13070-1-anton@khirnov.net> References: <20220404113037.13070-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 46/49] fftools/ffmpeg: do not write the output file header from init_output_stream() 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: 5BJ41wfovRim --- fftools/ffmpeg.c | 4 - fftools/ffmpeg.h | 2 - fftools/ffmpeg_mux.c | 186 ++++++++++++++++++++++--------------------- 3 files changed, 96 insertions(+), 96 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 0cab73ad7a..2dff41e57f 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -3230,10 +3230,6 @@ static int init_output_stream(OutputStream *ost, AVFrame *frame, ost->initialized = 1; - ret = of_check_init(output_files[ost->file_index]); - if (ret < 0) - return ret; - return ret; } diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index fef66c2325..14b98909d0 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -699,8 +699,6 @@ int hwaccel_decode_init(AVCodecContext *avctx); int of_muxer_init(OutputFile *of, AVFormatContext *fc, AVDictionary *opts, int64_t limit_filesize); -/* open the muxer when all the streams are initialized */ -int of_check_init(OutputFile *of); int of_write_trailer(OutputFile *of); void of_close(OutputFile **pof); diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 2fd131d1bc..6ca9a51dd6 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -63,6 +63,59 @@ struct Muxer { static int want_sdp = 1; +static int print_sdp(void) +{ + char sdp[16384]; + int i; + int j, ret; + AVIOContext *sdp_pb; + AVFormatContext **avc; + + for (i = 0; i < nb_output_files; i++) { + if (!output_files[i]->mux->header_written) + return 0; + } + + avc = av_malloc_array(nb_output_files, sizeof(*avc)); + if (!avc) + return AVERROR(ENOMEM); + for (i = 0, j = 0; i < nb_output_files; i++) { + if (!strcmp(output_files[i]->format->name, "rtp")) { + avc[j] = output_files[i]->mux->fc; + j++; + } + } + + if (!j) { + av_log(NULL, AV_LOG_ERROR, "No output streams in the SDP.\n"); + ret = AVERROR(EINVAL); + goto fail; + } + + ret = av_sdp_create(avc, j, sdp, sizeof(sdp)); + if (ret < 0) + goto fail; + + if (!sdp_filename) { + printf("SDP:\n%s\n", sdp); + fflush(stdout); + } else { + ret = avio_open2(&sdp_pb, sdp_filename, AVIO_FLAG_WRITE, &int_cb, NULL); + if (ret < 0) { + av_log(NULL, AV_LOG_ERROR, "Failed to open sdp file '%s'\n", sdp_filename); + goto fail; + } + + avio_print(sdp_pb, sdp); + avio_closep(&sdp_pb); + av_freep(&sdp_filename); + } + +fail: + av_freep(&avc); + return ret; +} + static int update_video_stats(OutputStream *ost, const AVPacket *pkt, int write_vstats) { const uint8_t *sd = av_packet_get_side_data(pkt, AV_PKT_DATA_QUALITY_STATS, @@ -273,92 +326,8 @@ static int submit_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost) return ret; } -int of_submit_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int eof) -{ - if (ost->sq_idx_mux >= 0) { - int ret = sq_send(of->sq_mux, ost->sq_idx_mux, - SQPKT(eof ? NULL: pkt)); - if (ret < 0) { - av_packet_unref(pkt); - if (ret == AVERROR_EOF) { - ost->finished |= MUXER_FINISHED; - return 0; - } else - return ret; - } - - while (1) { - ret = sq_receive(of->sq_mux, -1, SQPKT(pkt)); - if (ret == AVERROR_EOF || ret == AVERROR(EAGAIN)) - return 0; - else if (ret < 0) - return ret; - - ret = submit_packet(of, pkt, output_streams[of->ost_index + ret]); - if (ret < 0) - return ret; - } - } else if (!eof) - return submit_packet(of, pkt, ost); - - return 0; -} - -static int print_sdp(void) -{ - char sdp[16384]; - int i; - int j, ret; - AVIOContext *sdp_pb; - AVFormatContext **avc; - - for (i = 0; i < nb_output_files; i++) { - if (!output_files[i]->mux->header_written) - return 0; - } - - avc = av_malloc_array(nb_output_files, sizeof(*avc)); - if (!avc) - return AVERROR(ENOMEM); - for (i = 0, j = 0; i < nb_output_files; i++) { - if (!strcmp(output_files[i]->format->name, "rtp")) { - avc[j] = output_files[i]->mux->fc; - j++; - } - } - - if (!j) { - av_log(NULL, AV_LOG_ERROR, "No output streams in the SDP.\n"); - ret = AVERROR(EINVAL); - goto fail; - } - - ret = av_sdp_create(avc, j, sdp, sizeof(sdp)); - if (ret < 0) - goto fail; - - if (!sdp_filename) { - printf("SDP:\n%s\n", sdp); - fflush(stdout); - } else { - ret = avio_open2(&sdp_pb, sdp_filename, AVIO_FLAG_WRITE, &int_cb, NULL); - if (ret < 0) { - av_log(NULL, AV_LOG_ERROR, "Failed to open sdp file '%s'\n", sdp_filename); - goto fail; - } - - avio_print(sdp_pb, sdp); - avio_closep(&sdp_pb); - av_freep(&sdp_filename); - } - -fail: - av_freep(&avc); - return ret; -} - /* open the muxer when all the streams are initialized */ -int of_check_init(OutputFile *of) +static int check_write_header(OutputFile *of) { AVFormatContext *fc = of->mux->fc; int ret, i; @@ -397,10 +366,6 @@ int of_check_init(OutputFile *of) OutputStream *ost = output_streams[of->ost_index + i]; AVPacket *pkt; - /* try to improve muxing time_base (only possible if nothing has been written yet) */ - if (!av_fifo_can_read(ms->muxing_queue)) - ost->mux_timebase = ost->st->time_base; - while (av_fifo_read(ms->muxing_queue, &pkt, 1) >= 0) { ms->muxing_queue_data_size -= pkt->size; ret = write_packet(of, ost, pkt); @@ -413,6 +378,47 @@ int of_check_init(OutputFile *of) return 0; } +int of_submit_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int eof) +{ + int ret; + + if (!of->mux->header_written) { + ret = check_write_header(of); + if (ret < 0) { + av_packet_unref(pkt); + return ret; + } + } + + if (ost->sq_idx_mux >= 0) { + ret = sq_send(of->sq_mux, ost->sq_idx_mux, + SQPKT(eof ? NULL: pkt)); + if (ret < 0) { + av_packet_unref(pkt); + if (ret == AVERROR_EOF) { + ost->finished |= MUXER_FINISHED; + return 0; + } else + return ret; + } + + while (1) { + ret = sq_receive(of->sq_mux, -1, SQPKT(pkt)); + if (ret == AVERROR_EOF || ret == AVERROR(EAGAIN)) + return 0; + else if (ret < 0) + return ret; + + ret = submit_packet(of, pkt, output_streams[of->ost_index + ret]); + if (ret < 0) + return ret; + } + } else if (!eof) + return submit_packet(of, pkt, ost); + + return 0; +} + int of_write_trailer(OutputFile *of) { AVFormatContext *fc = of->mux->fc; @@ -540,7 +546,7 @@ int of_muxer_init(OutputFile *of, AVFormatContext *fc, /* write the header for files with no streams */ if (of->format->flags & AVFMT_NOSTREAMS && fc->nb_streams == 0) { - ret = of_check_init(of); + ret = check_write_header(of); if (ret < 0) goto fail; }