From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <ffmpeg-devel-bounces@ffmpeg.org>
Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100])
	by master.gitmailbox.com (Postfix) with ESMTP id B1E3648BE9
	for <ffmpegdev@gitmailbox.com>; Wed, 10 Jan 2024 02:56:48 +0000 (UTC)
Received: from [127.0.1.1] (localhost [127.0.0.1])
	by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9EE8168CE0C;
	Wed, 10 Jan 2024 04:56:47 +0200 (EET)
Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net
 [217.70.183.195])
 by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C961068CCF6
 for <ffmpeg-devel@ffmpeg.org>; Wed, 10 Jan 2024 04:56:40 +0200 (EET)
Received: by mail.gandi.net (Postfix) with ESMTPSA id 1474D60002
 for <ffmpeg-devel@ffmpeg.org>; Wed, 10 Jan 2024 02:56:39 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=niedermayer.cc;
 s=gm1; t=1704855400;
 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=zxIm7E/N3NWsifPXJndg/kHXxqVwJegCwcoZmxEVhi4=;
 b=AOuHzrePDfzWTlS7RtVT6yaXtDKEy8ZKVb26cPs/tmXdY5Q7pQ/Kf2UHULCuzB1SwOroQI
 dhkyOAASsTCr4FUO5DBb9SCqDD5CXysfS/brjB0kri5yr1JjPjNLReoFElMbonuwHpjhFE
 2mR3Dn78sH/Gzxc682a5UwPXzD3ppglmlnMvJLCStugjrG4EE1RjRtsGrpgQNvtDg2SW9E
 O54lR9C2HTJOzAmrkq3nROfY98xSVMRjUG02S3IUHQsHbiDrbP+a6bc06imEQ8lr8D8Npr
 hzg9B6qcla1BjUzTE6I6aFjlBP0lgH8z7R1ksDJLQI4oqY+5Pid0+jch6NoQYw==
Date: Wed, 10 Jan 2024 03:56:39 +0100
From: Michael Niedermayer <michael@niedermayer.cc>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Message-ID: <20240110025639.GR6420@pb2>
References: <PAVPR08MB97956CA2AC0B6F2A803A90439A61A@PAVPR08MB9795.eurprd08.prod.outlook.com>
MIME-Version: 1.0
In-Reply-To: <PAVPR08MB97956CA2AC0B6F2A803A90439A61A@PAVPR08MB9795.eurprd08.prod.outlook.com>
X-GND-Sasl: michael@niedermayer.cc
Subject: Re: [FFmpeg-devel] [PATCH 4/4] avformat/psxstr: basic FPS detection
 instead of fixed value
X-BeenThere: ffmpeg-devel@ffmpeg.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: FFmpeg development discussions and patches <ffmpeg-devel.ffmpeg.org>
List-Unsubscribe: <https://ffmpeg.org/mailman/options/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=unsubscribe>
List-Archive: <https://ffmpeg.org/pipermail/ffmpeg-devel>
List-Post: <mailto:ffmpeg-devel@ffmpeg.org>
List-Help: <mailto:ffmpeg-devel-request@ffmpeg.org?subject=help>
List-Subscribe: <https://ffmpeg.org/mailman/listinfo/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=subscribe>
Reply-To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Content-Type: multipart/mixed; boundary="===============0159450469367431301=="
Errors-To: ffmpeg-devel-bounces@ffmpeg.org
Sender: "ffmpeg-devel" <ffmpeg-devel-bounces@ffmpeg.org>
Archived-At: <https://master.gitmailbox.com/ffmpegdev/20240110025639.GR6420@pb2/>
List-Archive: <https://master.gitmailbox.com/ffmpegdev/>
List-Post: <mailto:ffmpegdev@gitmailbox.com>


--===============0159450469367431301==
Content-Type: multipart/signed; micalg=pgp-sha256;
	protocol="application/pgp-signature"; boundary="lGE/lu55aVFaufSH"
Content-Disposition: inline


--lGE/lu55aVFaufSH
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Tue, Jan 02, 2024 at 03:14:19AM +0000, aybe aybe wrote:
> This fourth and last patch is an attempt at removing the hard-coded value=
 of 15 FPS.
>=20
> In patch 1/4, although it would render video, the audio and video were no=
t synchronized at all, now there are.
>=20
> In this approach I kept it simple, grab min/max possible rates, pick min,=
 clamp to 15/30 just in case.
>=20
> It appears to work quite well, the right frame rate is picked up and both=
 streams are in sync.
