diff mbox series

[FFmpeg-devel,4/4] avformat/psxstr: basic FPS detection instead of fixed value

Message ID PAVPR08MB97956CA2AC0B6F2A803A90439A61A@PAVPR08MB9795.eurprd08.prod.outlook.com
State New
Headers show
Series None | expand

Commit Message

aybe aybe Jan. 2, 2024, 3:14 a.m. UTC
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(-)

--
2.41.0.windows.1

Comments

Michael Niedermayer Jan. 6, 2024, 11:44 p.m. UTC | #1
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>
> ---
>   libavformat/psxstr.c | 27 +++++++++++++++++++++++++--
>   1 file changed, 25 insertions(+), 2 deletions(-)

The fate checksums change with the code change, they
need to be updated in this patch, if the changes are intended:

make -j32  fate-psx-str-demux

--- ./tests/ref/fate/psx-str-demux	2024-01-06 03:38:10.432133150 +0100
+++ tests/data/fate/psx-str-demux	2024-01-07 00:42:26.202312209 +0100
@@ -1,4 +1,4 @@
-#tb 0: 1/15
+#tb 0: 1/16
 #media_type 0: video
 #codec_id 0: mdec
 #dimensions 0: 320x240
@@ -19,8 +19,8 @@
 1,          4,          4,        1,     2304, 0x40a1b447
 0,          4,          4,        1,     9404, 0xe94dfd40
 1,          5,          5,        1,     2304, 0x150dae9f
-1,          6,          6,        1,     2304, 0xad16bc63
 0,          5,          5,        1,     9492, 0xf73f2541
+1,          6,          6,        1,     2304, 0xad16bc63
 1,          7,          7,        1,     2304, 0xe989b175
 0,          6,          6,        1,     9652, 0x243d53f8
 1,          8,          8,        1,     2304, 0x3c77cd39
@@ -28,183 +28,183 @@
 1,          9,          9,        1,     2304, 0x93f0c2ba
 0,          8,          8,        1,    10052, 0x7604247a
 1,         10,         10,        1,     2304, 0x6e2ad2d0
-1,         11,         11,        1,     2304, 0xf8eab90a
 0,          9,          9,        1,    10100, 0x077107fd
-1,         12,         12,        1,     2304, 0xc039bf0d
+1,         11,         11,        1,     2304, 0xf8eab90a
 0,         10,         10,        1,    10264, 0xae675eb6
-1,         13,         13,        1,     2304, 0x0900c7e8
+1,         12,         12,        1,     2304, 0xc039bf0d
 0,         11,         11,        1,    10464, 0x428f83ae
+1,         13,         13,        1,     2304, 0x0900c7e8
 1,         14,         14,        1,     2304, 0x9722d580
 0,         12,         12,        1,    10580, 0x1bdcd71b
 1,         15,         15,        1,     2304, 0x02eec8de
-1,         16,         16,        1,     2304, 0x4807a2b3
 0,         13,         13,        1,    10800, 0xde75213a
-1,         17,         17,        1,     2304, 0x4643be06
+1,         16,         16,        1,     2304, 0x4807a2b3
 0,         14,         14,        1,    11236, 0x9387cc8e
-1,         18,         18,        1,     2304, 0x5bd9d249
+1,         17,         17,        1,     2304, 0x4643be06
 0,         15,         15,        1,    11420, 0x3a7d321b
-1,         19,         19,        1,     2304, 0x4e33c2bc
+1,         18,         18,        1,     2304, 0x5bd9d249
 0,         16,         16,        1,    11632, 0x7edc9cdf
+1,         19,         19,        1,     2304, 0x4e33c2bc
+0,         17,         17,        1,    11936, 0xf0521017
 1,         20,         20,        1,     2304, 0x085ca51d
 1,         21,         21,        1,     2304, 0xa205b202
-0,         17,         17,        1,    11936, 0xf0521017
-1,         22,         22,        1,     2304, 0x71b9bcca
 0,         18,         18,        1,    11804, 0x53b22066
-1,         23,         23,        1,     2304, 0xcb769e5f
+1,         22,         22,        1,     2304, 0x71b9bcca
 0,         19,         19,        1,    11852, 0x9425fb21
-1,         24,         24,        1,     2304, 0x9322d85a
+1,         23,         23,        1,     2304, 0xcb769e5f
 0,         20,         20,        1,    12108, 0xc386941d
+1,         24,         24,        1,     2304, 0x9322d85a
+0,         21,         21,        1,    12796, 0x8b7e5dab
 1,         25,         25,        1,     2304, 0x7f13bf6e
+0,         22,         22,        1,    13316, 0x81235102
 1,         26,         26,        1,     2304, 0xd302a5cd
-0,         21,         21,        1,    12796, 0x8b7e5dab
+0,         23,         23,        1,    13724, 0xe5fc2bca
 1,         27,         27,        1,     2304, 0x7a7a9e30
-0,         22,         22,        1,    13316, 0x81235102
 1,         28,         28,        1,     2304, 0x6ffccfdd
-0,         23,         23,        1,    13724, 0xe5fc2bca
-1,         29,         29,        1,     2304, 0xae88bf7a
 0,         24,         24,        1,    14304, 0xa5b1f811
+1,         29,         29,        1,     2304, 0xae88bf7a
+0,         25,         25,        1,    15216, 0xf4996763
 1,         30,         30,        1,     2304, 0xf816c2f5
+0,         26,         26,        1,    16224, 0xe30b0679
 1,         31,         31,        1,     2304, 0xdb42a783
-0,         25,         25,        1,    15216, 0xf4996763
+0,         27,         27,        1,    10640, 0xaeb122c9
 1,         32,         32,        1,     2304, 0xfc55c021
-0,         26,         26,        1,    16224, 0xe30b0679
+0,         28,         28,        1,    11652, 0x087d18b1
 1,         33,         33,        1,     2304, 0x9da68fc1
-0,         27,         27,        1,    10640, 0xaeb122c9
+0,         29,         29,        1,    12008, 0x1eeeac41
 1,         34,         34,        1,     2304, 0x2f65bb0f
-0,         28,         28,        1,    11652, 0x087d18b1
 1,         35,         35,        1,     2304, 0x6e5da2c7
+0,         30,         30,        1,    12344, 0x488c64ec
 1,         36,         36,        1,     2304, 0xb0b0c5f8
-0,         29,         29,        1,    12008, 0x1eeeac41
+0,         31,         31,        1,    13004, 0x02a69339
 1,         37,         37,        1,     2304, 0x32559dc6
-0,         30,         30,        1,    12344, 0x488c64ec
+0,         32,         32,        1,    14092, 0x348a7d3f
 1,         38,         38,        1,     2304, 0x9168aed0
-0,         31,         31,        1,    13004, 0x02a69339
+0,         33,         33,        1,    15048, 0xa55ef200
 1,         39,         39,        1,     2304, 0x32069bce
