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 D8AF64ABF1 for ; Wed, 15 May 2024 11:48:55 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 656BA68D6D2; Wed, 15 May 2024 14:48:52 +0300 (EEST) Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3857268CE0E for ; Wed, 15 May 2024 14:48:46 +0300 (EEST) Received: by mail-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-572af0b12b8so1626740a12.2 for ; Wed, 15 May 2024 04:48:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715773725; x=1716378525; darn=ffmpeg.org; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=avOhV9k6pbdMf82DyZAwrc4/FlCTiQ1K2XDrtqvbPuI=; b=KSrawpQzSlvVoVsKH3mJlgQxmLXSKDv9/M72LmbovXWr5k7oEUp3NJCNKx9k7M5dLs Bx1yuO4K/pl/dvjo8o1wd3JdxDn0rRAxU+tPoWf8QrpwQ8xawcOJhGUt2HqgHTPhRImV CHDGLvt62KfofiBtNf7ybLlTTRlKsqJz3Qe2XIgHT+dXQtLIEfOEtbpUlxJZsd0NLheQ ADFK1nSFNsS9YgkXLTcrvxH0BGWgzgMzXdk8w1BR6GjzyYaznp4G3+z9bM0DM2avTi7G lhw9kJNkiXtFEEUNbTnHsZb0MhzBLHyAEt0k82pVxQpQyxRuUt76m+XT0Z6tMd+DfO3t DhtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715773725; x=1716378525; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=avOhV9k6pbdMf82DyZAwrc4/FlCTiQ1K2XDrtqvbPuI=; b=g9z/q+SBF+qVLirZHhIqhXSCW1JsLWE0UyVqzjXCNOigQ2GIIaZDRhZi8NsgeT2BCp Vjq79QICuKzcwsr+Rbe4WwVQXK92BacR87c7ZRxSb3nbotqjDqAstFD+00o+8NIbax41 4ARJAZ3HuvW0CDoJYrCb/DjremRVJLj/nwXMESPnLe7bG/l7KcQTIkRxJTQC6T1NpMAt 9ntGYoyBlfa5FYMglTIn3Z8UD4XKi2/cBgUC1Vqh6kyTPZoqVBJccHBSiyzbfYUVD1ys Xi1TpAWE4TogIQtXw7vBj45BbYfEe8l2QeBJLW8gG4DkXbZ8POFEph3225xDuTeqIjOm m6SA== X-Gm-Message-State: AOJu0YzTL8pIQLpcPPuylRuKXDwe6UDyhkkcvScn+GzrqXDwVmvpoVJa fLg2Z7VwbOd3xnmkBulkkc/ssKRCJYEgLan+Vw+vN4fDHFUY+2gJEwJspnzgZR/ckguTkgddakB tu4zFj+sefsgoi00MFhvmoaYH7gwtfi7X X-Google-Smtp-Source: AGHT+IHaTg+GUBl4FQj8f9vzSuFp0baGdA/VzfNCgopgRzgqdekzRP7RLSMi+9P1DTLeM1N8Cub24xAgDMu6X8fiqzc= X-Received: by 2002:a17:906:8315:b0:a59:a977:a154 with SMTP id a640c23a62f3a-a5a2d6786b5mr1053424566b.64.1715773724992; Wed, 15 May 2024 04:48:44 -0700 (PDT) MIME-Version: 1.0 References: <20240514113314.1821249-1-hiccupzhu@gmail.com> In-Reply-To: From: Hiccup Zhu Date: Wed, 15 May 2024 19:48:32 +0800 Message-ID: To: FFmpeg development discussions and patches Subject: Re: [FFmpeg-devel] [PATCH] avformat/pcmdec: add pts and dts calculation for pcmdec 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 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: Andreas: > > Hiccup Zhu: > > The purpose of this patch is to calculate pts and dts when using pcmdemux. > > Is there anything wrong with doing this, or do you have any suggestions for > > improvement? > > > > 1. Don't top-post on this list. > 2. PTS and DTS are already produced with this demuxer. As has been said: > If it isn't for you, open a ticket about it. This is the case. I found that when opening a pcm file, avformat_find_stream_info will keep reading pkt until the number > max_ts_probe then exit. The reason is that when demux pcm was used, valid pts and dts were not read, and sti->first_pts was never set correctly; This is unreasonable in some scenarios, because avformat_find_stream_info will consume more time to read pkt, which is especially serious in the case of network streams; You can reproduce this problem by opening any pcm file. Based on the above facts, I submitted this patch; Of course, this problem can also be fixed by solving the assignment problem of sti->first_pts, in another patch of mine: https://patchwork.ffmpeg.org/project/ffmpeg/patch/20240515113522.1921274-1-hiccupzhu@gmail.com/ - Shiqi > > > >> Shiqi Zhu: > >>> Signed-off-by: Shiqi Zhu > >>> --- > >>> libavformat/pcmdec.c | 37 +++++++++++++++++++++++++++++++++++-- > >>> 1 file changed, 35 insertions(+), 2 deletions(-) > >>> > >>> diff --git a/libavformat/pcmdec.c b/libavformat/pcmdec.c > >>> index 2f6508b75a..d879aefaad 100644 > >>> --- a/libavformat/pcmdec.c > >>> +++ b/libavformat/pcmdec.c > >>> @@ -36,6 +36,7 @@ typedef struct PCMAudioDemuxerContext { > >>> AVClass *class; > >>> int sample_rate; > >>> AVChannelLayout ch_layout; > >>> + int64_t nb_samples; > >>> } PCMAudioDemuxerContext; > >>> > >>> static int pcm_read_header(AVFormatContext *s) > >>> @@ -46,6 +47,7 @@ static int pcm_read_header(AVFormatContext *s) > >>> uint8_t *mime_type = NULL; > >>> int ret; > >>> > >>> + s1->nb_samples = 0; > >>> st = avformat_new_stream(s, NULL); > >>> if (!st) > >>> return AVERROR(ENOMEM); > >>> @@ -104,6 +106,37 @@ static int pcm_read_header(AVFormatContext *s) > >>> return 0; > >>> } > >>> > >>> +static int pcm_dec_read_packet(AVFormatContext *s, AVPacket *pkt) > >>> +{ > >>> + PCMAudioDemuxerContext *s1 = s->priv_data; > >>> + AVCodecParameters *par = s->streams[0]->codecpar; > >>> + int ret; > >>> + > >>> + ret = ff_pcm_read_packet(s, pkt); > >>> + if (ret < 0) > >>> + return ret; > >>> + > >>> + pkt->time_base = s->streams[0]->time_base; > >>> + pkt->dts = pkt->pts = s1->nb_samples; > >>> + s1->nb_samples += pkt->size / par->block_align; > >>> + > >>> + return ret; > >>> +} > >>> + > >>> +static int pcm_dec_read_seek(AVFormatContext *s, > >>> + int stream_index, int64_t timestamp, int > >> flags) > >>> +{ > >>> + PCMAudioDemuxerContext *s1 = s->priv_data; > >>> + int ret; > >>> + > >>> + ret = ff_pcm_read_seek(s, stream_index, timestamp, flags); > >>> + if (ret < 0) > >>> + return ret; > >>> + > >>> + s1->nb_samples = ffstream(s->streams[0])->cur_dts; > >>> + return ret; > >>> +} > >>> + > >>> static const AVOption pcm_options[] = { > >>> { "sample_rate", "", offsetof(PCMAudioDemuxerContext, sample_rate), > >> AV_OPT_TYPE_INT, {.i64 = 44100}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM }, > >>> { "ch_layout", "", offsetof(PCMAudioDemuxerContext, ch_layout), > >> AV_OPT_TYPE_CHLAYOUT, {.str = "mono"}, 0, 0, AV_OPT_FLAG_DECODING_PARAM }, > >>> @@ -126,8 +159,8 @@ const FFInputFormat ff_pcm_ ## name_ ## _demuxer = > >> { \ > >>> .p.priv_class = &pcm_demuxer_class, \ > >>> .priv_data_size = sizeof(PCMAudioDemuxerContext), \ > >>> .read_header = pcm_read_header, \ > >>> - .read_packet = ff_pcm_read_packet, \ > >>> - .read_seek = ff_pcm_read_seek, \ > >>> + .read_packet = pcm_dec_read_packet, \ > >>> + .read_seek = pcm_dec_read_seek, \ > >>> .raw_codec_id = codec, \ > >>> __VA_ARGS__ \ > >>> }; > >> > >> A quick test shows that PTS and DTS are already set generically for pcm > >> formats (unless the AVFMT_FLAG_NOFILLIN flag is set). If it is not in > >> your usecase, then you should provide details about this (preferably by > >> opening a ticket on trac). > >> > >> - Andreas > >> > >> _______________________________________________ > >> 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". > >> > > > > > > _______________________________________________ > 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". _______________________________________________ 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".