From aff1be93b8056fdd15bd062aba71d407e6dab8af Mon Sep 17 00:00:00 2001 From: eisneinechse <42617957+eisneinechse@users.noreply.github.com> Date: Sun, 9 Sep 2018 10:54:31 -0700 Subject: [PATCH] Support for multiple input files --- include/FFmpegReader.h | 7 +++++-- src/FFmpegReader.cpp | 32 ++++++++++++++++++-------------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/include/FFmpegReader.h b/include/FFmpegReader.h index caf68e5e..f571af73 100644 --- a/include/FFmpegReader.h +++ b/include/FFmpegReader.h @@ -146,8 +146,11 @@ namespace openshot int64_t largest_frame_processed; int64_t current_video_frame; // can't reliably use PTS of video to determine this - //int hw_de_supported = 0; // Is set by FFmpegReader - //AVPixelFormat hw_de_av_pix_fmt = AV_PIX_FMT_NONE; + int hw_de_supported = 0; // Is set by FFmpegReader + #if IS_FFMPEG_3_2 + AVPixelFormat hw_de_av_pix_fmt = AV_PIX_FMT_NONE; + AVHWDeviceType hw_de_av_device_type = AV_HWDEVICE_TYPE_VAAPI; + #endif int is_hardware_decode_supported(int codecid); diff --git a/src/FFmpegReader.cpp b/src/FFmpegReader.cpp index 083de926..4ec46191 100644 --- a/src/FFmpegReader.cpp +++ b/src/FFmpegReader.cpp @@ -33,10 +33,10 @@ using namespace openshot; int hw_de_on = 1; // Is set in UI -int hw_de_supported = 0; // Is set by FFmpegReader +//int hw_de_supported = 0; // Is set by FFmpegReader #if IS_FFMPEG_3_2 -AVPixelFormat hw_de_av_pix_fmt = AV_PIX_FMT_NONE; -AVHWDeviceType hw_de_av_device_type = AV_HWDEVICE_TYPE_VAAPI; +AVPixelFormat hw_de_av_pix_fmt_global = AV_PIX_FMT_NONE; +AVHWDeviceType hw_de_av_device_type_global = AV_HWDEVICE_TYPE_VAAPI; #endif FFmpegReader::FFmpegReader(string path) @@ -120,35 +120,35 @@ static enum AVPixelFormat get_hw_dec_format(AVCodecContext *ctx, const enum AVPi for (p = pix_fmts; *p != AV_PIX_FMT_NONE; p++) { //Linux formats if (*p == AV_PIX_FMT_VAAPI) { - hw_de_av_pix_fmt = AV_PIX_FMT_VAAPI; - hw_de_av_device_type = AV_HWDEVICE_TYPE_VAAPI; + hw_de_av_pix_fmt_global = AV_PIX_FMT_VAAPI; + hw_de_av_device_type_global = AV_HWDEVICE_TYPE_VAAPI; return *p; } if (*p == AV_PIX_FMT_CUDA) { - hw_de_av_pix_fmt = AV_PIX_FMT_CUDA; - hw_de_av_device_type = AV_HWDEVICE_TYPE_CUDA; + hw_de_av_pix_fmt_global = AV_PIX_FMT_CUDA; + hw_de_av_device_type_global = AV_HWDEVICE_TYPE_CUDA; return *p; } // Windows formats if (*p == AV_PIX_FMT_DXVA2_VLD) { - hw_de_av_pix_fmt = AV_PIX_FMT_DXVA2_VLD; - hw_de_av_device_type = AV_HWDEVICE_TYPE_DXVA2; + hw_de_av_pix_fmt_global = AV_PIX_FMT_DXVA2_VLD; + hw_de_av_device_type_global = AV_HWDEVICE_TYPE_DXVA2; return *p; } if (*p == AV_PIX_FMT_D3D11) { - hw_de_av_pix_fmt = AV_PIX_FMT_D3D11; - hw_de_av_device_type = AV_HWDEVICE_TYPE_D3D11VA; + hw_de_av_pix_fmt_global = AV_PIX_FMT_D3D11; + hw_de_av_device_type_global = AV_HWDEVICE_TYPE_D3D11VA; return *p; } //Mac format if (*p == AV_PIX_FMT_QSV) { - hw_de_av_pix_fmt = AV_PIX_FMT_QSV; - hw_de_av_device_type = AV_HWDEVICE_TYPE_QSV; + hw_de_av_pix_fmt_global = AV_PIX_FMT_QSV; + hw_de_av_device_type_global = AV_HWDEVICE_TYPE_QSV; return *p; } } ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::ReadStream (Unable to decode this file using hardware decode.)", "", -1, "", -1, "", -1, "", -1, "", -1, "", -1); - hw_de_supported = 0; + //hw_de_supported = 0; return AV_PIX_FMT_NONE; } @@ -853,6 +853,10 @@ bool FFmpegReader::GetAVFrame() ret = avcodec_send_packet(pCodecCtx, packet); + // Get the format from the variables set in get_hw_dec_format + hw_de_av_pix_fmt = hw_de_av_pix_fmt_global; + hw_de_av_device_type = hw_de_av_device_type_global; + if (ret < 0 || ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) { ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::GetAVFrame (Packet not sent)", "", -1, "", -1, "", -1, "", -1, "", -1, "", -1); }