implement some checks for valid values when opening the output file

This commit is contained in:
Isaac Connor 2016-07-13 15:29:29 -04:00
parent df6aaf5dec
commit b7096b742d
1 changed files with 22 additions and 6 deletions

View File

@ -39,8 +39,6 @@ VideoStore::VideoStore(const char *filename_in, const char *format_in,
Monitor::Orientation orientation Monitor::Orientation orientation
) { ) {
AVDictionary *pmetadata = NULL;
int dsr;
//store inputs in variables local to class //store inputs in variables local to class
filename = filename_in; filename = filename_in;
@ -49,10 +47,10 @@ VideoStore::VideoStore(const char *filename_in, const char *format_in,
keyframeMessage = false; keyframeMessage = false;
keyframeSkipNumber = 0; keyframeSkipNumber = 0;
Info("Opening video storage stream %s format: %d\n", filename, format); Info("Opening video storage stream %s format: %s\n", filename, format);
//Init everything we need
int ret; int ret;
//Init everything we need
av_register_all(); av_register_all();
ret = avformat_alloc_output_context2(&oc, NULL, NULL, filename); ret = avformat_alloc_output_context2(&oc, NULL, NULL, filename);
@ -74,7 +72,8 @@ VideoStore::VideoStore(const char *filename_in, const char *format_in,
} }
} }
dsr = av_dict_set(&pmetadata, "title", "Zoneminder Security Recording", 0); AVDictionary *pmetadata = NULL;
int dsr = av_dict_set(&pmetadata, "title", "Zoneminder Security Recording", 0);
if (dsr < 0) Warning("%s:%d: title set failed", __FILE__, __LINE__ ); if (dsr < 0) Warning("%s:%d: title set failed", __FILE__, __LINE__ );
oc->metadata = pmetadata; oc->metadata = pmetadata;
@ -92,6 +91,23 @@ VideoStore::VideoStore(const char *filename_in, const char *format_in,
av_make_error_string(ret).c_str()); av_make_error_string(ret).c_str());
} }
if ( video_st->sample_aspect_ratio.den != video_st->codec->sample_aspect_ratio.den ) {
Warning("Fixingample_aspect_ratio.den");
video_st->sample_aspect_ratio.den = video_st->codec->sample_aspect_ratio.den;
}
if ( video_st->sample_aspect_ratio.num != input_st->codec->sample_aspect_ratio.num ) {
Warning("Fixingample_aspect_ratio.num");
video_st->sample_aspect_ratio.num = input_st->codec->sample_aspect_ratio.num;
}
if ( video_st->codec->codec_id != input_st->codec->codec_id ) {
Warning("Fixing video_st->codec->codec_id");
video_st->codec->codec_id = input_st->codec->codec_id;
}
if ( ! video_st->codec->time_base.num ) {
Warning("video_st->codec->time_base.num is not set. Fixing by setting it to 1");
video_st->codec->time_base.num = 1;
}
video_st->codec->codec_tag = 0; video_st->codec->codec_tag = 0;
if (oc->oformat->flags & AVFMT_GLOBALHEADER) { if (oc->oformat->flags & AVFMT_GLOBALHEADER) {
video_st->codec->flags |= CODEC_FLAG_GLOBAL_HEADER; video_st->codec->flags |= CODEC_FLAG_GLOBAL_HEADER;