-0,         32,         32,        1,    14092, 0x348a7d3f
+0,         34,         34,        1,    16100, 0xac17de5b
 1,         40,         40,        1,     2304, 0x763ca8e0
 1,         41,         41,        1,     2304, 0x70c7a44e
-0,         33,         33,        1,    15048, 0xa55ef200
+0,         35,         35,        1,    13180, 0x4d874f61
 1,         42,         42,        1,     2304, 0x7dc1b275
-0,         34,         34,        1,    16100, 0xac17de5b
+0,         36,         36,        1,    14592, 0x5f58f505
 1,         43,         43,        1,     2304, 0x2e26ceae
-0,         35,         35,        1,    13180, 0x4d874f61
+0,         37,         37,        1,    14372, 0x369bb5d9
 1,         44,         44,        1,     2304, 0xa071a7e2
-0,         36,         36,        1,    14592, 0x5f58f505
+0,         38,         38,        1,    16172, 0x513a97b6
 1,         45,         45,        1,     2304, 0xe434ad92
+0,         39,         39,        1,    15136, 0x7f9a3865
 1,         46,         46,        1,     2304, 0xb4469381
-0,         37,         37,        1,    14372, 0x369bb5d9
+0,         40,         40,        1,    16336, 0x1339ba5f
 1,         47,         47,        1,     2304, 0x3f20a7c5
-0,         38,         38,        1,    16172, 0x513a97b6
 1,         48,         48,        1,     2304, 0x68ef9ef9
-0,         39,         39,        1,    15136, 0x7f9a3865
+0,         41,         41,        1,    16944, 0x122f71b7
 1,         49,         49,        1,     2304, 0x32dbb3e2
-0,         40,         40,        1,    16336, 0x1339ba5f
+0,         42,         42,        1,    17536, 0x7461b152
 1,         50,         50,        1,     2304, 0xdd90c7c3
+0,         43,         43,        1,    13940, 0xf5278274
 1,         51,         51,        1,     2304, 0xd106adb5
-0,         41,         41,        1,    16944, 0x122f71b7
+0,         44,         44,        1,     8592, 0x4bb2eaea
 1,         52,         52,        1,     2304, 0x11dca8c4
-0,         42,         42,        1,    17536, 0x7461b152
+0,         45,         45,        1,     8584, 0x2ff1e3db
 1,         53,         53,        1,     2304, 0x646d98bc
-0,         43,         43,        1,    13940, 0xf5278274
+0,         46,         46,        1,     8548, 0xadfd01b4
 1,         54,         54,        1,     2304, 0x6f019e81
-0,         44,         44,        1,     8592, 0x4bb2eaea
 1,         55,         55,        1,     2304, 0xc872a896
+0,         47,         47,        1,     8548, 0x9e2ec85f
 1,         56,         56,        1,     2304, 0xc7d7a0bc
-0,         45,         45,        1,     8584, 0x2ff1e3db
+0,         48,         48,        1,     8540, 0x9e2ad166
 1,         57,         57,        1,     2304, 0x181b880a
-0,         46,         46,        1,     8548, 0xadfd01b4
+0,         49,         49,        1,     8524, 0x047bc406
 1,         58,         58,        1,     2304, 0x6486b158
-0,         47,         47,        1,     8548, 0x9e2ec85f
+0,         50,         50,        1,     8508, 0xd051ddbb
 1,         59,         59,        1,     2304, 0x26d5a3db
-0,         48,         48,        1,     8540, 0x9e2ad166
+0,         51,         51,        1,     8572, 0x40b5004c
 1,         60,         60,        1,     2304, 0x4ff89a4d
+0,         52,         52,        1,     8564, 0xb379db59
 1,         61,         61,        1,     2304, 0xc42e9552
-0,         49,         49,        1,     8524, 0x047bc406
 1,         62,         62,        1,     2304, 0x0dc1c346
-0,         50,         50,        1,     8508, 0xd051ddbb
+0,         53,         53,        1,     8592, 0x22d0bc35
 1,         63,         63,        1,     2304, 0x5e51b7a5
-0,         51,         51,        1,     8572, 0x40b5004c
+0,         54,         54,        1,     8656, 0xa58917d5
 1,         64,         64,        1,     2304, 0xbd49c142
-0,         52,         52,        1,     8564, 0xb379db59
+0,         55,         55,        1,     8616, 0xc9e4f431
 1,         65,         65,        1,     2304, 0x373da274
+0,         56,         56,        1,     8660, 0x7a90ffd1
 1,         66,         66,        1,     2304, 0xde97b1bb
-0,         53,         53,        1,     8592, 0x22d0bc35
+0,         57,         57,        1,     8636, 0xec8ce437
 1,         67,         67,        1,     2304, 0x9715bf29
-0,         54,         54,        1,     8656, 0xa58917d5
+0,         58,         58,        1,     8668, 0x8b73139f
 1,         68,         68,        1,     2304, 0xc341b4ef
-0,         55,         55,        1,     8616, 0xc9e4f431
 1,         69,         69,        1,     2304, 0xc610adc6
-0,         56,         56,        1,     8660, 0x7a90ffd1
+0,         59,         59,        1,     8640, 0x3ee30f9c
 1,         70,         70,        1,     2304, 0x67bba315
+0,         60,         60,        1,     8728, 0xdbe12a94
 1,         71,         71,        1,     2304, 0x949b9c16
-0,         57,         57,        1,     8636, 0xec8ce437
+0,         61,         61,        1,     8748, 0xc4132fd5
 1,         72,         72,        1,     2304, 0xc7c1a8ca
-0,         58,         58,        1,     8668, 0x8b73139f
+0,         62,         62,        1,     8720, 0x7ac9316a
 1,         73,         73,        1,     2304, 0x1929bc7e
-0,         59,         59,        1,     8640, 0x3ee30f9c
+0,         63,         63,        1,     8756, 0xf47d843d
 1,         74,         74,        1,     2304, 0x5fc97897
-0,         60,         60,        1,     8728, 0xdbe12a94
+0,         64,         64,        1,     8840, 0x82808e79
 1,         75,         75,        1,     2304, 0x272da8d3
 1,         76,         76,        1,     2304, 0x141e904d
-0,         61,         61,        1,     8748, 0xc4132fd5
+0,         65,         65,        1,     8908, 0x63568647
 1,         77,         77,        1,     2304, 0x9880b0ed
-0,         62,         62,        1,     8720, 0x7ac9316a
+0,         66,         66,        1,     8968, 0xbd26de31
 1,         78,         78,        1,     2304, 0x0438932a
-0,         63,         63,        1,     8756, 0xf47d843d
+0,         67,         67,        1,     9168, 0xe1cd43a3
 1,         79,         79,        1,     2304, 0x27069761
-0,         64,         64,        1,     8840, 0x82808e79
+0,         68,         68,        1,     9272, 0x0cc64c79
 1,         80,         80,        1,     2304, 0x0baba2b7
