From da5438a6ff69f9a2fea0662585d4207cc3636426 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Wed, 16 Aug 2017 12:16:15 -0400 Subject: [PATCH] detect hardware accel capabilities --- CMakeLists.txt | 1 + src/zm_ffmpeg_camera.cpp | 14 ++++++++++++-- src/zm_videostore.cpp | 8 ++++++-- zoneminder-config.cmake | 1 + 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ad65d1f7..d4c0bba2b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -557,6 +557,7 @@ if(NOT ZM_NO_FFMPEG) mark_as_advanced(FORCE AVUTIL_LIBRARIES AVUTIL_INCLUDE_DIR) check_include_file("libavutil/avutil.h" HAVE_LIBAVUTIL_AVUTIL_H) check_include_file("libavutil/mathematics.h" HAVE_LIBAVUTIL_MATHEMATICS_H) + check_include_file("libavutil/hwcontext.h" HAVE_LIBAVUTIL_HWCONTEXT_H) set(optlibsfound "${optlibsfound} AVUtil") else(AVUTIL_LIBRARIES) set(optlibsnotfound "${optlibsnotfound} AVUtil") diff --git a/src/zm_ffmpeg_camera.cpp b/src/zm_ffmpeg_camera.cpp index f0548498e..1edc00c83 100644 --- a/src/zm_ffmpeg_camera.cpp +++ b/src/zm_ffmpeg_camera.cpp @@ -25,8 +25,10 @@ extern "C" { #include "libavutil/time.h" -#include "libavutil/hwcontext.h" -#include "libavutil/hwcontext_qsv.h" +#if HAVE_AVUTIL_HWCONTEXT_H + #include "libavutil/hwcontext.h" + #include "libavutil/hwcontext_qsv.h" +#endif } #ifndef AV_ERROR_MAX_STRING_SIZE #define AV_ERROR_MAX_STRING_SIZE 64 @@ -39,6 +41,7 @@ extern "C" { #endif +#if HAVE_AVUTIL_HWCONTEXT_H static AVPixelFormat get_format(AVCodecContext *avctx, const enum AVPixelFormat *pix_fmts) { while (*pix_fmts != AV_PIX_FMT_NONE) { if (*pix_fmts == AV_PIX_FMT_QSV) { @@ -76,6 +79,7 @@ static AVPixelFormat get_format(AVCodecContext *avctx, const enum AVPixelFormat return AV_PIX_FMT_NONE; } +#endif FfmpegCamera::FfmpegCamera( int p_id, const std::string &p_path, const std::string &p_method, const std::string &p_options, int p_width, int p_height, int p_colours, int p_brightness, int p_contrast, int p_hue, int p_colour, bool p_capture, bool p_record_audio ) : Camera( p_id, FFMPEG_SRC, p_width, p_height, p_colours, ZM_SUBPIX_ORDER_DEFAULT_FOR_COLOUR(p_colours), p_brightness, p_contrast, p_hue, p_colour, p_capture, p_record_audio ), @@ -234,6 +238,7 @@ int FfmpegCamera::Capture( Image &image ) { continue; } +#if HAVE_AVUTIL_HWCONTEXT_H if ( hwaccel ) { ret = avcodec_receive_frame( mVideoCodecContext, hwFrame ); if ( ret < 0 ) { @@ -250,6 +255,7 @@ int FfmpegCamera::Capture( Image &image ) { continue; } } else { +#endif ret = avcodec_receive_frame( mVideoCodecContext, mRawFrame ); if ( ret < 0 ) { av_strerror( ret, errbuf, AV_ERROR_MAX_STRING_SIZE ); @@ -258,7 +264,9 @@ int FfmpegCamera::Capture( Image &image ) { continue; } +#if HAVE_AVUTIL_HWCONTEXT_H } +#endif frameComplete = 1; # else @@ -461,6 +469,7 @@ int FfmpegCamera::OpenFfmpeg() { //mVideoCodecContext->flags2 |= CODEC_FLAG2_FAST | CODEC_FLAG2_CHUNKS | CODEC_FLAG_LOW_DELAY; // Enable faster H264 decode. mVideoCodecContext->flags2 |= CODEC_FLAG2_FAST | CODEC_FLAG_LOW_DELAY; +#if HAVE_AVUTIL_HWCONTEXT_H if ( mVideoCodecContext->codec_id == AV_CODEC_ID_H264 ) { //vaapi_decoder = new VAAPIDecoder(); @@ -497,6 +506,7 @@ int FfmpegCamera::OpenFfmpeg() { } } // end if h264 +#endif if ( (!mVideoCodec) and ( (mVideoCodec = avcodec_find_decoder(mVideoCodecContext->codec_id)) == NULL ) ) { // Try and get the codec from the codec context diff --git a/src/zm_videostore.cpp b/src/zm_videostore.cpp index b270649ca..cba27cef6 100644 --- a/src/zm_videostore.cpp +++ b/src/zm_videostore.cpp @@ -623,7 +623,7 @@ bool VideoStore::setup_resampler() { void VideoStore::dumpPacket( AVPacket *pkt ){ char b[10240]; - snprintf(b, sizeof(b), " pts: %" PRId64 ", dts: %" PRId64 ", data: %p, size: %d, sindex: %d, dflags: %04x, s-pos: %" PRId64 ", c-duration: %" PRId64 "\n" + snprintf(b, sizeof(b), " pts: %" PRId64 ", dts: %" PRId64 ", data: %p, size: %d, sindex: %d, dflags: %04x, s-pos: %" PRId64 ", c-duration: %d\n" , pkt->pts , pkt->dts , pkt->data @@ -643,12 +643,16 @@ int VideoStore::writeVideoFramePacket( AVPacket *ipkt ) { opkt.dts = video_next_dts; opkt.duration = 0; - unsigned int duration; + int duration; if ( ! video_last_pts ) { duration = 0; } else { duration = av_rescale_q( ipkt->pts - video_last_pts, video_input_stream->time_base, video_output_stream->time_base); Debug(1, "duration calc: pts(%d) - last_pts(%d) = (%d)", ipkt->pts, video_last_pts, duration ); + if ( duration < 0 ) { + + duration = ipkt->duration; + } } //#if ( 0 && video_last_pts && ( ipkt->duration == AV_NOPTS_VALUE || ! ipkt->duration ) ) { diff --git a/zoneminder-config.cmake b/zoneminder-config.cmake index 3b35684b5..8641bb4a8 100644 --- a/zoneminder-config.cmake +++ b/zoneminder-config.cmake @@ -51,6 +51,7 @@ #cmakedefine HAVE_LIBAVUTIL 1 #cmakedefine HAVE_LIBAVUTIL_AVUTIL_H 1 #cmakedefine HAVE_LIBAVUTIL_MATHEMATICS_H 1 +#cmakedefine HAVE_LIBAVUTIL_HWCONTEXT_H 0 #cmakedefine HAVE_LIBSWSCALE 1 #cmakedefine HAVE_LIBSWSCALE_SWSCALE_H 1 #cmakedefine HAVE_LIBAVRESAMPLE 1