guess format before allocating context

This commit is contained in:
Vlad Firoiu 2017-02-21 01:43:31 -08:00
parent 8fb2eb889d
commit 1723645c99
1 changed files with 16 additions and 15 deletions

View File

@ -98,21 +98,22 @@ bool AVIDump::CreateVideoFile()
{ {
AVCodec* codec = nullptr; AVCodec* codec = nullptr;
s_format_context = avformat_alloc_context(); const char s_format[] = "avi";
std::stringstream s_file_index_str;
s_file_index_str << s_file_index; std::stringstream file_ss;
snprintf(s_format_context->filename, sizeof(s_format_context->filename), "%s", file_ss << File::GetUserPath(D_DUMPFRAMES_IDX)
(File::GetUserPath(D_DUMPFRAMES_IDX) + "framedump" + s_file_index_str.str() + ".avi") << "framedump" << s_file_index
.c_str()); << "." << s_format;
File::CreateFullPath(s_format_context->filename); std::string filename = file_ss.str();
File::CreateFullPath(filename);
// Ask to delete file // Ask to delete file
if (File::Exists(s_format_context->filename)) if (File::Exists(filename))
{ {
if (SConfig::GetInstance().m_DumpFramesSilent || if (SConfig::GetInstance().m_DumpFramesSilent ||
AskYesNoT("Delete the existing file '%s'?", s_format_context->filename)) AskYesNoT("Delete the existing file '%s'?", filename.c_str()))
{ {
File::Delete(s_format_context->filename); File::Delete(filename);
} }
else else
{ {
@ -121,13 +122,13 @@ bool AVIDump::CreateVideoFile()
} }
} }
if (!(s_format_context->oformat = av_guess_format("avi", nullptr, nullptr))) AVOutputFormat* output_format = av_guess_format(s_format, filename.c_str(), nullptr);
{ if (!output_format) return false;
return false; avformat_alloc_output_context2(&s_format_context, output_format, nullptr, filename.c_str());
}
AVCodecID codec_id = AVCodecID codec_id =
g_Config.bUseFFV1 ? AV_CODEC_ID_FFV1 : s_format_context->oformat->video_codec; g_Config.bUseFFV1 ? AV_CODEC_ID_FFV1 : output_format->video_codec;
if (!(codec = avcodec_find_encoder(codec_id)) || if (!(codec = avcodec_find_encoder(codec_id)) ||
!(s_codec_context = avcodec_alloc_context3(codec))) !(s_codec_context = avcodec_alloc_context3(codec)))
{ {