>=20
> (tested against Wipeout introduction for both PAL and NTSC versions).
>=20
>=20
> Besides, there have been significant findings over the years regarding th=
at format, specifically:
> https://problemkaputt.de/psxspx-macroblock-decoder-mdec.htm
> https://github.com/m35/jpsxdec/blob/readme/jpsxdec/PlayStation1_STR_forma=
t.txt
>=20
> Maybe someone versed in this topic (I'm not) could further improve suppor=
t of this format according these docs...
>=20
>=20
>=20
> Signed-off-by: aybe <aybe@users.noreply.github.com>
> ---
>   libavformat/psxstr.c | 27 +++++++++++++++++++++++++--
>   1 file changed, 25 insertions(+), 2 deletions(-)
>=20
> diff --git a/libavformat/psxstr.c b/libavformat/psxstr.c
> index 306a690f52..98897acde3 100644
> --- a/libavformat/psxstr.c
> +++ b/libavformat/psxstr.c
> @@ -52,6 +52,9 @@
>=20
>   #define STR_MAGIC (0x80010160)
>=20
> +#define MDEC_STR_FPS_MIN 15
> +#define MDEC_STR_FPS_MAX 30
> +
>   typedef struct StrChannel {
>       /* video parameters */
>       int video_stream_index;
> @@ -65,6 +68,10 @@ typedef struct StrDemuxContext {
>=20
>       /* a STR file can contain up to 32 channels of data */
>       StrChannel channels[32];
> +    /* trivial FPS detection based on sectors per frame */
> +    int fps_min; /* slowest FPS found */
> +    int fps_max; /* fastest FPS found */
> +    int fps_val; /* nominal FPS value */
>   } StrDemuxContext;
>=20
>   static const uint8_t sync_header[12] =3D {0x00,0xff,0xff,0xff,0xff,0xff=
,0xff,0xff,0xff,0xff,0xff,0x00};
> @@ -150,6 +157,10 @@ static int str_read_header(AVFormatContext *s)
>           str->channels[i].audio_stream_index=3D -1;
>       }
>=20
> +    str->fps_min =3D INT_MAX;
> +    str->fps_max =3D INT_MIN;
> +    str->fps_val =3D 0;
> +
>       s->ctx_flags |=3D AVFMTCTX_NOHEADER;
>=20
>       return 0;
> @@ -161,7 +172,7 @@ static int str_read_packet(AVFormatContext *s,
>       AVIOContext *pb =3D s->pb;
>       StrDemuxContext *str =3D s->priv_data;
>       unsigned char sector[RAW_CD_SECTOR_SIZE];
> -    int channel, ret;
> +    int channel, ret, sub_mode, idx_sect, num_sect;
>       AVPacket *pkt;
>       AVStream *st;
>=20
> @@ -178,6 +189,18 @@ static int str_read_packet(AVFormatContext *s,
>           if (channel >=3D 32)
>               return AVERROR_INVALIDDATA;
>=20
> +        sub_mode =3D sector[0x12];
> +        idx_sect =3D AV_RL16(&sector[0x1C]);
> +        num_sect =3D AV_RL16(&sector[0x1E]);
> +
> +        /* compute FPS from sector count @ each new video frame */
> +        if (sub_mode & 0x02 && idx_sect =3D=3D 0x00) {
> +            int fps =3D 150 / num_sect;
> +            str->fps_min =3D FFMIN(str->fps_min, fps);
> +            str->fps_max =3D FFMAX(str->fps_max, fps);
> +            str->fps_val =3D FFMIN(MDEC_STR_FPS_MAX, FFMAX(MDEC_STR_FPS_=
MIN, str->fps_min));
> +        }
> +
>           switch (sector[0x12] & CDXA_TYPE_MASK) {
>=20
>           case CDXA_TYPE_DATA:
> @@ -200,7 +223,7 @@ static int str_read_packet(AVFormatContext *s,
>                       st =3D avformat_new_stream(s, NULL);
>                       if (!st)
>                           return AVERROR(ENOMEM);
> -                    avpriv_set_pts_info(st, 64, 1, 15);
> +                    avpriv_set_pts_info(st, 64, 1, str->fps_val);

This is not a FPS value,
avpriv_set_pts_info() sets the timebase in which timestamps are specified

I dont know psxstr but can you explain what information there is in it
about the video frames ?
is there some sort of information that indicates when a frame is to be
displayed ?
that is like a timestamp ?

thx

[...]
--=20
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Elect your leaders based on what they did after the last election, not
based on what they say before an election.


--lGE/lu55aVFaufSH
Content-Type: application/pgp-signature; name="signature.asc"

-----BEGIN PGP SIGNATURE-----

iF0EABEIAB0WIQSf8hKLFH72cwut8TNhHseHBAsPqwUCZZ4HYAAKCRBhHseHBAsP
q4WcAKCXGQS1WGHQldk4x19WKlN5XnzZJgCfb+Op9z2Bkp5GVYZF3NtMlmuqDWE=
=e697
-----END PGP SIGNATURE-----

--lGE/lu55aVFaufSH--

--===============0159450469367431301==
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
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

--===============0159450469367431301==--