+0,         69,         69,        1,     9700, 0x5cd2be73
 1,         81,         81,        1,     2304, 0x4bc491af
-0,         65,         65,        1,     8908, 0x63568647
 1,         82,         82,        1,     2304, 0x72e18e82
-0,         66,         66,        1,     8968, 0xbd26de31
+0,         70,         70,        1,     9868, 0x9b1629ae
 1,         83,         83,        1,     2304, 0xf85d8a91
-0,         67,         67,        1,     9168, 0xe1cd43a3
+0,         71,         71,        1,    10264, 0xa13cb7db
 1,         84,         84,        1,     2304, 0x653582e3
-0,         68,         68,        1,     9272, 0x0cc64c79
+0,         72,         72,        1,    10908, 0xe995858e
 1,         85,         85,        1,     2304, 0x6b5e8084
+0,         73,         73,        1,    11272, 0xebea53f6
 1,         86,         86,        1,     2304, 0x8cc27d10
-0,         69,         69,        1,     9700, 0x5cd2be73
+0,         74,         74,        1,    12128, 0xdfa8b7aa
 1,         87,         87,        1,     2304, 0xcf8f9e1d
-0,         70,         70,        1,     9868, 0x9b1629ae
+0,         75,         75,        1,    12560, 0x46048576
 1,         88,         88,        1,     2304, 0xecbe89df
-0,         71,         71,        1,    10264, 0xa13cb7db
 1,         89,         89,        1,     2304, 0xa433753d
-0,         72,         72,        1,    10908, 0xe995858e
+0,         76,         76,        1,    12900, 0x5b3aeb76
 1,         90,         90,        1,     2304, 0xe386afe9
+0,         77,         77,        1,    13544, 0x0f98fb94
 1,         91,         91,        1,     2304, 0x90409771
-0,         73,         73,        1,    11272, 0xebea53f6
+0,         78,         78,        1,    13968, 0x7c17c4c2
 1,         92,         92,        1,     2304, 0x29c88ae5
-0,         74,         74,        1,    12128, 0xdfa8b7aa
+0,         79,         79,        1,    15020, 0xe8faa930
 1,         93,         93,        1,     2304, 0x900b9e6a
-0,         75,         75,        1,    12560, 0x46048576
+0,         80,         80,        1,    16152, 0x3f004f78
 1,         94,         94,        1,     2304, 0x958cbb49
-0,         76,         76,        1,    12900, 0x5b3aeb76
+0,         81,         81,        1,    17224, 0x103f3935
 1,         95,         95,        1,     2304, 0xf83da537
 1,         96,         96,        1,     2304, 0x5fad9e5f
-0,         77,         77,        1,    13544, 0x0f98fb94
+0,         82,         82,        1,    11956, 0x7af9354a
 1,         97,         97,        1,     2304, 0xae15902a
-0,         78,         78,        1,    13968, 0x7c17c4c2
+0,         83,         83,        1,    12644, 0xe113a4b2
 1,         98,         98,        1,     2304, 0xf2a8b9d8
-0,         79,         79,        1,    15020, 0xe8faa930
+0,         84,         84,        1,    13420, 0xdf3ec8a4
 1,         99,         99,        1,     2304, 0x7bc99f71
-0,         80,         80,        1,    16152, 0x3f004f78
+0,         85,         85,        1,    14140, 0x0ad8a165
 1,        100,        100,        1,     2304, 0x3f199672
+0,         86,         86,        1,    15192, 0xc55f45cd
 1,        101,        101,        1,     2304, 0x4e258c38
-0,         81,         81,        1,    17224, 0x103f3935
+0,         87,         87,        1,    12740, 0xa13c85db
 1,        102,        102,        1,     2304, 0x5119b909
-0,         82,         82,        1,    11956, 0x7af9354a
 1,        103,        103,        1,     2304, 0xad57a533
-0,         83,         83,        1,    12644, 0xe113a4b2
+0,         88,         88,        1,    14416, 0x9e68b57d
 1,        104,        104,        1,     2304, 0xe40eb453
-0,         84,         84,        1,    13420, 0xdf3ec8a4
 1,        105,        105,        1,     2304, 0x502cc37e
 1,        106,        106,        1,     2304, 0x5b7bae9a
-0,         85,         85,        1,    14140, 0x0ad8a165
 1,        107,        107,        1,     2304, 0x0458a92d
-0,         86,         86,        1,    15192, 0xc55f45cd
 1,        108,        108,        1,     2304, 0x1529aba8
-0,         87,         87,        1,    12740, 0xa13c85db
 1,        109,        109,        1,     2304, 0x1a52a9d1
-0,         88,         88,        1,    14416, 0x9e68b57d
 1,        110,        110,        1,     2304, 0x76a2a7c9
Test psx-str-demux failed. Look at tests/data/fate/psx-str-demux.err for details.
tests/Makefile:312: recipe for target 'fate-psx-str-demux' failed
make: *** [fate-psx-str-demux] Error 1


[...]
aybe aybe Jan. 8, 2024, 9:28 a.m. UTC | #2
Let's see if I've got it right: pasting patch down there should make patchwork pick it up automatically and do its magic :)

Signed-off-by: aybe <aybe@users.noreply.github.com<mailto:aybe@users.noreply.github.com>>
---
 tests/ref/fate/psx-str-demux | 162 +++++++++++++++++------------------
 1 file changed, 81 insertions(+), 81 deletions(-)

diff --git a/tests/ref/fate/psx-str-demux b/tests/ref/fate/psx-str-demux
index 18a21b0bb6..ea90261bf3 100644
--- a/tests/ref/fate/psx-str-demux
+++ b/tests/ref/fate/psx-str-demux
@@ -1,4 +1,4 @@
-#tb 0: 1/15
+#tb 0: 1/16
 #media_type 0: video
 #codec_id 0: mdec
 #dimensions 0: 320x240
@@ -19,8 +19,8 @@
 1,          4,          4,        1,     2304, 0x40a1b447
 0,          4,          4,        1,     9404, 0xe94dfd40
 1,          5,          5,        1,     2304, 0x150dae9f
-1,          6,          6,        1,     2304, 0xad16bc63
 0,          5,          5,        1,     9492, 0xf73f2541
+1,          6,          6,        1,     2304, 0xad16bc63
 1,          7,          7,        1,     2304, 0xe989b175
 0,          6,          6,        1,     9652, 0x243d53f8
 1,          8,          8,        1,     2304, 0x3c77cd39
@@ -28,183 +28,183 @@
 1,          9,          9,        1,     2304, 0x93f0c2ba
 0,          8,          8,        1,    10052, 0x7604247a
 1,         10,         10,        1,     2304, 0x6e2ad2d0
-1,         11,         11,        1,     2304, 0xf8eab90a
 0,          9,          9,        1,    10100, 0x077107fd
