From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 59EAF4D172 for ; Tue, 11 Nov 2025 03:17:20 +0000 (UTC) Authentication-Results: ffbox; dkim=fail (body hash mismatch (got b'8OinQW8i2Za8vdEsT7RUAoV7z//XIHunLA2iC0tk2ac=', expected b'90ACgcUsasFDC9+KERRPrFBD9zTUh1B9XrcrYhfJ22M=')) header.d=niedermayer.cc header.a=rsa-sha256 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1762831032; h=date : to : message-id : references : mime-version : in-reply-to : reply-to : subject : list-id : list-archive : list-archive : list-help : list-owner : list-post : list-subscribe : list-unsubscribe : from : cc : content-type : from; bh=CFtdYTjXufeHlXk28d4YMY10Ac6wZuZeU1UFK42Kyp8=; b=juePYGyEVGYB/5t2zwoyWA0lCEv7TUwkukDc9aqkdniKU0VB8iKbU5gokVRPbK96Xfk8B xgFMB8b0ie69oSt9n+PnQahhEyb0PCx4d2i4G34xDrm0yjWN4yS32Dce0JkpVz4vMQX8eBB 87SVsVBpwCwa64QZHczPuhSa2hyPG+EDTJvFAcHkQNIs0saZNBWXpM8GK9sJrUePaQyi3GZ uG//sMWtATVGmD7kK4umMxKvFRU/M/apLLFag4iFPuG1v+O9p5DR5tPoZzBcQecriEwyDAT xIcCmWcus5Raglbc5DdMUJqKIDv1K5aG5j9Q9xg3x6IyV8FVVL3ywHHVGPZA== Received: from [172.19.0.2] (unknown [172.19.0.2]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id F3DDF68FC5A; Tue, 11 Nov 2025 05:17:11 +0200 (EET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=ffmpeg.org; s=arc; t=1762831011; b=DixFzIlqSEjbPwATYKybFTET/bFqIuSEGop0Vyo35DyQe5rHx0UGrzzgU4qbKeWTxnRZA ayHA9c7ZzYpOCyDMbg6ofOJed/9RKVRAFIlHIraxEoFrt9a8O9ngNeGAMu7Z23NQEiBqc20 Fb0y15tVDsPf5VGBLscN7Ycgfc5fls8hSvjuaXPgqx9qUwhHikEiyIP1vw061bxXH9BRqTa hHbaXKxMDO7lFU0EcBemmpZOb5xJDJYxfayPeqmlp3nTGQ0ib68cGhrSYCQpcdYE7KQLMyM yZgO6KnrCh3rJJHEhe5gnk69XodzZmRg3ECqxFbn4GbetCVMc+Ly6yyCcShw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=ffmpeg.org; s=arc; t=1762831011; h=from : sender : reply-to : subject : date : message-id : to : cc : mime-version : content-type : content-transfer-encoding : content-id : content-description : resent-date : resent-from : resent-sender : resent-to : resent-cc : resent-message-id : in-reply-to : references : list-id : list-help : list-unsubscribe : list-subscribe : list-post : list-owner : list-archive; bh=8OinQW8i2Za8vdEsT7RUAoV7z//XIHunLA2iC0tk2ac=; b=MhD3/Cyd01ioxOo9j+U4JiDB75vCWT3hlJzusX15NSy4wSszBE5KHNfkFTCnGJZeHH/ro sAPA96djN2OKpE/8v79DEwkrlaTp1ShqreCC1eeq2c1OdH2oTZWw7SeZKFLM1DTMbHjvRu6 ZQkjvz40sqDk6VRAfZWz8hdL/gS3jxSD/pUD8dQMZHriOLAXz2w6+8sN7sbP577DSMNBfAf C9WxvQ4rC2Fme0o5VPdJAi2e+ZuMXAM/ibspoGRPox/b4/kL/pOklsXBHslW7fkAh/eaHe/ aJl9NXG2lFowMF/vlwM/tzYggclvRxkZoNO3E72CS+aSDM7dzBQes17wfIQA== ARC-Authentication-Results: i=1; ffmpeg.org; dkim=pass header.d=niedermayer.cc; arc=none; dmarc=none Authentication-Results: ffmpeg.org; dkim=pass header.d=niedermayer.cc; arc=none (Message is not ARC signed); dmarc=none Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 1CE6568FBC4 for ; Tue, 11 Nov 2025 05:16:37 +0200 (EET) Received: by mail.gandi.net (Postfix) with ESMTPSA id 3DDFB43B24 for ; Tue, 11 Nov 2025 03:16:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=niedermayer.cc; s=gm1; t=1762830996; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=90ACgcUsasFDC9+KERRPrFBD9zTUh1B9XrcrYhfJ22M=; b=RbKhwhZmRiT4DgAMKHcWdBI+NKJBWI8Mb7vh6h/ac3dxNC5gdBdqVA7KBxcftWONPHlfrz Fp4D8OBcH19jKcg9VvloPBbnrAN4ob26nRHth2kYPprxcH/uFSWi2Q+eHHjF6lEHWAfBP8 Twaq4DCNw6+ZcSKBDCmDhmezjimBBSgKOO9SwkmloajmQ0RZEuYSDIWhDQtiPeZBUEe6K7 nfxWm4vd6jacpHgAxQDYaTMCio2Mc9gHqd7ZSsYdSryKKCtGs06J2I4n/trAeiAI/wvLe3 /a9zoAroV/uTZOP4vSMsQCUNhX///P/L77FVQ1eH8w31w2B+5NwHHXSfwKR5+A== Date: Tue, 11 Nov 2025 04:16:35 +0100 To: FFmpeg development discussions and patches Message-ID: References: MIME-Version: 1.0 In-Reply-To: X-GND-State: clean X-GND-Score: -85 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggddvtddttdekucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenfghrlhcuvffnffculdduhedmnecujfgurhepfffhvffukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefoihgthhgrvghlucfpihgvuggvrhhmrgihvghruceomhhitghhrggvlhesnhhivgguvghrmhgrhigvrhdrtggtqeenucggtffrrghtthgvrhhnpeeigeektdejudffjefhteegjedtgeettefggedthfejgfevhfetgeekjedtvdfhveenucfkphepgedurdeiiedrieeirdehtdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeeguddrieeirdeiiedrhedtpdhhvghloheplhhotggrlhhhohhsthdpmhgrihhlfhhrohhmpehmihgthhgrvghlsehnihgvuggvrhhmrgihvghrrdgttgdpnhgspghrtghpthhtohepuddprhgtphhtthhopehffhhmphgvghdquggvvhgvlhesfhhfmhhpvghgrdhorhhg X-GND-Sasl: michael@niedermayer.cc Message-ID-Hash: VQDGHG7TLQS3HB73ZTBLSFD6E4E4JS33 X-Message-ID-Hash: VQDGHG7TLQS3HB73ZTBLSFD6E4E4JS33 X-MailFrom: SRS0=X2QP=5T=niedermayer.cc=michael@ffmpeg.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-ffmpeg-devel.ffmpeg.org-0; header-match-ffmpeg-devel.ffmpeg.org-1; header-match-ffmpeg-devel.ffmpeg.org-2; header-match-ffmpeg-devel.ffmpeg.org-3; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list Reply-To: FFmpeg development discussions and patches Subject: [FFmpeg-devel] Re: [PATCH] avformat/mpjpegdec: add support for X-Timestamp and X-Framerate headers List-Id: FFmpeg development discussions and patches Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Michael Niedermayer via ffmpeg-devel Cc: Michael Niedermayer Content-Type: multipart/mixed; boundary="===============6569076724916390555==" Archived-At: List-Archive: List-Post: --===============6569076724916390555== Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="v/M67xqNlaCp7C7I" Content-Disposition: inline --v/M67xqNlaCp7C7I Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi Vladimir On Sun, Nov 09, 2025 at 02:38:56AM +0200, Vladimir Sobolev via ffmpeg-devel= wrote: > >From 31d73c6774c1ea6d621db57f26439e297cc23c3d Mon Sep 17 00:00:00 2001 > From: Vladimir Sobolev > Date: Sun, 9 Nov 2025 02:28:13 +0200 > Subject: [PATCH] avformat/mpjpegdec: add support for X-Timestamp and > X-Framerate headers >=20 > Add support for parsing X-Timestamp and X-Framerate headers from > HTTP multipart MJPEG streams. These headers allow servers to provide > accurate timestamps and framerate information for each frame. >=20 > Changes: > - Parse X-Timestamp header (in seconds) and set packet PTS/DTS > - Parse X-Framerate/X-FrameRate header and update stream framerate > - Maintain backward compatibility (defaults to 25 fps if not provided) > - Add debug logging for parsed header values >=20 > This enables proper timestamp handling for MJPEG streams that provide > timing information in HTTP headers, improving synchronization accuracy. > --- > libavformat/mpjpegdec.c | 69 ++++++++++++++++++++++++++++++++++++++--- > 1 file changed, 65 insertions(+), 4 deletions(-) >=20 > diff --git a/libavformat/mpjpegdec.c b/libavformat/mpjpegdec.c > index 125b17585e..c90d7a2ad4 100644 > --- a/libavformat/mpjpegdec.c > +++ b/libavformat/mpjpegdec.c > @@ -22,6 +22,9 @@ > #include "libavutil/avstring.h" > #include "libavutil/mem.h" > #include "libavutil/opt.h" > +#include "libavutil/parseutils.h" > +#include "libavutil/eval.h" > +#include "libavutil/intfloat.h" > =20 > #include "avformat.h" > #include "demux.h" > @@ -34,6 +37,11 @@ typedef struct MPJPEGDemuxContext { > char *searchstr; > int searchstr_len; > int strict_mime_boundary; > + AVRational framerate; /* framerate from X-Framerate header */ > + int64_t timestamp; /* timestamp from X-Timestamp header */ > + int has_timestamp; /* flag indicating if timestamp was set = */ > + int framerate_set; /* flag indicating if framerate was set i= n header */ > + int framerate_applied; /* flag indicating if framerate was a= pplied to stream */ > } MPJPEGDemuxContext; > =20 > static void trim_right(char *p) > @@ -97,7 +105,8 @@ static int split_tag_value(char **tag, char **value, c= har *line) > static int parse_multipart_header(AVIOContext *pb, > int* size, > const char* expected_boundary, > - void *log_ctx); > + void *log_ctx, > + MPJPEGDemuxContext *mpjpeg); > =20 > static int mpjpeg_read_close(AVFormatContext *s) > { > @@ -118,7 +127,7 @@ static int mpjpeg_read_probe(const AVProbeData *p) > =20 > ffio_init_read_context(&pb, p->buf, p->buf_size); > =20 > - ret =3D (parse_multipart_header(&pb.pub, &size, "--", NULL) >=3D 0) = ? AVPROBE_SCORE_MAX : 0; > + ret =3D (parse_multipart_header(&pb.pub, &size, "--", NULL, NULL) >= =3D 0) ? AVPROBE_SCORE_MAX : 0; > =20 > return ret; > } > @@ -146,6 +155,12 @@ static int mpjpeg_read_header(AVFormatContext *s) > st->codecpar->codec_type =3D AVMEDIA_TYPE_VIDEO; > st->codecpar->codec_id =3D AV_CODEC_ID_MJPEG; > =20 > + /* Default framerate is 25 fps, will be updated from headers if avai= lable */ > + MPJPEGDemuxContext *mpjpeg =3D s->priv_data; > + mpjpeg->framerate =3D (AVRational){25, 1}; > + mpjpeg->framerate_set =3D 0; > + mpjpeg->framerate_applied =3D 0; > + mpjpeg->has_timestamp =3D 0; > avpriv_set_pts_info(st, 60, 1, 25); > =20 > avio_seek(s->pb, pos, SEEK_SET); > @@ -167,7 +182,8 @@ static int parse_content_length(const char *value) > static int parse_multipart_header(AVIOContext *pb, > int* size, > const char* expected_boundary, > - void *log_ctx) > + void *log_ctx, > + MPJPEGDemuxContext *mpjpeg) > { > char line[128]; > int found_content_type =3D 0; > @@ -235,6 +251,33 @@ static int parse_multipart_header(AVIOContext *pb, > av_log(log_ctx, AV_LOG_WARNING, > "Invalid Content-Length value : %s\n", > value); > + } else if (mpjpeg && !av_strcasecmp(tag, "X-Timestamp")) { > + double ts =3D av_strtod(value, NULL); > + if (!isnan(ts) && isfinite(ts)) { nan is not finite > + /* X-Timestamp is in seconds, convert to AV_TIME_BASE */ > + mpjpeg->timestamp =3D (int64_t)(ts * AV_TIME_BASE); > + mpjpeg->has_timestamp =3D 1; > + if (log_ctx) > + av_log(log_ctx, AV_LOG_DEBUG, > + "Parsed X-Timestamp: %s -> %"PRId64" (%.6f se= conds)\n", > + value, mpjpeg->timestamp, ts); > + } else if (log_ctx) { > + av_log(log_ctx, AV_LOG_WARNING, > + "Invalid X-Timestamp value : %s\n", value); > + } > + } else if (mpjpeg && (!av_strcasecmp(tag, "X-Framerate") || !av_= strcasecmp(tag, "X-FrameRate"))) { > + AVRational fps =3D {0}; > + if (av_parse_video_rate(&fps, value) >=3D 0 && fps.num > 0 &= & fps.den > 0) { > + mpjpeg->framerate =3D fps; > + mpjpeg->framerate_set =3D 1; > + if (log_ctx) > + av_log(log_ctx, AV_LOG_DEBUG, > + "Parsed X-Framerate: %s -> %d/%d fps\n", > + value, fps.num, fps.den); > + } else if (log_ctx) { > + av_log(log_ctx, AV_LOG_WARNING, > + "Invalid X-Framerate value : %s\n", value); > + } all the if(log_ctx) looks wierd i dont think log_ctx is ever NULL in this c= ode thats under if(mpjpeg) > } > } > =20 > @@ -311,10 +354,21 @@ static int mpjpeg_read_packet(AVFormatContext *s, A= VPacket *pkt) > mpjpeg->searchstr_len =3D strlen(mpjpeg->searchstr); > } > =20 > - ret =3D parse_multipart_header(s->pb, &size, mpjpeg->boundary, s); > + /* Reset timestamp flag for each packet */ > + mpjpeg->has_timestamp =3D 0; > + > + ret =3D parse_multipart_header(s->pb, &size, mpjpeg->boundary, s, mp= jpeg); > if (ret < 0) > return ret; > =20 > + /* Update framerate if it was set in header and hasn't been applied = yet */ > + if (mpjpeg->framerate_set && !mpjpeg->framerate_applied && s->nb_str= eams > 0) { > + AVStream *st =3D s->streams[0]; > + st->avg_frame_rate =3D mpjpeg->framerate; > + avpriv_set_pts_info(st, 60, mpjpeg->framerate.den, mpjpeg->frame= rate.num); > + mpjpeg->framerate_applied =3D 1; > + } this looks wrong * you should not set the timebase more than once. it was already set to 1/25 * the average framerate can only match the 1/timebase for "constant fps" which is the opposit of what this patch is trying to do > + > if (size > 0) { > /* size has been provided to us in MIME header */ > ret =3D av_get_packet(s->pb, pkt, size); > @@ -353,6 +407,13 @@ static int mpjpeg_read_packet(AVFormatContext *s, AV= Packet *pkt) > } > } > =20 > + /* Set timestamp from X-Timestamp header if available */ > + if (ret >=3D 0 && mpjpeg->has_timestamp && s->nb_streams > 0) { > + AVStream *st =3D s->streams[0]; > + pkt->pts =3D av_rescale_q(mpjpeg->timestamp, AV_TIME_BASE_Q, st-= >time_base); rescaling timestamps suggests you set the timebase wrong thx [...] --=20 Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB What does censorship reveal? It reveals fear. -- Julian Assange --v/M67xqNlaCp7C7I Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABEKAB0WIQSf8hKLFH72cwut8TNhHseHBAsPqwUCaRKqkAAKCRBhHseHBAsP q99WAJ0evJxKX+5KEv9QoL36pj8TkZuSpwCgiq5KOf40rwxEj+D6to48yEOdqbg= =LO56 -----END PGP SIGNATURE----- --v/M67xqNlaCp7C7I-- --===============6569076724916390555== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org --===============6569076724916390555==--