From: Hiccup Zhu <hiccupzhu@gmail.com> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Subject: Re: [FFmpeg-devel] [PATCH] avformat/pcmdec: add pts and dts calculation for pcmdec Date: Wed, 15 May 2024 19:48:32 +0800 Message-ID: <CACW1+SYM3mfuWVdW=_tNj9D5iSc+jqXkV1OtXQNiQ+xmt1KiEw@mail.gmail.com> (raw) In-Reply-To: <AS8P250MB07447DB71B59D780117C5AE28FEC2@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM> 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 <hiccupzhu@gmail.com> > >>> --- > >>> 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".
prev parent reply other threads:[~2024-05-15 11:48 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-05-14 11:33 Shiqi Zhu 2024-05-14 11:40 ` Andreas Rheinhardt 2024-05-15 1:32 ` Hiccup Zhu 2024-05-15 1:39 ` Andreas Rheinhardt 2024-05-15 11:48 ` Hiccup Zhu [this message]
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to='CACW1+SYM3mfuWVdW=_tNj9D5iSc+jqXkV1OtXQNiQ+xmt1KiEw@mail.gmail.com' \ --to=hiccupzhu@gmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git