Added code to save avi files in base folder.

This commit is contained in:
mjbudd77 2021-04-30 16:26:54 -04:00
parent ec33153e88
commit 22523076de
3 changed files with 67 additions and 13 deletions

View File

@ -265,6 +265,44 @@ int aviRecordOpenFile( const char *filepath )
char fourcc[8]; char fourcc[8];
gwavi_audio_t audioConfig; gwavi_audio_t audioConfig;
unsigned int fps; unsigned int fps;
char fileName[1024];
if ( filepath != NULL )
{
strcpy( fileName, filepath );
}
else
{
const char *romFile;
romFile = getRomFile();
if ( romFile )
{
char base[512];
const char *baseDir = FCEUI_GetBaseDirectory();
getFileBaseName( romFile, base );
if ( baseDir )
{
strcpy( fileName, baseDir );
strcat( fileName, "/avi/" );
}
else
{
fileName[0] = 0;
}
strcat( fileName, base );
strcat( fileName, ".avi");
//printf("AVI Filepath:'%s'\n", fileName );
}
else
{
return -1;
}
}
if ( gwavi != NULL ) if ( gwavi != NULL )
{ {
@ -292,7 +330,7 @@ int aviRecordOpenFile( const char *filepath )
gwavi = new gwavi_t(); gwavi = new gwavi_t();
if ( gwavi->open( filepath, nes_shm->video.ncol, nes_shm->video.nrow, fourcc, fps, &audioConfig ) ) if ( gwavi->open( fileName, nes_shm->video.ncol, nes_shm->video.nrow, fourcc, fps, &audioConfig ) )
{ {
printf("Error: Failed to open AVI file.\n"); printf("Error: Failed to open AVI file.\n");
recordEnable = false; recordEnable = false;
@ -438,7 +476,7 @@ void AviRecordDiskThread_t::run(void)
int16_t audioOut[48000]; int16_t audioOut[48000];
uint32_t videoOut[1048576]; uint32_t videoOut[1048576];
char writeAudio = 1; char writeAudio = 1;
int avgAudioPerFrame; int avgAudioPerFrame, localVideoFormat;
printf("AVI Record Disk Start\n"); printf("AVI Record Disk Start\n");
@ -454,13 +492,25 @@ void AviRecordDiskThread_t::run(void)
height = nes_shm->video.nrow; height = nes_shm->video.nrow;
numPixels = width * height; numPixels = width * height;
rgb24 = (unsigned char *)malloc( numPixels * sizeof(uint32_t) );
if ( rgb24 )
{
memset( rgb24, 0, numPixels * sizeof(uint32_t) );
}
else
{
// Error allocating buffer.
return;
}
localVideoFormat = videoFormat;
#ifdef _USE_X264 #ifdef _USE_X264
if ( videoFormat == 2) if ( localVideoFormat == 2)
{ {
X264::init( width, height ); X264::init( width, height );
} }
#endif #endif
rgb24 = (unsigned char *)malloc( numPixels * sizeof(uint32_t) );
while ( !isInterruptionRequested() ) while ( !isInterruptionRequested() )
{ {
@ -478,13 +528,13 @@ void AviRecordDiskThread_t::run(void)
writeAudio = 1; writeAudio = 1;
if ( videoFormat == 1) if ( localVideoFormat == 1)
{ {
Convert_4byte_To_I420Frame<4>(videoOut,rgb24,numPixels,width); Convert_4byte_To_I420Frame<4>(videoOut,rgb24,numPixels,width);
gwavi->add_frame( rgb24, (numPixels*3)/2 ); gwavi->add_frame( rgb24, (numPixels*3)/2 );
} }
#ifdef _USE_X264 #ifdef _USE_X264
else if ( videoFormat == 2) else if ( localVideoFormat == 2)
{ {
Convert_4byte_To_I420Frame<4>(videoOut,rgb24,numPixels,width); Convert_4byte_To_I420Frame<4>(videoOut,rgb24,numPixels,width);
X264::encode_frame( rgb24, width, height ); X264::encode_frame( rgb24, width, height );
@ -533,7 +583,7 @@ void AviRecordDiskThread_t::run(void)
free(rgb24); free(rgb24);
#ifdef _USE_X264 #ifdef _USE_X264
if ( videoFormat == 2) if ( localVideoFormat == 2)
{ {
X264::close(); X264::close();
} }

View File

@ -3104,7 +3104,7 @@ void consoleWin_t::recordMovieAs(void)
void consoleWin_t::aviOpen(void) void consoleWin_t::aviOpen(void)
{ {
printf("AVI!!!\n"); //printf("AVI!!!\n");
if ( aviRecordRunning() ) if ( aviRecordRunning() )
{ {
fceuWrapperLock(); fceuWrapperLock();
@ -3116,7 +3116,7 @@ void consoleWin_t::aviOpen(void)
else else
{ {
fceuWrapperLock(); fceuWrapperLock();
aviRecordOpenFile( "/tmp/test.avi" ); aviRecordOpenFile(NULL);
aviDiskThread->start(); aviDiskThread->start();
fceuWrapperUnLock(); fceuWrapperUnLock();
} }

View File

@ -335,22 +335,26 @@ LoadCPalette(const std::string &file)
static void static void
CreateDirs(const std::string &dir) CreateDirs(const std::string &dir)
{ {
const char *subs[9]={"fcs","snaps","gameinfo","sav","cheats","movies","input"}; const char *subs[]={"fcs","snaps","gameinfo","sav","cheats","avi", "movies","input", NULL };
std::string subdir; std::string subdir;
int x; int x=0;
#if defined(WIN32) || defined(NEED_MINGW_HACKS) #if defined(WIN32) || defined(NEED_MINGW_HACKS)
mkdir(dir.c_str()); mkdir(dir.c_str());
chmod(dir.c_str(), 755); chmod(dir.c_str(), 755);
for(x = 0; x < 7; x++) { while ( subs[x] != NULL )
{
subdir = dir + PSS + subs[x]; subdir = dir + PSS + subs[x];
mkdir(subdir.c_str()); mkdir(subdir.c_str());
x++;
} }
#else #else
mkdir(dir.c_str(), S_IRWXU); mkdir(dir.c_str(), S_IRWXU);
for(x = 0; x < 7; x++) { while ( subs[x] != NULL )
{
subdir = dir + PSS + subs[x]; subdir = dir + PSS + subs[x];
mkdir(subdir.c_str(), S_IRWXU); mkdir(subdir.c_str(), S_IRWXU);
x++;
} }
#endif #endif
} }