Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: aybe aybe <aybe.one-at-hotmail.com@ffmpeg.org>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Subject: Re: [FFmpeg-devel] [PATCH 4/4] avformat/psxstr: basic FPS detection instead of fixed value
Date: Sat, 13 Jan 2024 02:05:42 +0000
Message-ID: <PAVPR08MB97959732078A62FDCE67883A9A6E2@PAVPR08MB9795.eurprd08.prod.outlook.com> (raw)
In-Reply-To: <20240110025639.GR6420@pb2>

Sorry mate but I'm currently having a lot of trouble keeping in track with the mailing list...
I thought emClient would be a savior but it isn't, it's buggy and confusing as hell.
Have to check mailing list online, find mail in client so I can reply to it, really boring!

Anyway... for the patch I simply followed what the previous author did
Previous author did put 15 there and when played in VLC you get 15 FPS.
Therefore, I concluded that it is indeed the right place where this should be updated.

Format itself does not store the FPS, people would know in advance movie size/speed.
But as mentioned before, it is sort of possible to 'detect' that, what I've done in the patch.
A good source of information about the format is the following link:
https://github.com/m35/jpsxdec/blob/readme/jpsxdec/PlayStation1_STR_format.txt

My approach differs with the above in the sense that I assume min FPS is definitely right.
And that works on the movies I have tested so far, it returns 25/30 for PAL/NTSC versions.

------ Original Message ------
From "Michael Niedermayer" <michael@niedermayer.cc<mailto:michael@niedermayer.cc>>
To "FFmpeg development discussions and patches" <ffmpeg-devel@ffmpeg.org<mailto:ffmpeg-devel@ffmpeg.org>>
Date 1/10/2024 3:56:39 AM
Subject Re: [FFmpeg-devel] [PATCH 4/4] avformat/psxstr: basic FPS detection instead of fixed value

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.

In patch 1/4, although it would render video, the audio and video were not synchronized at all, now there are.

In this approach I kept it simple, grab min/max possible rates, pick min, clamp to 15/30 just in case.

It appears to work quite well, the right frame rate is picked up and both streams are in sync.

(tested against Wipeout introduction for both PAL and NTSC versions).


Besides, there have been significant findings over the years regarding that format, specifically:
https://problemkaputt.de/psxspx-macroblock-decoder-mdec.htm
https://github.com/m35/jpsxdec/blob/readme/jpsxdec/PlayStation1_STR_format.txt

Maybe someone versed in this topic (I'm not) could further improve support of this format according these docs...



Signed-off-by: aybe <aybe@users.noreply.github.com<mailto:aybe@users.noreply.github.com>>
---
libavformat/psxstr.c | 27 +++++++++++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)

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 @@

#define STR_MAGIC (0x80010160)

+#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 {

/* 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;

static const uint8_t sync_header[12] = {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= -1;
}

+ str->fps_min = INT_MAX;
+ str->fps_max = INT_MIN;
+ str->fps_val = 0;
+
s->ctx_flags |= AVFMTCTX_NOHEADER;

return 0;
@@ -161,7 +172,7 @@ static int str_read_packet(AVFormatContext *s,
AVIOContext *pb = s->pb;
StrDemuxContext *str = 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;

@@ -178,6 +189,18 @@ static int str_read_packet(AVFormatContext *s,
if (channel >= 32)
return AVERROR_INVALIDDATA;

+ sub_mode = sector[0x12];
+ idx_sect = AV_RL16(&sector[0x1C]);
+ num_sect = AV_RL16(&sector[0x1E]);
+
+ /* compute FPS from sector count @ each new video frame */
+ if (sub_mode & 0x02 && idx_sect == 0x00) {
+ int fps = 150 / num_sect;
+ str->fps_min = FFMIN(str->fps_min, fps);
+ str->fps_max = FFMAX(str->fps_max, fps);
+ str->fps_val = FFMIN(MDEC_STR_FPS_MAX, FFMAX(MDEC_STR_FPS_MIN, str->fps_min));
+ }
+
switch (sector[0x12] & CDXA_TYPE_MASK) {

case CDXA_TYPE_DATA:
@@ -200,7 +223,7 @@ static int str_read_packet(AVFormatContext *s,
st = 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

[...]
--
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.

_______________________________________________
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".

      reply	other threads:[~2024-01-13  2:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-02  3:14 aybe aybe
2024-01-06 23:44 ` Michael Niedermayer
2024-01-08  9:28   ` aybe aybe
2024-01-10  2:56 ` Michael Niedermayer
2024-01-13  2:05   ` aybe aybe [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=PAVPR08MB97959732078A62FDCE67883A9A6E2@PAVPR08MB9795.eurprd08.prod.outlook.com \
    --to=aybe.one-at-hotmail.com@ffmpeg.org \
    --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