Add a default timebase if the codec timebase is invalid. Also fix crash when we can't open the .mp4

pull/2224/head
Isaac Connor 2018-09-26 15:34:01 -04:00
parent 1419f20dcc
commit 51f0e7e5c8
1 changed files with 13 additions and 6 deletions

View File

@ -127,7 +127,8 @@ VideoStore::VideoStore(const char *filename_in, const char *format_in,
#else
video_out_stream =
avformat_new_stream(oc,(AVCodec *)(video_in_ctx->codec));
avformat_new_stream(oc, NULL);
//(AVCodec *)(video_in_ctx->codec));
//avformat_new_stream(oc,(const AVCodec *)(video_in_ctx->codec));
if ( !video_out_stream ) {
Fatal("Unable to create video out stream\n");
@ -158,6 +159,9 @@ VideoStore::VideoStore(const char *filename_in, const char *format_in,
// Just copy them from the in, no reason to choose different
video_out_ctx->time_base = video_in_ctx->time_base;
if ( ! (video_out_ctx->time_base.num && video_out_ctx->time_base.den) ) {
video_out_ctx->time_base = AV_TIME_BASE_Q;
}
video_out_stream->time_base = video_in_stream->time_base;
Debug(3,
@ -339,6 +343,9 @@ bool VideoStore::open() {
if (ret < 0) {
Error("Error occurred when writing out file header to %s: %s\n",
filename, av_make_error_string(ret).c_str());
/* free the stream */
avio_closep(&oc->pb);
//avformat_free_context(oc);
return false;
}
return true;
@ -412,7 +419,7 @@ VideoStore::~VideoStore() {
if (int rc = av_write_trailer(oc)) {
Error("Error writing trailer %s", av_err2str(rc));
} else {
Debug(3, "Sucess Writing trailer");
Debug(3, "Success Writing trailer");
}
// When will we not be using a file ?
@ -426,7 +433,7 @@ VideoStore::~VideoStore() {
} else {
Debug(3, "Not closing avio because we are not writing to a file.");
}
}
} // end if ( oc->pb )
// I wonder if we should be closing the file first.
// I also wonder if we really need to be doing all the ctx
// allocation/de-allocation constantly, or whether we can just re-use it.