-1,         12,         12,        1,     2304, 0xc039bf0d
+1,         11,         11,        1,     2304, 0xf8eab90a
 0,         10,         10,        1,    10264, 0xae675eb6
-1,         13,         13,        1,     2304, 0x0900c7e8
+1,         12,         12,        1,     2304, 0xc039bf0d
 0,         11,         11,        1,    10464, 0x428f83ae
+1,         13,         13,        1,     2304, 0x0900c7e8
 1,         14,         14,        1,     2304, 0x9722d580
 0,         12,         12,        1,    10580, 0x1bdcd71b
 1,         15,         15,        1,     2304, 0x02eec8de
-1,         16,         16,        1,     2304, 0x4807a2b3
 0,         13,         13,        1,    10800, 0xde75213a
-1,         17,         17,        1,     2304, 0x4643be06
+1,         16,         16,        1,     2304, 0x4807a2b3
 0,         14,         14,        1,    11236, 0x9387cc8e
-1,         18,         18,        1,     2304, 0x5bd9d249
+1,         17,         17,        1,     2304, 0x4643be06
 0,         15,         15,        1,    11420, 0x3a7d321b
-1,         19,         19,        1,     2304, 0x4e33c2bc
+1,         18,         18,        1,     2304, 0x5bd9d249
 0,         16,         16,        1,    11632, 0x7edc9cdf
+1,         19,         19,        1,     2304, 0x4e33c2bc
+0,         17,         17,        1,    11936, 0xf0521017
 1,         20,         20,        1,     2304, 0x085ca51d
 1,         21,         21,        1,     2304, 0xa205b202
-0,         17,         17,        1,    11936, 0xf0521017
-1,         22,         22,        1,     2304, 0x71b9bcca
 0,         18,         18,        1,    11804, 0x53b22066
-1,         23,         23,        1,     2304, 0xcb769e5f
+1,         22,         22,        1,     2304, 0x71b9bcca
 0,         19,         19,        1,    11852, 0x9425fb21
-1,         24,         24,        1,     2304, 0x9322d85a
+1,         23,         23,        1,     2304, 0xcb769e5f
 0,         20,         20,        1,    12108, 0xc386941d
+1,         24,         24,        1,     2304, 0x9322d85a
+0,         21,         21,        1,    12796, 0x8b7e5dab
 1,         25,         25,        1,     2304, 0x7f13bf6e
+0,         22,         22,        1,    13316, 0x81235102
 1,         26,         26,        1,     2304, 0xd302a5cd
-0,         21,         21,        1,    12796, 0x8b7e5dab
+0,         23,         23,        1,    13724, 0xe5fc2bca
 1,         27,         27,        1,     2304, 0x7a7a9e30
-0,         22,         22,        1,    13316, 0x81235102
 1,         28,         28,        1,     2304, 0x6ffccfdd
-0,         23,         23,        1,    13724, 0xe5fc2bca
-1,         29,         29,        1,     2304, 0xae88bf7a
 0,         24,         24,        1,    14304, 0xa5b1f811
+1,         29,         29,        1,     2304, 0xae88bf7a
+0,         25,         25,        1,    15216, 0xf4996763
 1,         30,         30,        1,     2304, 0xf816c2f5
+0,         26,         26,        1,    16224, 0xe30b0679
 1,         31,         31,        1,     2304, 0xdb42a783
-0,         25,         25,        1,    15216, 0xf4996763
+0,         27,         27,        1,    10640, 0xaeb122c9
 1,         32,         32,        1,     2304, 0xfc55c021
-0,         26,         26,        1,    16224, 0xe30b0679
+0,         28,         28,        1,    11652, 0x087d18b1
 1,         33,         33,        1,     2304, 0x9da68fc1
-0,         27,         27,        1,    10640, 0xaeb122c9
+0,         29,         29,        1,    12008, 0x1eeeac41
 1,         34,         34,        1,     2304, 0x2f65bb0f
-0,         28,         28,        1,    11652, 0x087d18b1
 1,         35,         35,        1,     2304, 0x6e5da2c7
+0,         30,         30,        1,    12344, 0x488c64ec
 1,         36,         36,        1,     2304, 0xb0b0c5f8
-0,         29,         29,        1,    12008, 0x1eeeac41
+0,         31,         31,        1,    13004, 0x02a69339
 1,         37,         37,        1,     2304, 0x32559dc6
-0,         30,         30,        1,    12344, 0x488c64ec
+0,         32,         32,        1,    14092, 0x348a7d3f
 1,         38,         38,        1,     2304, 0x9168aed0
-0,         31,         31,        1,    13004, 0x02a69339
+0,         33,         33,        1,    15048, 0xa55ef200
 1,         39,         39,        1,     2304, 0x32069bce
-0,         32,         32,        1,    14092, 0x348a7d3f
+0,         34,         34,        1,    16100, 0xac17de5b
 1,         40,         40,        1,     2304, 0x763ca8e0
 1,         41,         41,        1,     2304, 0x70c7a44e
-0,         33,         33,        1,    15048, 0xa55ef200
+0,         35,         35,        1,    13180, 0x4d874f61
 1,         42,         42,        1,     2304, 0x7dc1b275
-0,         34,         34,        1,    16100, 0xac17de5b
+0,         36,         36,        1,    14592, 0x5f58f505
 1,         43,         43,        1,     2304, 0x2e26ceae
-0,         35,         35,        1,    13180, 0x4d874f61
+0,         37,         37,        1,    14372, 0x369bb5d9
 1,         44,         44,        1,     2304, 0xa071a7e2
-0,         36,         36,        1,    14592, 0x5f58f505
+0,         38,         38,        1,    16172, 0x513a97b6
 1,         45,         45,        1,     2304, 0xe434ad92
+0,         39,         39,        1,    15136, 0x7f9a3865
 1,         46,         46,        1,     2304, 0xb4469381
-0,         37,         37,        1,    14372, 0x369bb5d9
+0,         40,         40,        1,    16336, 0x1339ba5f
 1,         47,         47,        1,     2304, 0x3f20a7c5
-0,         38,         38,        1,    16172, 0x513a97b6
 1,         48,         48,        1,     2304, 0x68ef9ef9
-0,         39,         39,        1,    15136, 0x7f9a3865
+0,         41,         41,        1,    16944, 0x122f71b7
 1,         49,         49,        1,     2304, 0x32dbb3e2
-0,         40,         40,        1,    16336, 0x1339ba5f
+0,         42,         42,        1,    17536, 0x7461b152
 1,         50,         50,        1,     2304, 0xdd90c7c3
+0,         43,         43,        1,    13940, 0xf5278274
 1,         51,         51,        1,     2304, 0xd106adb5
-0,         41,         41,        1,    16944, 0x122f71b7
+0,         44,         44,        1,     8592, 0x4bb2eaea
 1,         52,         52,        1,     2304, 0x11dca8c4
