From 622fff5a59791aa1c90a05cf8658b0cbe29913db Mon Sep 17 00:00:00 2001 From: MonoS Date: Thu, 23 Mar 2023 00:50:30 +0100 Subject: [PATCH 1/4] Better handle audio and video conversion Those are the changes made and the reasons: avi:rgb => avi:jyuv: as the documentations says "This is most similar to the original PlayStation video colors" add zscale: the PSX video are in a particular color space (full range, bt601, centered chroma location), but modern browser, AFAIK, will use the "full HD colorspace" (limited range, bt709, left chroma location), making this conversion at the encoding stage will make sure that browser will display correct colors and levels w=640:h=526: upscale the video and fix AR, i'm not quite sure regarding the AR, i've tested it using the preview from jpsxdec and counting pixels -crf 15: a bit of a quality boost, the videos are quite small anyway, it can be raised to lower quality/size -preset veryslow: quality boost at the expense of time, the video are short and at low resolution/framerate, it will take not much more -ar 44100: with default conversion ffmpeg was downsampling the 18.9KHz sound to 16KHz, also AAC use an internal lowpass filter so it was muffling the sound, this will upsample to 44.1KHz so that it will sound correctly -b:a 192k: a bit more bitrate for the sound, it can probably be lowered to 128k but i prefer a bit more as the original sounds are already quite compressed Regarding the videos a better job could be made introducing avs/vs in the mix, the original videos suffers quite a bit of blocking and Deblock_QED fix almost all of it with minimal/low loss of quality, also the upscale can be done using better algorithms like nnedi3 or a specifically trained ESRGAN model --- scripts/extract/extract_media.mjs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/scripts/extract/extract_media.mjs b/scripts/extract/extract_media.mjs index cf37e065..1aac93a1 100644 --- a/scripts/extract/extract_media.mjs +++ b/scripts/extract/extract_media.mjs @@ -19,7 +19,7 @@ export function extract_video(tempdir, jpsxdec_jar, no_delete) { "-quality", "high", "-vf", - "avi:rgb", + "avi:jyuv", "-up", "Lanczos3", ], @@ -51,6 +51,18 @@ export function extract_video(tempdir, jpsxdec_jar, no_delete) { "-pix_fmt", "yuv420p", "-n", + "-filter:v", + "zscale=w=640:h=526:dither=error_diffusion:filter=lanczos:rin=full:r=limited:tin=601:t=709:min=470bg:m=709:cin=center:c=left", + "-crf", + "15", + "-preset", + "veryslow", + "-level", + "31", + "-ar", + "44100", + "-b:a", + "192k", join(output_movie_folder, file.replace("avi", "mp4")), ], { stdio: "inherit" } @@ -102,6 +114,10 @@ export function extract_audio(tempdir, jpsxdec_jar, no_delete) { "-i", join(tempdir, "XA", file), "-n", + "-ar", + "44100", + "-b:a", + "192k", join(output_audio_folder, file.replace("wav", "mp4")), ], {stdio:'inherit'}); } From ab197dcb769a618726ebbdaa1adb17c2a6849998 Mon Sep 17 00:00:00 2001 From: MonoS Date: Thu, 23 Mar 2023 10:35:00 +0100 Subject: [PATCH 2/4] Use correct AR I think a better way to check the AR is to execute the game in an emulator and count the pixel here, there i found two resolution 291*224 and 291.5*224 (i used duckstation x4 zoom), then i found an integer mod2 resolution soutable, 582*448 is the first one --- scripts/extract/extract_media.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/extract/extract_media.mjs b/scripts/extract/extract_media.mjs index 1aac93a1..85101c58 100644 --- a/scripts/extract/extract_media.mjs +++ b/scripts/extract/extract_media.mjs @@ -52,7 +52,7 @@ export function extract_video(tempdir, jpsxdec_jar, no_delete) { "yuv420p", "-n", "-filter:v", - "zscale=w=640:h=526:dither=error_diffusion:filter=lanczos:rin=full:r=limited:tin=601:t=709:min=470bg:m=709:cin=center:c=left", + "zscale=w=582:h=448:dither=error_diffusion:filter=lanczos:rin=full:r=limited:tin=601:t=709:min=470bg:m=709:cin=center:c=left", "-crf", "15", "-preset", From 1149ac92bbd8a8b8cc56608128d97d1ebc0a74f8 Mon Sep 17 00:00:00 2001 From: MonoS Date: Thu, 23 Mar 2023 13:02:15 +0100 Subject: [PATCH 3/4] Add primaries conversion JPG, and so the PSX format should, use the color primaries specified by Rec.601 standard https://en.wikipedia.org/wiki/Rec._601 , there are two version of this standard, PAL and NTSC, i expect it to use the NTSC version, so the one called SMPTE 170M I forgot to check it yesterday --- scripts/extract/extract_media.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/extract/extract_media.mjs b/scripts/extract/extract_media.mjs index 85101c58..ea85f344 100644 --- a/scripts/extract/extract_media.mjs +++ b/scripts/extract/extract_media.mjs @@ -52,7 +52,7 @@ export function extract_video(tempdir, jpsxdec_jar, no_delete) { "yuv420p", "-n", "-filter:v", - "zscale=w=582:h=448:dither=error_diffusion:filter=lanczos:rin=full:r=limited:tin=601:t=709:min=470bg:m=709:cin=center:c=left", + "zscale=w=582:h=448:dither=error_diffusion:filter=lanczos:rin=full:r=limited:tin=601:t=709:min=470bg:m=709:pin=170m:p=709:cin=center:c=left", "-crf", "15", "-preset", From 9c3f3f3caa51c15d89d494d1d50a24e7c9a33b88 Mon Sep 17 00:00:00 2001 From: MonoS Date: Sat, 25 Mar 2023 14:39:41 +0100 Subject: [PATCH 4/4] Do not fix AR for video Maybe my configuration of duckstation is wrong? I'll need to check --- scripts/extract/extract_media.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/extract/extract_media.mjs b/scripts/extract/extract_media.mjs index ea85f344..5d898bf1 100644 --- a/scripts/extract/extract_media.mjs +++ b/scripts/extract/extract_media.mjs @@ -52,7 +52,7 @@ export function extract_video(tempdir, jpsxdec_jar, no_delete) { "yuv420p", "-n", "-filter:v", - "zscale=w=582:h=448:dither=error_diffusion:filter=lanczos:rin=full:r=limited:tin=601:t=709:min=470bg:m=709:pin=170m:p=709:cin=center:c=left", + "zscale=dither=error_diffusion:filter=lanczos:rin=full:r=limited:tin=601:t=709:min=470bg:m=709:pin=170m:p=709:cin=center:c=left", "-crf", "15", "-preset",