Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 4/4] avformat/psxstr: basic FPS detection instead of fixed value
@ 2024-01-02  3:14 aybe aybe
  2024-01-06 23:44 ` Michael Niedermayer
  2024-01-10  2:56 ` Michael Niedermayer
  0 siblings, 2 replies; 5+ messages in thread
From: aybe aybe @ 2024-01-02  3:14 UTC (permalink / raw)
  To: ffmpeg-devel

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>
---
  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);

                      str->channels[channel].video_stream_index = st->index;

--
2.41.0.windows.1
_______________________________________________
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".

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-01-13  2:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-02  3:14 [FFmpeg-devel] [PATCH 4/4] avformat/psxstr: basic FPS detection instead of fixed value 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

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