-0,         42,         42,        1,    17536, 0x7461b152
+0,         45,         45,        1,     8584, 0x2ff1e3db
 1,         53,         53,        1,     2304, 0x646d98bc
-0,         43,         43,        1,    13940, 0xf5278274
+0,         46,         46,        1,     8548, 0xadfd01b4
 1,         54,         54,        1,     2304, 0x6f019e81
-0,         44,         44,        1,     8592, 0x4bb2eaea
 1,         55,         55,        1,     2304, 0xc872a896
+0,         47,         47,        1,     8548, 0x9e2ec85f
 1,         56,         56,        1,     2304, 0xc7d7a0bc
-0,         45,         45,        1,     8584, 0x2ff1e3db
+0,         48,         48,        1,     8540, 0x9e2ad166
 1,         57,         57,        1,     2304, 0x181b880a
-0,         46,         46,        1,     8548, 0xadfd01b4
+0,         49,         49,        1,     8524, 0x047bc406
 1,         58,         58,        1,     2304, 0x6486b158
-0,         47,         47,        1,     8548, 0x9e2ec85f
+0,         50,         50,        1,     8508, 0xd051ddbb
 1,         59,         59,        1,     2304, 0x26d5a3db
-0,         48,         48,        1,     8540, 0x9e2ad166
+0,         51,         51,        1,     8572, 0x40b5004c
 1,         60,         60,        1,     2304, 0x4ff89a4d
+0,         52,         52,        1,     8564, 0xb379db59
 1,         61,         61,        1,     2304, 0xc42e9552
-0,         49,         49,        1,     8524, 0x047bc406
 1,         62,         62,        1,     2304, 0x0dc1c346
-0,         50,         50,        1,     8508, 0xd051ddbb
+0,         53,         53,        1,     8592, 0x22d0bc35
 1,         63,         63,        1,     2304, 0x5e51b7a5
-0,         51,         51,        1,     8572, 0x40b5004c
+0,         54,         54,        1,     8656, 0xa58917d5
 1,         64,         64,        1,     2304, 0xbd49c142
-0,         52,         52,        1,     8564, 0xb379db59
+0,         55,         55,        1,     8616, 0xc9e4f431
 1,         65,         65,        1,     2304, 0x373da274
+0,         56,         56,        1,     8660, 0x7a90ffd1
 1,         66,         66,        1,     2304, 0xde97b1bb
-0,         53,         53,        1,     8592, 0x22d0bc35
+0,         57,         57,        1,     8636, 0xec8ce437
 1,         67,         67,        1,     2304, 0x9715bf29
-0,         54,         54,        1,     8656, 0xa58917d5
+0,         58,         58,        1,     8668, 0x8b73139f
 1,         68,         68,        1,     2304, 0xc341b4ef
-0,         55,         55,        1,     8616, 0xc9e4f431
 1,         69,         69,        1,     2304, 0xc610adc6
-0,         56,         56,        1,     8660, 0x7a90ffd1
+0,         59,         59,        1,     8640, 0x3ee30f9c
 1,         70,         70,        1,     2304, 0x67bba315
+0,         60,         60,        1,     8728, 0xdbe12a94
 1,         71,         71,        1,     2304, 0x949b9c16
-0,         57,         57,        1,     8636, 0xec8ce437
+0,         61,         61,        1,     8748, 0xc4132fd5
 1,         72,         72,        1,     2304, 0xc7c1a8ca
-0,         58,         58,        1,     8668, 0x8b73139f
+0,         62,         62,        1,     8720, 0x7ac9316a
 1,         73,         73,        1,     2304, 0x1929bc7e
-0,         59,         59,        1,     8640, 0x3ee30f9c
+0,         63,         63,        1,     8756, 0xf47d843d
 1,         74,         74,        1,     2304, 0x5fc97897
-0,         60,         60,        1,     8728, 0xdbe12a94
+0,         64,         64,        1,     8840, 0x82808e79
 1,         75,         75,        1,     2304, 0x272da8d3
 1,         76,         76,        1,     2304, 0x141e904d
-0,         61,         61,        1,     8748, 0xc4132fd5
+0,         65,         65,        1,     8908, 0x63568647
 1,         77,         77,        1,     2304, 0x9880b0ed
-0,         62,         62,        1,     8720, 0x7ac9316a
+0,         66,         66,        1,     8968, 0xbd26de31
 1,         78,         78,        1,     2304, 0x0438932a
-0,         63,         63,        1,     8756, 0xf47d843d
+0,         67,         67,        1,     9168, 0xe1cd43a3
 1,         79,         79,        1,     2304, 0x27069761
-0,         64,         64,        1,     8840, 0x82808e79
+0,         68,         68,        1,     9272, 0x0cc64c79
 1,         80,         80,        1,     2304, 0x0baba2b7
+0,         69,         69,        1,     9700, 0x5cd2be73
 1,         81,         81,        1,     2304, 0x4bc491af
-0,         65,         65,        1,     8908, 0x63568647
 1,         82,         82,        1,     2304, 0x72e18e82
-0,         66,         66,        1,     8968, 0xbd26de31
+0,         70,         70,        1,     9868, 0x9b1629ae
 1,         83,         83,        1,     2304, 0xf85d8a91
-0,         67,         67,        1,     9168, 0xe1cd43a3
+0,         71,         71,        1,    10264, 0xa13cb7db
 1,         84,         84,        1,     2304, 0x653582e3
-0,         68,         68,        1,     9272, 0x0cc64c79
+0,         72,         72,        1,    10908, 0xe995858e
 1,         85,         85,        1,     2304, 0x6b5e8084
+0,         73,         73,        1,    11272, 0xebea53f6
 1,         86,         86,        1,     2304, 0x8cc27d10
-0,         69,         69,        1,     9700, 0x5cd2be73
+0,         74,         74,        1,    12128, 0xdfa8b7aa
 1,         87,         87,        1,     2304, 0xcf8f9e1d
-0,         70,         70,        1,     9868, 0x9b1629ae
+0,         75,         75,        1,    12560, 0x46048576
 1,         88,         88,        1,     2304, 0xecbe89df
-0,         71,         71,        1,    10264, 0xa13cb7db
 1,         89,         89,        1,     2304, 0xa433753d
-0,         72,         72,        1,    10908, 0xe995858e
+0,         76,         76,        1,    12900, 0x5b3aeb76
 1,         90,         90,        1,     2304, 0xe386afe9
+0,         77,         77,        1,    13544, 0x0f98fb94
 1,         91,         91,        1,     2304, 0x90409771
-0,         73,         73,        1,    11272, 0xebea53f6
+0,         78,         78,        1,    13968, 0x7c17c4c2
 1,         92,         92,        1,     2304, 0x29c88ae5
-0,         74,         74,        1,    12128, 0xdfa8b7aa
+0,         79,         79,        1,    15020, 0xe8faa930
 1,         93,         93,        1,     2304, 0x900b9e6a
