dick around reverting ffmpeg 3.4 deprecations to try to get fps correct
This commit is contained in:
parent
bf1fbd169c
commit
0bb672b86b
|
@ -273,12 +273,15 @@ void zm_dump_stream_format(AVFormatContext *ic, int i, int index, int is_output)
|
||||||
/* the pid is an important information, so we display it */
|
/* the pid is an important information, so we display it */
|
||||||
/* XXX: add a generic system */
|
/* XXX: add a generic system */
|
||||||
if (flags & AVFMT_SHOW_IDS)
|
if (flags & AVFMT_SHOW_IDS)
|
||||||
Debug(1, "[0x%x]", st->id);
|
Debug(1, "ids [0x%x]", st->id);
|
||||||
if (lang)
|
if (lang)
|
||||||
Debug(1, "(%s)", lang->value);
|
Debug(1, "lang:%s", lang->value);
|
||||||
Debug(1, ", frames:%d, timebase: %d/%d", st->codec_info_nb_frames, st->time_base.num, st->time_base.den);
|
Debug(1, "frames:%d, stream timebase: %d/%d codec timebase: %d/%d",
|
||||||
|
st->codec_info_nb_frames, st->time_base.num, st->time_base.den,
|
||||||
|
st->codec->time_base.num, st->codec->time_base.den
|
||||||
|
);
|
||||||
avcodec_string(buf, sizeof(buf), st->codec, is_output);
|
avcodec_string(buf, sizeof(buf), st->codec, is_output);
|
||||||
Debug(1, ": %s", buf);
|
Debug(1, "codec: %s", buf);
|
||||||
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
|
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
|
||||||
AVCodecParameters *codec = st->codecpar;
|
AVCodecParameters *codec = st->codecpar;
|
||||||
#else
|
#else
|
||||||
|
@ -302,13 +305,10 @@ void zm_dump_stream_format(AVFormatContext *ic, int i, int index, int is_output)
|
||||||
int tbn = st->time_base.den && st->time_base.num;
|
int tbn = st->time_base.den && st->time_base.num;
|
||||||
int tbc = st->codec->time_base.den && st->codec->time_base.num;
|
int tbc = st->codec->time_base.den && st->codec->time_base.num;
|
||||||
|
|
||||||
if (fps || tbn || tbc)
|
|
||||||
Debug(3, "\n" );
|
|
||||||
|
|
||||||
if (fps)
|
if (fps)
|
||||||
zm_log_fps(av_q2d(st->avg_frame_rate), tbn || tbc ? "fps, " : "fps");
|
zm_log_fps(av_q2d(st->avg_frame_rate), "fps");
|
||||||
if (tbn)
|
if (tbn)
|
||||||
zm_log_fps(1 / av_q2d(st->time_base), tbc ? "stream tb numerator , " : "stream tb numerator");
|
zm_log_fps(1 / av_q2d(st->time_base), "stream tb numerator");
|
||||||
if (tbc)
|
if (tbc)
|
||||||
zm_log_fps(1 / av_q2d(st->codec->time_base), "codec time base:");
|
zm_log_fps(1 / av_q2d(st->codec->time_base), "codec time base:");
|
||||||
}
|
}
|
||||||
|
@ -333,7 +333,6 @@ void zm_dump_stream_format(AVFormatContext *ic, int i, int index, int is_output)
|
||||||
Debug(1, " (visual impaired)");
|
Debug(1, " (visual impaired)");
|
||||||
if (st->disposition & AV_DISPOSITION_CLEAN_EFFECTS)
|
if (st->disposition & AV_DISPOSITION_CLEAN_EFFECTS)
|
||||||
Debug(1, " (clean effects)");
|
Debug(1, " (clean effects)");
|
||||||
Debug(1, "\n");
|
|
||||||
|
|
||||||
//dump_metadata(NULL, st->metadata, " ");
|
//dump_metadata(NULL, st->metadata, " ");
|
||||||
|
|
||||||
|
|
|
@ -437,11 +437,13 @@ int FfmpegCamera::OpenFfmpeg() {
|
||||||
Debug(3, "Found audio stream at index %d", mAudioStreamId);
|
Debug(3, "Found audio stream at index %d", mAudioStreamId);
|
||||||
|
|
||||||
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
|
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
|
||||||
mVideoCodecContext = avcodec_alloc_context3(NULL);
|
//mVideoCodecContext = avcodec_alloc_context3(NULL);
|
||||||
avcodec_parameters_to_context( mVideoCodecContext, mFormatContext->streams[mVideoStreamId]->codecpar );
|
//avcodec_parameters_to_context( mVideoCodecContext, mFormatContext->streams[mVideoStreamId]->codecpar );
|
||||||
|
// this isn't copied.
|
||||||
|
//mVideoCodecContext->time_base = mFormatContext->streams[mVideoStreamId]->codec->time_base;
|
||||||
#else
|
#else
|
||||||
mVideoCodecContext = mFormatContext->streams[mVideoStreamId]->codec;
|
|
||||||
#endif
|
#endif
|
||||||
|
mVideoCodecContext = mFormatContext->streams[mVideoStreamId]->codec;
|
||||||
// STolen from ispy
|
// STolen from ispy
|
||||||
//this fixes issues with rtsp streams!! woot.
|
//this fixes issues with rtsp streams!! woot.
|
||||||
//mVideoCodecContext->flags2 |= CODEC_FLAG2_FAST | CODEC_FLAG2_CHUNKS | CODEC_FLAG_LOW_DELAY; // Enable faster H264 decode.
|
//mVideoCodecContext->flags2 |= CODEC_FLAG2_FAST | CODEC_FLAG2_CHUNKS | CODEC_FLAG_LOW_DELAY; // Enable faster H264 decode.
|
||||||
|
@ -484,16 +486,6 @@ int FfmpegCamera::OpenFfmpeg() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
#ifdef AV_CODEC_ID_H265
|
|
||||||
if ( mVideoCodecContext->codec_id == AV_CODEC_ID_H265 ) {
|
|
||||||
Debug( 1, "Input stream appears to be h265. The stored event file may not be viewable in browser." );
|
|
||||||
} else {
|
|
||||||
#endif
|
|
||||||
Warning( "Input stream is not h264. The stored event file may not be viewable in browser." );
|
|
||||||
#ifdef AV_CODEC_ID_H265
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
} // end if h264
|
} // end if h264
|
||||||
#endif
|
#endif
|
||||||
if ( mVideoCodecContext->codec_id == AV_CODEC_ID_H264 ) {
|
if ( mVideoCodecContext->codec_id == AV_CODEC_ID_H264 ) {
|
||||||
|
@ -511,29 +503,30 @@ int FfmpegCamera::OpenFfmpeg() {
|
||||||
} else {
|
} else {
|
||||||
Debug(1, "Video Found decoder %s", mVideoCodec->name);
|
Debug(1, "Video Found decoder %s", mVideoCodec->name);
|
||||||
zm_dump_stream_format(mFormatContext, mVideoStreamId, 0, 0);
|
zm_dump_stream_format(mFormatContext, mVideoStreamId, 0, 0);
|
||||||
// Open the codec
|
// Open the codec
|
||||||
#if !LIBAVFORMAT_VERSION_CHECK(53, 8, 0, 8, 0)
|
#if !LIBAVFORMAT_VERSION_CHECK(53, 8, 0, 8, 0)
|
||||||
Debug ( 1, "Calling avcodec_open" );
|
Debug(1, "Calling avcodec_open");
|
||||||
if ( avcodec_open(mVideoCodecContext, mVideoCodec) < 0 ){
|
if ( avcodec_open(mVideoCodecContext, mVideoCodec) < 0 )
|
||||||
#else
|
#else
|
||||||
Debug ( 1, "Calling avcodec_open2" );
|
Debug(1, "Calling avcodec_open2");
|
||||||
if ( avcodec_open2(mVideoCodecContext, mVideoCodec, &opts) < 0 ) {
|
if ( avcodec_open2(mVideoCodecContext, mVideoCodec, &opts) < 0 )
|
||||||
#endif
|
#endif
|
||||||
AVDictionaryEntry *e = NULL;
|
{
|
||||||
while ( (e = av_dict_get(opts, "", e, AV_DICT_IGNORE_SUFFIX)) != NULL ) {
|
AVDictionaryEntry *e = NULL;
|
||||||
Warning( "Option %s not recognized by ffmpeg", e->key);
|
while ( (e = av_dict_get(opts, "", e, AV_DICT_IGNORE_SUFFIX)) != NULL ) {
|
||||||
}
|
Warning( "Option %s not recognized by ffmpeg", e->key);
|
||||||
Error( "Unable to open codec for video stream from %s", mPath.c_str() );
|
}
|
||||||
av_dict_free(&opts);
|
Error( "Unable to open codec for video stream from %s", mPath.c_str() );
|
||||||
return -1;
|
av_dict_free(&opts);
|
||||||
} else {
|
return -1;
|
||||||
|
} else {
|
||||||
|
|
||||||
AVDictionaryEntry *e = NULL;
|
AVDictionaryEntry *e = NULL;
|
||||||
if ( (e = av_dict_get(opts, "", e, AV_DICT_IGNORE_SUFFIX)) != NULL ) {
|
if ( (e = av_dict_get(opts, "", e, AV_DICT_IGNORE_SUFFIX)) != NULL ) {
|
||||||
Warning( "Option %s not recognized by ffmpeg", e->key);
|
Warning( "Option %s not recognized by ffmpeg", e->key);
|
||||||
|
}
|
||||||
|
av_dict_free(&opts);
|
||||||
}
|
}
|
||||||
av_dict_free(&opts);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mVideoCodecContext->hwaccel != NULL) {
|
if (mVideoCodecContext->hwaccel != NULL) {
|
||||||
|
@ -653,8 +646,9 @@ int FfmpegCamera::Close() {
|
||||||
|
|
||||||
if ( mVideoCodecContext ) {
|
if ( mVideoCodecContext ) {
|
||||||
avcodec_close(mVideoCodecContext);
|
avcodec_close(mVideoCodecContext);
|
||||||
|
Debug(1,"After codec close");
|
||||||
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
|
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
|
||||||
avcodec_free_context(&mVideoCodecContext);
|
//avcodec_free_context(&mVideoCodecContext);
|
||||||
#endif
|
#endif
|
||||||
mVideoCodecContext = NULL; // Freed by av_close_input_file
|
mVideoCodecContext = NULL; // Freed by av_close_input_file
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,13 +39,13 @@ VideoStore::VideoStore(const char *filename_in, const char *format_in,
|
||||||
audio_in_stream = p_audio_in_stream;
|
audio_in_stream = p_audio_in_stream;
|
||||||
|
|
||||||
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
|
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
|
||||||
video_in_ctx = avcodec_alloc_context3(NULL);
|
//video_in_ctx = avcodec_alloc_context3(NULL);
|
||||||
avcodec_parameters_to_context(video_in_ctx,
|
//avcodec_parameters_to_context(video_in_ctx,
|
||||||
video_in_stream->codecpar);
|
//video_in_stream->codecpar);
|
||||||
// zm_dump_codecpar( video_in_stream->codecpar );
|
// zm_dump_codecpar( video_in_stream->codecpar );
|
||||||
#else
|
#else
|
||||||
video_in_ctx = video_in_stream->codec;
|
|
||||||
#endif
|
#endif
|
||||||
|
video_in_ctx = video_in_stream->codec;
|
||||||
|
|
||||||
// store ins in variables local to class
|
// store ins in variables local to class
|
||||||
filename = filename_in;
|
filename = filename_in;
|
||||||
|
@ -85,7 +85,8 @@ VideoStore::VideoStore(const char *filename_in, const char *format_in,
|
||||||
oc->metadata = pmetadata;
|
oc->metadata = pmetadata;
|
||||||
out_format = oc->oformat;
|
out_format = oc->oformat;
|
||||||
|
|
||||||
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
|
#if 0
|
||||||
|
//LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
|
||||||
|
|
||||||
// Since we are not re-encoding, all we have to do is copy the parameters
|
// Since we are not re-encoding, all we have to do is copy the parameters
|
||||||
video_out_ctx = avcodec_alloc_context3(NULL);
|
video_out_ctx = avcodec_alloc_context3(NULL);
|
||||||
|
@ -159,6 +160,20 @@ VideoStore::VideoStore(const char *filename_in, const char *format_in,
|
||||||
// Just copy them from the in, no reason to choose different
|
// Just copy them from the in, no reason to choose different
|
||||||
video_out_ctx->time_base = video_in_ctx->time_base;
|
video_out_ctx->time_base = video_in_ctx->time_base;
|
||||||
video_out_stream->time_base = video_in_stream->time_base;
|
video_out_stream->time_base = video_in_stream->time_base;
|
||||||
|
if ( video_in_stream->avg_frame_rate.num ) {
|
||||||
|
Debug(3,"Copying avg_frame_rate (%d/%d)",
|
||||||
|
video_in_stream->avg_frame_rate.num,
|
||||||
|
video_in_stream->avg_frame_rate.den
|
||||||
|
);
|
||||||
|
video_out_stream->avg_frame_rate = video_in_stream->avg_frame_rate;
|
||||||
|
}
|
||||||
|
if ( video_in_stream->r_frame_rate.num ) {
|
||||||
|
Debug(3,"Copying r_frame_rate (%d/%d)",
|
||||||
|
video_in_stream->r_frame_rate.num,
|
||||||
|
video_in_stream->r_frame_rate.den
|
||||||
|
);
|
||||||
|
video_out_stream->r_frame_rate = video_in_stream->r_frame_rate;
|
||||||
|
}
|
||||||
|
|
||||||
Debug(3,
|
Debug(3,
|
||||||
"Time bases: VIDEO in stream (%d/%d) in codec: (%d/%d) out "
|
"Time bases: VIDEO in stream (%d/%d) in codec: (%d/%d) out "
|
||||||
|
@ -166,8 +181,7 @@ VideoStore::VideoStore(const char *filename_in, const char *format_in,
|
||||||
video_in_stream->time_base.num, video_in_stream->time_base.den,
|
video_in_stream->time_base.num, video_in_stream->time_base.den,
|
||||||
video_in_ctx->time_base.num, video_in_ctx->time_base.den,
|
video_in_ctx->time_base.num, video_in_ctx->time_base.den,
|
||||||
video_out_stream->time_base.num, video_out_stream->time_base.den,
|
video_out_stream->time_base.num, video_out_stream->time_base.den,
|
||||||
video_out_ctx->time_base.num,
|
video_out_ctx->time_base.num, video_out_ctx->time_base.den);
|
||||||
video_out_ctx->time_base.den);
|
|
||||||
|
|
||||||
if (oc->oformat->flags & AVFMT_GLOBALHEADER) {
|
if (oc->oformat->flags & AVFMT_GLOBALHEADER) {
|
||||||
#if LIBAVCODEC_VERSION_CHECK(56, 35, 0, 64, 0)
|
#if LIBAVCODEC_VERSION_CHECK(56, 35, 0, 64, 0)
|
||||||
|
@ -324,7 +338,7 @@ bool VideoStore::open() {
|
||||||
|
|
||||||
AVDictionary *opts = NULL;
|
AVDictionary *opts = NULL;
|
||||||
// av_dict_set(&opts, "movflags", "frag_custom+dash+delay_moov", 0);
|
// av_dict_set(&opts, "movflags", "frag_custom+dash+delay_moov", 0);
|
||||||
// av_dict_set(&opts, "movflags", "frag_custom+dash+delay_moov", 0);
|
av_dict_set(&opts, "movflags", "frag_keyframe+empty_moov", 0);
|
||||||
// av_dict_set(&opts, "movflags",
|
// av_dict_set(&opts, "movflags",
|
||||||
// "frag_keyframe+empty_moov+default_base_moof", 0);
|
// "frag_keyframe+empty_moov+default_base_moof", 0);
|
||||||
if ((ret = avformat_write_header(oc, &opts)) < 0) {
|
if ((ret = avformat_write_header(oc, &opts)) < 0) {
|
||||||
|
@ -435,13 +449,13 @@ VideoStore::~VideoStore() {
|
||||||
if ( video_out_stream ) {
|
if ( video_out_stream ) {
|
||||||
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
|
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
|
||||||
// We allocate and copy in newer ffmpeg, so need to free it
|
// We allocate and copy in newer ffmpeg, so need to free it
|
||||||
avcodec_free_context(&video_in_ctx);
|
//avcodec_free_context(&video_in_ctx);
|
||||||
#endif
|
#endif
|
||||||
video_in_ctx = NULL;
|
video_in_ctx = NULL;
|
||||||
|
|
||||||
avcodec_close(video_out_ctx);
|
avcodec_close(video_out_ctx);
|
||||||
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
|
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
|
||||||
avcodec_free_context(&video_out_ctx);
|
//avcodec_free_context(&video_out_ctx);
|
||||||
#endif
|
#endif
|
||||||
video_out_ctx = NULL;
|
video_out_ctx = NULL;
|
||||||
Debug(4, "Success freeing video_out_ctx");
|
Debug(4, "Success freeing video_out_ctx");
|
||||||
|
|
Loading…
Reference in New Issue