Split Video Dumps on Resolution Change

This commit is contained in:
Chris Burgener
2016-06-24 22:41:10 -04:00
parent cbd6fda5e3
commit 88dbaf1fa5
2 changed files with 28 additions and 1 deletions

View File

@ -45,6 +45,10 @@ static int s_size;
static u64 s_last_frame; static u64 s_last_frame;
static bool s_start_dumping = false; static bool s_start_dumping = false;
static u64 s_last_pts; static u64 s_last_pts;
static int s_current_width;
static int s_current_height;
static int s_file_index = 0;
static AVIDump::DumpFormat s_current_format;
static void InitAVCodec() static void InitAVCodec()
{ {
@ -63,8 +67,12 @@ bool AVIDump::Start(int w, int h, DumpFormat format)
else else
s_pix_fmt = AV_PIX_FMT_RGBA; s_pix_fmt = AV_PIX_FMT_RGBA;
s_current_format = format;
s_width = w; s_width = w;
s_height = h; s_height = h;
s_current_width = w;
s_current_height = h;
s_last_frame = CoreTiming::GetTicks(); s_last_frame = CoreTiming::GetTicks();
s_last_pts = 0; s_last_pts = 0;
@ -81,8 +89,11 @@ bool AVIDump::CreateFile()
AVCodec* codec = nullptr; AVCodec* codec = nullptr;
s_format_context = avformat_alloc_context(); s_format_context = avformat_alloc_context();
std::stringstream s_file_index_str;
s_file_index_str << s_file_index;
snprintf(s_format_context->filename, sizeof(s_format_context->filename), "%s", snprintf(s_format_context->filename, sizeof(s_format_context->filename), "%s",
(File::GetUserPath(D_DUMPFRAMES_IDX) + "framedump0.avi").c_str()); (File::GetUserPath(D_DUMPFRAMES_IDX) + "framedump" + s_file_index_str.str() + ".avi")
.c_str());
File::CreateFullPath(s_format_context->filename); File::CreateFullPath(s_format_context->filename);
// Ask to delete file // Ask to delete file
@ -156,6 +167,7 @@ static void PreparePacket(AVPacket* pkt)
void AVIDump::AddFrame(const u8* data, int width, int height) void AVIDump::AddFrame(const u8* data, int width, int height)
{ {
CheckResolution(width, height);
avpicture_fill((AVPicture*)s_src_frame, const_cast<u8*>(data), s_pix_fmt, width, height); avpicture_fill((AVPicture*)s_src_frame, const_cast<u8*>(data), s_pix_fmt, width, height);
// Convert image from {BGR24, RGBA} to desired pixel format, and scale to initial // Convert image from {BGR24, RGBA} to desired pixel format, and scale to initial
@ -232,6 +244,7 @@ void AVIDump::Stop()
{ {
av_write_trailer(s_format_context); av_write_trailer(s_format_context);
CloseFile(); CloseFile();
s_file_index = 0;
NOTICE_LOG(VIDEO, "Stopping frame dump"); NOTICE_LOG(VIDEO, "Stopping frame dump");
} }
@ -273,3 +286,16 @@ void AVIDump::DoState()
{ {
s_last_frame = CoreTiming::GetTicks(); s_last_frame = CoreTiming::GetTicks();
} }
void AVIDump::CheckResolution(int width, int height)
{
if (width != s_current_width || height != s_current_height)
{
int temp_file_index = s_file_index;
Stop();
s_file_index = temp_file_index + 1;
Start(width, height, s_current_format);
s_current_width = width;
s_current_height = height;
}
}

View File

@ -11,6 +11,7 @@ class AVIDump
private: private:
static bool CreateFile(); static bool CreateFile();
static void CloseFile(); static void CloseFile();
static void CheckResolution(int width, int height);
public: public:
enum class DumpFormat enum class DumpFormat