From ba5be09a283df93d59a4ef510c411a1b33bdc3db Mon Sep 17 00:00:00 2001 From: mjbudd77 Date: Fri, 20 Aug 2021 16:27:30 -0400 Subject: [PATCH] Fix for Qt AVI encoding of dwRate and dwScale in the stream header. --- src/drivers/Qt/AviRecord.cpp | 11 ++++++----- src/drivers/Qt/avi/gwavi.cpp | 25 +++++++++++++++++-------- src/drivers/Qt/avi/gwavi.h | 4 ++-- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/drivers/Qt/AviRecord.cpp b/src/drivers/Qt/AviRecord.cpp index 70ee6a86..0d042f11 100644 --- a/src/drivers/Qt/AviRecord.cpp +++ b/src/drivers/Qt/AviRecord.cpp @@ -444,7 +444,7 @@ int aviRecordOpenFile( const char *filepath ) { char fourcc[8]; gwavi_audio_t audioConfig; - unsigned int fps; + double fps; char fileName[1024]; #ifdef WIN32 @@ -519,7 +519,7 @@ int aviRecordOpenFile( const char *filepath ) { delete gwavi; gwavi = NULL; } - fps = FCEUI_GetDesiredFPS() >> 24; + fps = ((double)FCEUI_GetDesiredFPS()) / 16777216.0; g_config->getOption("SDL.Sound.Rate", &audioSampleRate); @@ -770,7 +770,8 @@ AviRecordDiskThread_t::~AviRecordDiskThread_t(void) void AviRecordDiskThread_t::run(void) { int numPixels, width, height, numPixelsReady = 0; - int fps = 60, numSamples = 0; + int numSamples = 0; + double fps = 60.0; unsigned char *rgb24; int16_t *audioOut; uint32_t *videoOut; @@ -781,9 +782,9 @@ void AviRecordDiskThread_t::run(void) setPriority( QThread::HighestPriority ); - fps = FCEUI_GetDesiredFPS() >> 24; + fps = ((double)FCEUI_GetDesiredFPS()) / 16777216.0; - avgAudioPerFrame = (audioSampleRate / fps) + 1; + avgAudioPerFrame = ( audioSampleRate / fps) + 1; printf("Avg Audio Rate per Frame: %i \n", avgAudioPerFrame ); diff --git a/src/drivers/Qt/avi/gwavi.cpp b/src/drivers/Qt/avi/gwavi.cpp index 5bc3e3f7..259f3b15 100644 --- a/src/drivers/Qt/avi/gwavi.cpp +++ b/src/drivers/Qt/avi/gwavi.cpp @@ -91,9 +91,11 @@ gwavi_t::~gwavi_t(void) int gwavi_t::open(const char *filename, unsigned int width, unsigned int height, - const char *fourcc, unsigned int fps, struct gwavi_audio_t *audio) + const char *fourcc, double fps, struct gwavi_audio_t *audio) { int size = 0; + unsigned int usec; + memset( this->fourcc, 0, sizeof(this->fourcc) ); strcpy( this->fourcc, fourcc ); @@ -112,10 +114,12 @@ gwavi_t::open(const char *filename, unsigned int width, unsigned int height, perror("gwavi_open: failed to open file for writing"); return -1; } + usec = (unsigned int)(1000000.0 / fps); + printf("FPS: %f %u\n", fps, usec ); /* set avi header */ - avi_header.time_delay= 1000000 / fps; - avi_header.data_rate = width * height * 3; + avi_header.time_delay= usec; + avi_header.data_rate = width * height * 3 * (((unsigned int)fps)+1); avi_header.flags = 0x10; if (audio) @@ -156,8 +160,8 @@ gwavi_t::open(const char *filename, unsigned int width, unsigned int height, /* set stream header */ (void)strcpy(stream_header_v.data_type, "vids"); (void)memcpy(stream_header_v.codec, fourcc, 4); - stream_header_v.time_scale = 1; - stream_header_v.data_rate = fps; + stream_header_v.time_scale = usec; + stream_header_v.data_rate = 1000000; stream_header_v.buffer_size = size; stream_header_v.data_length = 0; @@ -498,10 +502,15 @@ fseek_failed: * @return 0 on success, -1 on error. */ int -gwavi_t::set_framerate(unsigned int fps) +gwavi_t::set_framerate(double fps) { - stream_header_v.data_rate = fps; - avi_header.time_delay = (10000000 / fps); + unsigned int usec; + + usec = (unsigned int)(1000000.0 / fps); + + stream_header_v.time_scale = usec; + stream_header_v.data_rate = 1000000; + avi_header.time_delay = usec; return 0; } diff --git a/src/drivers/Qt/avi/gwavi.h b/src/drivers/Qt/avi/gwavi.h index bf20738a..429f7298 100644 --- a/src/drivers/Qt/avi/gwavi.h +++ b/src/drivers/Qt/avi/gwavi.h @@ -118,7 +118,7 @@ class gwavi_t ~gwavi_t(void); int open(const char *filename, unsigned int width, - unsigned int height, const char *fourcc, unsigned int fps, + unsigned int height, const char *fourcc, double fps, struct gwavi_audio_t *audio); int close(void); @@ -131,7 +131,7 @@ class gwavi_t int set_size( unsigned int width, unsigned int height); - int set_framerate(unsigned int fps); + int set_framerate(double fps); private: FILE *out;