From b0964ca592eadb7cd3b50eac719ba66fb94121bb Mon Sep 17 00:00:00 2001 From: zlice Date: Wed, 22 Mar 2023 20:01:47 -0400 Subject: [PATCH] ffmpegthumbnailer: revbump for ffmpeg6 --- .../ffmpegthumbnailer/patches/ffmpeg6.patch | 202 ++++++++++++++++++ srcpkgs/ffmpegthumbnailer/template | 8 +- 2 files changed, 206 insertions(+), 4 deletions(-) create mode 100644 srcpkgs/ffmpegthumbnailer/patches/ffmpeg6.patch diff --git a/srcpkgs/ffmpegthumbnailer/patches/ffmpeg6.patch b/srcpkgs/ffmpegthumbnailer/patches/ffmpeg6.patch new file mode 100644 index 00000000000..363ff35a284 --- /dev/null +++ b/srcpkgs/ffmpegthumbnailer/patches/ffmpeg6.patch @@ -0,0 +1,202 @@ +--- a/libffmpegthumbnailer/moviedecoder.cpp 2017-11-21 14:06:57.000000000 -0500 ++++ b/libffmpegthumbnailer/moviedecoder.cpp 2023-05-05 13:14:47.946560668 -0400 +@@ -41,11 +41,6 @@ + namespace ffmpegthumbnailer + { + +-struct SilenceLogLevel +-{ +- SilenceLogLevel() { av_log_set_level(AV_LOG_QUIET); } +-}; +- + MovieDecoder::MovieDecoder(AVFormatContext* pavContext) + : m_VideoStream(-1) + , m_pFormatContext(pavContext) +@@ -70,8 +65,6 @@ + + void MovieDecoder::initialize(const string& filename, bool preferEmbeddedMetadata) + { +- av_register_all(); +- avcodec_register_all(); + avformat_network_init(); + + string inputFile = filename == "-" ? "pipe:" : filename; +@@ -97,8 +90,7 @@ + { + if (m_pVideoCodecContext) + { +- avcodec_close(m_pVideoCodecContext); +- m_pVideoCodecContext = nullptr; ++ avcodec_free_context(&m_pVideoCodecContext); + } + + if ((!m_FormatContextWasGiven) && m_pFormatContext) +@@ -152,10 +144,10 @@ + for (unsigned int i = 0; i < m_pFormatContext->nb_streams; ++i) + { + AVStream *stream = m_pFormatContext->streams[i]; +- auto ctx = m_pFormatContext->streams[i]->codec; +- if (ctx->codec_type == AVMEDIA_TYPE_VIDEO) ++ auto par = m_pFormatContext->streams[i]->codecpar; ++ if (par->codec_type == AVMEDIA_TYPE_VIDEO) + { +- if (!preferEmbeddedMetadata || !isStillImageCodec(ctx->codec_id)) ++ if (!preferEmbeddedMetadata || !isStillImageCodec(par->codec_id)) + { + videoStreams.push_back(i); + continue; +@@ -203,8 +195,7 @@ + } + + m_pVideoStream = m_pFormatContext->streams[m_VideoStream]; +- m_pVideoCodecContext = m_pVideoStream->codec; +- m_pVideoCodec = avcodec_find_decoder(m_pVideoCodecContext->codec_id); ++ m_pVideoCodec = avcodec_find_decoder(m_pVideoStream->codecpar->codec_id); + + if (m_pVideoCodec == nullptr) + { +@@ -214,6 +205,20 @@ + throw logic_error("Video Codec not found"); + } + ++ m_pVideoCodecContext = avcodec_alloc_context3(m_pVideoCodec); ++ ++ if (m_pVideoCodecContext == nullptr) ++ { ++ destroy(); ++ throw logic_error("Could not allocate video codec context"); ++ } ++ ++ if (avcodec_parameters_to_context(m_pVideoCodecContext, m_pVideoStream->codecpar) < 0) ++ { ++ destroy(); ++ throw logic_error("Could not configure video codec context"); ++ } ++ + m_pVideoCodecContext->workaround_bugs = 1; + + if (avcodec_open2(m_pVideoCodecContext, m_pVideoCodec, nullptr) < 0) +@@ -386,13 +391,6 @@ + + void MovieDecoder::initializeFilterGraph(const AVRational& timeBase, const std::string& size, bool maintainAspectRatio) + { +- static const AVPixelFormat pixelFormats[] = { AV_PIX_FMT_RGB24, AV_PIX_FMT_NONE }; +- +- auto del = [] (AVBufferSinkParams* p) { av_freep(p); }; +- std::unique_ptr buffersinkParams(av_buffersink_params_alloc(), del); +- +- avfilter_register_all(); +- + m_pFilterGraph = avfilter_graph_alloc(); + assert(m_pFilterGraph); + +@@ -404,10 +402,8 @@ + + checkRc(avfilter_graph_create_filter(&m_pFilterSource, avfilter_get_by_name("buffer"), "thumb_buffer", ss.str().c_str(), nullptr, m_pFilterGraph), + "Failed to create filter source"); +- buffersinkParams->pixel_fmts = pixelFormats; +- checkRc(avfilter_graph_create_filter(&m_pFilterSink, avfilter_get_by_name("buffersink"), "thumb_buffersink", nullptr, buffersinkParams.get(), m_pFilterGraph), ++ checkRc(avfilter_graph_create_filter(&m_pFilterSink, avfilter_get_by_name("buffersink"), "thumb_buffersink", nullptr, nullptr, m_pFilterGraph), + "Failed to create filter sink"); +- buffersinkParams.release(); + + AVFilterContext* yadifFilter = nullptr; + if (m_pFrame->interlaced_frame != 0) +@@ -500,15 +496,15 @@ + } + + checkRc(av_seek_frame(m_pFormatContext, -1, timestamp, 0), "Seeking in video failed"); +- avcodec_flush_buffers(m_pFormatContext->streams[m_VideoStream]->codec); ++ avcodec_flush_buffers(m_pVideoCodecContext); + + int keyFrameAttempts = 0; +- bool gotFrame = 0; ++ bool gotFrame; + + do + { + int count = 0; +- gotFrame = 0; ++ gotFrame = false; + + while (!gotFrame && count < 20) + { +@@ -552,17 +548,33 @@ + return false; + } + +- av_frame_unref(m_pFrame); +- +- int frameFinished; ++ int rc = avcodec_send_packet(m_pVideoCodecContext, m_pPacket); ++ if(rc == AVERROR(EAGAIN)) ++ { ++ rc = 0; ++ } + +- int bytesDecoded = avcodec_decode_video2(m_pVideoCodecContext, m_pFrame, &frameFinished, m_pPacket); +- if (bytesDecoded < 0) ++ if(rc == AVERROR_EOF) ++ { ++ return false; ++ } ++ else if(rc < 0) + { +- throw logic_error("Failed to decode video frame: bytesDecoded < 0"); ++ throw logic_error("Failed to decode video frame: avcodec_send_packet() < 0"); + } + +- return frameFinished > 0; ++ rc = avcodec_receive_frame(m_pVideoCodecContext, m_pFrame); ++ switch(rc) ++ { ++ case 0: ++ return true; ++ ++ case AVERROR(EAGAIN): ++ return false; ++ ++ default: ++ throw logic_error("Failed to decode video frame: avcodec_receive_frame() < 0"); ++ } + } + + bool MovieDecoder::getVideoPacket() +@@ -570,8 +582,6 @@ + bool framesAvailable = true; + bool frameDecoded = false; + +- int attempts = 0; +- + if (m_pPacket) + { + av_packet_unref(m_pPacket); +@@ -580,6 +590,7 @@ + + m_pPacket = new AVPacket(); + ++ + while (framesAvailable && !frameDecoded) + { + framesAvailable = av_read_frame(m_pFormatContext, m_pPacket) >= 0; +@@ -644,7 +655,7 @@ + + int32_t MovieDecoder::getStreamRotation() + { +- int32_t* matrix = reinterpret_cast(av_stream_get_side_data(m_pVideoStream, AV_PKT_DATA_DISPLAYMATRIX, nullptr)); ++ auto matrix = reinterpret_cast(av_stream_get_side_data(m_pVideoStream, AV_PKT_DATA_DISPLAYMATRIX, nullptr)); + if (matrix) + { + auto angle = lround(av_display_rotation_get(matrix)); + +--- a/libffmpegthumbnailer/moviedecoder.h 2017-11-12 04:23:38.000000000 -0500 ++++ b/libffmpegthumbnailer/moviedecoder.h 2023-05-05 13:26:07.095529911 -0400 +@@ -78,7 +78,7 @@ + int m_VideoStream; + AVFormatContext* m_pFormatContext; + AVCodecContext* m_pVideoCodecContext; +- AVCodec* m_pVideoCodec; ++ const AVCodec* m_pVideoCodec; + AVFilterGraph* m_pFilterGraph; + AVFilterContext* m_pFilterSource; + AVFilterContext* m_pFilterSink; diff --git a/srcpkgs/ffmpegthumbnailer/template b/srcpkgs/ffmpegthumbnailer/template index 039eea7622b..add38199986 100644 --- a/srcpkgs/ffmpegthumbnailer/template +++ b/srcpkgs/ffmpegthumbnailer/template @@ -1,16 +1,16 @@ # Template file for 'ffmpegthumbnailer' pkgname=ffmpegthumbnailer version=2.2.2 -revision=1 +revision=2 build_style=cmake hostmakedepends="pkg-config" -makedepends="libpng-devel libjpeg-turbo-devel ffmpeg-devel" +makedepends="libpng-devel libjpeg-turbo-devel ffmpeg6-devel" depends="ffmpeg" short_desc="Lightweight video thumbnailer" maintainer="Orphaned " license="GPL-2.0-or-later" -homepage="https://github.com/dirkvdb/${pkgname}" -distfiles="${homepage}/releases/download/${version}/${pkgname}-${version}.tar.bz2" +homepage="https://github.com/dirkvdb" +distfiles="${homepage}/${pkgname}/releases/download/${version}/${pkgname}-${version}.tar.bz2" checksum=1cb24059c38223f657b300c84dd80491b7040d4b69471c4fea69be862bc99b5b post_install() {