-0,         75,         75,        1,    12560, 0x46048576
+0,         80,         80,        1,    16152, 0x3f004f78
 1,         94,         94,        1,     2304, 0x958cbb49
-0,         76,         76,        1,    12900, 0x5b3aeb76
+0,         81,         81,        1,    17224, 0x103f3935
 1,         95,         95,        1,     2304, 0xf83da537
 1,         96,         96,        1,     2304, 0x5fad9e5f
-0,         77,         77,        1,    13544, 0x0f98fb94
+0,         82,         82,        1,    11956, 0x7af9354a
 1,         97,         97,        1,     2304, 0xae15902a
-0,         78,         78,        1,    13968, 0x7c17c4c2
+0,         83,         83,        1,    12644, 0xe113a4b2
 1,         98,         98,        1,     2304, 0xf2a8b9d8
-0,         79,         79,        1,    15020, 0xe8faa930
+0,         84,         84,        1,    13420, 0xdf3ec8a4
 1,         99,         99,        1,     2304, 0x7bc99f71
-0,         80,         80,        1,    16152, 0x3f004f78
+0,         85,         85,        1,    14140, 0x0ad8a165
 1,        100,        100,        1,     2304, 0x3f199672
+0,         86,         86,        1,    15192, 0xc55f45cd
 1,        101,        101,        1,     2304, 0x4e258c38
-0,         81,         81,        1,    17224, 0x103f3935
+0,         87,         87,        1,    12740, 0xa13c85db
 1,        102,        102,        1,     2304, 0x5119b909
-0,         82,         82,        1,    11956, 0x7af9354a
 1,        103,        103,        1,     2304, 0xad57a533
-0,         83,         83,        1,    12644, 0xe113a4b2
+0,         88,         88,        1,    14416, 0x9e68b57d
 1,        104,        104,        1,     2304, 0xe40eb453
-0,         84,         84,        1,    13420, 0xdf3ec8a4
 1,        105,        105,        1,     2304, 0x502cc37e
 1,        106,        106,        1,     2304, 0x5b7bae9a
-0,         85,         85,        1,    14140, 0x0ad8a165
 1,        107,        107,        1,     2304, 0x0458a92d
-0,         86,         86,        1,    15192, 0xc55f45cd
 1,        108,        108,        1,     2304, 0x1529aba8
-0,         87,         87,        1,    12740, 0xa13c85db
 1,        109,        109,        1,     2304, 0x1a52a9d1
-0,         88,         88,        1,    14416, 0x9e68b57d
 1,        110,        110,        1,     2304, 0x76a2a7c9
--
2.41.0.windows.1


------ 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/7/2024 12:44:03 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(-)

The fate checksums change with the code change, they
need to be updated in this patch, if the changes are intended:

make -j32 fate-psx-str-demux

