From 67746af7b4ed52285114c0d8bdcf09618fb2fecf Mon Sep 17 00:00:00 2001 From: spicyjpeg Date: Tue, 16 May 2023 10:30:59 +0200 Subject: [PATCH] Fix colorspace conversion and sbs2 frame rate issues --- psxavenc/common.h | 1 - psxavenc/decoding.c | 16 +++++++++++----- psxavenc/filefmt.c | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/psxavenc/common.h b/psxavenc/common.h index 857031c..3408555 100644 --- a/psxavenc/common.h +++ b/psxavenc/common.h @@ -69,7 +69,6 @@ typedef struct { } vid_encoder_state_t; typedef struct { - int video_frame_src_size; int video_frame_dst_size; int audio_stream_index; int video_stream_index; diff --git a/psxavenc/decoding.c b/psxavenc/decoding.c index ac84e1c..56f25a4 100644 --- a/psxavenc/decoding.c +++ b/psxavenc/decoding.c @@ -48,7 +48,6 @@ bool open_av_data(const char *filename, settings_t *settings, bool use_audio, bo av_decoder_state_t* av = &(settings->decoder_state_av); av->video_next_pts = 0.0; av->frame = NULL; - av->video_frame_src_size = 0; av->video_frame_dst_size = 0; av->audio_stream_index = -1; av->video_stream_index = -1; @@ -202,8 +201,13 @@ bool open_av_data(const char *filename, settings_t *settings, bool use_audio, bo NULL, NULL ); - // Is this even necessary? -- spicyjpeg - sws_setColorspaceDetails( + if (av->scaler == NULL) { + return false; + } +#if 0 + // FIXME: if this is uncommented libswscale may produce completely black + // frames for whatever reason... + if (sws_setColorspaceDetails( av->scaler, sws_getCoefficients(av->video_codec_context->colorspace), (av->video_codec_context->color_range == AVCOL_RANGE_JPEG), @@ -212,14 +216,16 @@ bool open_av_data(const char *filename, settings_t *settings, bool use_audio, bo 0, 0, 0 - ); + ) < 0) { + return false; + } +#endif if (settings->swscale_options) { if (av_opt_set_from_string(av->scaler, settings->swscale_options, NULL, "=", ":,") < 0) { return false; } } - av->video_frame_src_size = 4*av->video_codec_context->width*av->video_codec_context->height; av->video_frame_dst_size = 3*settings->video_width*settings->video_height/2; } diff --git a/psxavenc/filefmt.c b/psxavenc/filefmt.c index 873b558..23c68cc 100644 --- a/psxavenc/filefmt.c +++ b/psxavenc/filefmt.c @@ -363,7 +363,7 @@ void encode_file_sbs(settings_t *settings, FILE *output) { settings->state_vid.frame_max_size = settings->alignment; settings->state_vid.quant_scale_sum = 0; - for (int j = 0; ensure_av_data(settings, 0, 1); j++) { + for (int j = 0; ensure_av_data(settings, 0, 2); j++) { encode_frame_bs(settings->video_frames, settings); fwrite(settings->state_vid.frame_output, settings->alignment, 1, output);