--- ./tests/ref/fate/psx-str-demux 2024-01-06 03:38:10.432133150 +0100
+++ tests/data/fate/psx-str-demux 2024-01-07 00:42:26.202312209 +0100
@@ -1,4 +1,4 @@
-#tb 0: 1/15
+#tb 0: 1/16
#media_type 0: video
#codec_id 0: mdec
#dimensions 0: 320x240
@@ -19,8 +19,8 @@
1, 4, 4, 1, 2304, 0x40a1b447
0, 4, 4, 1, 9404, 0xe94dfd40
1, 5, 5, 1, 2304, 0x150dae9f
-1, 6, 6, 1, 2304, 0xad16bc63
0, 5, 5, 1, 9492, 0xf73f2541
+1, 6, 6, 1, 2304, 0xad16bc63
1, 7, 7, 1, 2304, 0xe989b175
0, 6, 6, 1, 9652, 0x243d53f8
1, 8, 8, 1, 2304, 0x3c77cd39
@@ -28,183 +28,183 @@
1, 9, 9, 1, 2304, 0x93f0c2ba
0, 8, 8, 1, 10052, 0x7604247a
1, 10, 10, 1, 2304, 0x6e2ad2d0
-1, 11, 11, 1, 2304, 0xf8eab90a
0, 9, 9, 1, 10100, 0x077107fd
-1, 12, 12, 1, 2304, 0xc039bf0d
+1, 11, 11, 1, 2304, 0xf8eab90a
0, 10, 10, 1, 10264, 0xae675eb6
-1, 13, 13, 1, 2304, 0x0900c7e8
+1, 12, 12, 1, 2304, 0xc039bf0d
0, 11, 11, 1, 10464, 0x428f83ae
+1, 13, 13, 1, 2304, 0x0900c7e8
1, 14, 14, 1, 2304, 0x9722d580
0, 12, 12, 1, 10580, 0x1bdcd71b
1, 15, 15, 1, 2304, 0x02eec8de
-1, 16, 16, 1, 2304, 0x4807a2b3
0, 13, 13, 1, 10800, 0xde75213a
-1, 17, 17, 1, 2304, 0x4643be06
+1, 16, 16, 1, 2304, 0x4807a2b3
0, 14, 14, 1, 11236, 0x9387cc8e
-1, 18, 18, 1, 2304, 0x5bd9d249
+1, 17, 17, 1, 2304, 0x4643be06
0, 15, 15, 1, 11420, 0x3a7d321b
-1, 19, 19, 1, 2304, 0x4e33c2bc
+1, 18, 18, 1, 2304, 0x5bd9d249
0, 16, 16, 1, 11632, 0x7edc9cdf
+1, 19, 19, 1, 2304, 0x4e33c2bc
+0, 17, 17, 1, 11936, 0xf0521017
1, 20, 20, 1, 2304, 0x085ca51d
1, 21, 21, 1, 2304, 0xa205b202
-0, 17, 17, 1, 11936, 0xf0521017
-1, 22, 22, 1, 2304, 0x71b9bcca
0, 18, 18, 1, 11804, 0x53b22066
-1, 23, 23, 1, 2304, 0xcb769e5f
+1, 22, 22, 1, 2304, 0x71b9bcca
0, 19, 19, 1, 11852, 0x9425fb21
-1, 24, 24, 1, 2304, 0x9322d85a
+1, 23, 23, 1, 2304, 0xcb769e5f
0, 20, 20, 1, 12108, 0xc386941d
+1, 24, 24, 1, 2304, 0x9322d85a
+0, 21, 21, 1, 12796, 0x8b7e5dab
1, 25, 25, 1, 2304, 0x7f13bf6e
+0, 22, 22, 1, 13316, 0x81235102
1, 26, 26, 1, 2304, 0xd302a5cd
-0, 21, 21, 1, 12796, 0x8b7e5dab
+0, 23, 23, 1, 13724, 0xe5fc2bca
1, 27, 27, 1, 2304, 0x7a7a9e30
-0, 22, 22, 1, 13316, 0x81235102
1, 28, 28, 1, 2304, 0x6ffccfdd
-0, 23, 23, 1, 13724, 0xe5fc2bca
-1, 29, 29, 1, 2304, 0xae88bf7a
0, 24, 24, 1, 14304, 0xa5b1f811
+1, 29, 29, 1, 2304, 0xae88bf7a
+0, 25, 25, 1, 15216, 0xf4996763
1, 30, 30, 1, 2304, 0xf816c2f5
+0, 26, 26, 1, 16224, 0xe30b0679
1, 31, 31, 1, 2304, 0xdb42a783
-0, 25, 25, 1, 15216, 0xf4996763
+0, 27, 27, 1, 10640, 0xaeb122c9
1, 32, 32, 1, 2304, 0xfc55c021
-0, 26, 26, 1, 16224, 0xe30b0679
+0, 28, 28, 1, 11652, 0x087d18b1
1, 33, 33, 1, 2304, 0x9da68fc1
-0, 27, 27, 1, 10640, 0xaeb122c9
+0, 29, 29, 1, 12008, 0x1eeeac41
1, 34, 34, 1, 2304, 0x2f65bb0f
-0, 28, 28, 1, 11652, 0x087d18b1
1, 35, 35, 1, 2304, 0x6e5da2c7
+0, 30, 30, 1, 12344, 0x488c64ec
1, 36, 36, 1, 2304, 0xb0b0c5f8
-0, 29, 29, 1, 12008, 0x1eeeac41
+0, 31, 31, 1, 13004, 0x02a69339
1, 37, 37, 1, 2304, 0x32559dc6
-0, 30, 30, 1, 12344, 0x488c64ec
+0, 32, 32, 1, 14092, 0x348a7d3f
1, 38, 38, 1, 2304, 0x9168aed0
-0, 31, 31, 1, 13004, 0x02a69339
+0, 33, 33, 1, 15048, 0xa55ef200
1, 39, 39, 1, 2304, 0x32069bce
-0, 32, 32, 1, 14092, 0x348a7d3f
+0, 34, 34, 1, 16100, 0xac17de5b
1, 40, 40, 1, 2304, 0x763ca8e0
1, 41, 41, 1, 2304, 0x70c7a44e
-0, 33, 33, 1, 15048, 0xa55ef200
+0, 35, 35, 1, 13180, 0x4d874f61
1, 42, 42, 1, 2304, 0x7dc1b275
-0, 34, 34, 1, 16100, 0xac17de5b
+0, 36, 36, 1, 14592, 0x5f58f505
1, 43, 43, 1, 2304, 0x2e26ceae
-0, 35, 35, 1, 13180, 0x4d874f61
+0, 37, 37, 1, 14372, 0x369bb5d9
1, 44, 44, 1, 2304, 0xa071a7e2
-0, 36, 36, 1, 14592, 0x5f58f505
+0, 38, 38, 1, 16172, 0x513a97b6
1, 45, 45, 1, 2304, 0xe434ad92
+0, 39, 39, 1, 15136, 0x7f9a3865
1, 46, 46, 1, 2304, 0xb4469381
-0, 37, 37, 1, 14372, 0x369bb5d9
+0, 40, 40, 1, 16336, 0x1339ba5f
1, 47, 47, 1, 2304, 0x3f20a7c5
-0, 38, 38, 1, 16172, 0x513a97b6
1, 48, 48, 1, 2304, 0x68ef9ef9
-0, 39, 39, 1, 15136, 0x7f9a3865
+0, 41, 41, 1, 16944, 0x122f71b7
1, 49, 49, 1, 2304, 0x32dbb3e2
-0, 40, 40, 1, 16336, 0x1339ba5f
+0, 42, 42, 1, 17536, 0x7461b152
1, 50, 50, 1, 2304, 0xdd90c7c3
+0, 43, 43, 1, 13940, 0xf5278274
1, 51, 51, 1, 2304, 0xd106adb5
-0, 41, 41, 1, 16944, 0x122f71b7
+0, 44, 44, 1, 8592, 0x4bb2eaea
1, 52, 52, 1, 2304, 0x11dca8c4
-0, 42, 42, 1, 17536, 0x7461b152
+0, 45, 45, 1, 8584, 0x2ff1e3db
1, 53, 53, 1, 2304, 0x646d98bc
-0, 43, 43, 1, 13940, 0xf5278274
+0, 46, 46, 1, 8548, 0xadfd01b4
1, 54, 54, 1, 2304, 0x6f019e81
-0, 44, 44, 1, 8592, 0x4bb2eaea
1, 55, 55, 1, 2304, 0xc872a896
+0, 47, 47, 1, 8548, 0x9e2ec85f
1, 56, 56, 1, 2304, 0xc7d7a0bc
-0, 45, 45, 1, 8584, 0x2ff1e3db
+0, 48, 48, 1, 8540, 0x9e2ad166
1, 57, 57, 1, 2304, 0x181b880a
-0, 46, 46, 1, 8548, 0xadfd01b4
+0, 49, 49, 1, 8524, 0x047bc406
1, 58, 58, 1, 2304, 0x6486b158
-0, 47, 47, 1, 8548, 0x9e2ec85f
+0, 50, 50, 1, 8508, 0xd051ddbb
1, 59, 59, 1, 2304, 0x26d5a3db
-0, 48, 48, 1, 8540, 0x9e2ad166
+0, 51, 51, 1, 8572, 0x40b5004c
1, 60, 60, 1, 2304, 0x4ff89a4d
+0, 52, 52, 1, 8564, 0xb379db59
1, 61, 61, 1, 2304, 0xc42e9552
-0, 49, 49, 1, 8524, 0x047bc406
1, 62, 62, 1, 2304, 0x0dc1c346
-0, 50, 50, 1, 8508, 0xd051ddbb
+0, 53, 53, 1, 8592, 0x22d0bc35
1, 63, 63, 1, 2304, 0x5e51b7a5
-0, 51, 51, 1, 8572, 0x40b5004c
+0, 54, 54, 1, 8656, 0xa58917d5
1, 64, 64, 1, 2304, 0xbd49c142
-0, 52, 52, 1, 8564, 0xb379db59
+0, 55, 55, 1, 8616, 0xc9e4f431
1, 65, 65, 1, 2304, 0x373da274
+0, 56, 56, 1, 8660, 0x7a90ffd1
1, 66, 66, 1, 2304, 0xde97b1bb
-0, 53, 53, 1, 8592, 0x22d0bc35
+0, 57, 57, 1, 8636, 0xec8ce437
1, 67, 67, 1, 2304, 0x9715bf29
-0, 54, 54, 1, 8656, 0xa58917d5
+0, 58, 58, 1, 8668, 0x8b73139f
1, 68, 68, 1, 2304, 0xc341b4ef
-0, 55, 55, 1, 8616, 0xc9e4f431
1, 69, 69, 1, 2304, 0xc610adc6
-0, 56, 56, 1, 8660, 0x7a90ffd1
+0, 59, 59, 1, 8640, 0x3ee30f9c
1, 70, 70, 1, 2304, 0x67bba315
+0, 60, 60, 1, 8728, 0xdbe12a94
1, 71, 71, 1, 2304, 0x949b9c16
-0, 57, 57, 1, 8636, 0xec8ce437
+0, 61, 61, 1, 8748, 0xc4132fd5
1, 72, 72, 1, 2304, 0xc7c1a8ca
-0, 58, 58, 1, 8668, 0x8b73139f
+0, 62, 62, 1, 8720, 0x7ac9316a
1, 73, 73, 1, 2304, 0x1929bc7e
-0, 59, 59, 1, 8640, 0x3ee30f9c
+0, 63, 63, 1, 8756, 0xf47d843d
1, 74, 74, 1, 2304, 0x5fc97897
-0, 60, 60, 1, 8728, 0xdbe12a94
+0, 64, 64, 1, 8840, 0x82808e79
1, 75, 75, 1, 2304, 0x272da8d3
1, 76, 76, 1, 2304, 0x141e904d
-0, 61, 61, 1, 8748, 0xc4132fd5
+0, 65, 65, 1, 8908, 0x63568647
1, 77, 77, 1, 2304, 0x9880b0ed
-0, 62, 62, 1, 8720, 0x7ac9316a
+0, 66, 66, 1, 8968, 0xbd26de31
1, 78, 78, 1, 2304, 0x0438932a
-0, 63, 63, 1, 8756, 0xf47d843d
+0, 67, 67, 1, 9168, 0xe1cd43a3
1, 79, 79, 1, 2304, 0x27069761
-0, 64, 64, 1, 8840, 0x82808e79
+0, 68, 68, 1, 9272, 0x0cc64c79
1, 80, 80, 1, 2304, 0x0baba2b7
+0, 69, 69, 1, 9700, 0x5cd2be73
1, 81, 81, 1, 2304, 0x4bc491af
-0, 65, 65, 1, 8908, 0x63568647
1, 82, 82, 1, 2304, 0x72e18e82
-0, 66, 66, 1, 8968, 0xbd26de31
+0, 70, 70, 1, 9868, 0x9b1629ae
1, 83, 83, 1, 2304, 0xf85d8a91
-0, 67, 67, 1, 9168, 0xe1cd43a3
+0, 71, 71, 1, 10264, 0xa13cb7db
1, 84, 84, 1, 2304, 0x653582e3
-0, 68, 68, 1, 9272, 0x0cc64c79
+0, 72, 72, 1, 10908, 0xe995858e
1, 85, 85, 1, 2304, 0x6b5e8084
+0, 73, 73, 1, 11272, 0xebea53f6
1, 86, 86, 1, 2304, 0x8cc27d10
-0, 69, 69, 1, 9700, 0x5cd2be73
+0, 74, 74, 1, 12128, 0xdfa8b7aa
1, 87, 87, 1, 2304, 0xcf8f9e1d
-0, 70, 70, 1, 9868, 0x9b1629ae
+0, 75, 75, 1, 12560, 0x46048576
1, 88, 88, 1, 2304, 0xecbe89df
-0, 71, 71, 1, 10264, 0xa13cb7db
1, 89, 89, 1, 2304, 0xa433753d
-0, 72, 72, 1, 10908, 0xe995858e
+0, 76, 76, 1, 12900, 0x5b3aeb76
1, 90, 90, 1, 2304, 0xe386afe9
+0, 77, 77, 1, 13544, 0x0f98fb94
1, 91, 91, 1, 2304, 0x90409771
-0, 73, 73, 1, 11272, 0xebea53f6
+0, 78, 78, 1, 13968, 0x7c17c4c2
1, 92, 92, 1, 2304, 0x29c88ae5
-0, 74, 74, 1, 12128, 0xdfa8b7aa
+0, 79, 79, 1, 15020, 0xe8faa930
1, 93, 93, 1, 2304, 0x900b9e6a
-0, 75, 75, 1, 12560, 0x46048576
+0, 80, 80, 1, 16152, 0x3f004f78
1, 94, 94, 1, 2304, 0x958cbb49
-0, 76, 76, 1, 12900, 0x5b3aeb76
+0, 81, 81, 1, 17224, 0x103f3935
1, 95, 95, 1, 2304, 0xf83da537
1, 96, 96, 1, 2304, 0x5fad9e5f
-0, 77, 77, 1, 13544, 0x0f98fb94
+0, 82, 82, 1, 11956, 0x7af9354a
1, 97, 97, 1, 2304, 0xae15902a
-0, 78, 78, 1, 13968, 0x7c17c4c2
+0, 83, 83, 1, 12644, 0xe113a4b2
1, 98, 98, 1, 2304, 0xf2a8b9d8
-0, 79, 79, 1, 15020, 0xe8faa930
+0, 84, 84, 1, 13420, 0xdf3ec8a4
1, 99, 99, 1, 2304, 0x7bc99f71
-0, 80, 80, 1, 16152, 0x3f004f78
+0, 85, 85, 1, 14140, 0x0ad8a165
1, 100, 100, 1, 2304, 0x3f199672
+0, 86, 86, 1, 15192, 0xc55f45cd
1, 101, 101, 1, 2304, 0x4e258c38
-0, 81, 81, 1, 17224, 0x103f3935
+0, 87, 87, 1, 12740, 0xa13c85db
1, 102, 102, 1, 2304, 0x5119b909
-0, 82, 82, 1, 11956, 0x7af9354a
1, 103, 103, 1, 2304, 0xad57a533
-0, 83, 83, 1, 12644, 0xe113a4b2
+0, 88, 88, 1, 14416, 0x9e68b57d
1, 104, 104, 1, 2304, 0xe40eb453
-0, 84, 84, 1, 13420, 0xdf3ec8a4
1, 105, 105, 1, 2304, 0x502cc37e
1, 106, 106, 1, 2304, 0x5b7bae9a
-0, 85, 85, 1, 14140, 0x0ad8a165
1, 107, 107, 1, 2304, 0x0458a92d
-0, 86, 86, 1, 15192, 0xc55f45cd
1, 108, 108, 1, 2304, 0x1529aba8
-0, 87, 87, 1, 12740, 0xa13c85db
1, 109, 109, 1, 2304, 0x1a52a9d1
-0, 88, 88, 1, 14416, 0x9e68b57d
1, 110, 110, 1, 2304, 0x76a2a7c9
Test psx-str-demux failed. Look at tests/data/fate/psx-str-demux.err for details.
tests/Makefile:312: recipe for target 'fate-psx-str-demux' failed
make: *** [fate-psx-str-demux] Error 1


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

It is dangerous to be right in matters on which the established authorities
are wrong. -- Voltaire
Michael Niedermayer Jan. 10, 2024, 2:56 a.m. UTC | #3
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>
> ---
>   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

[...]
aybe aybe Jan. 13, 2024, 2:05 a.m. UTC | #4
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.
diff mbox series

Patch

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;