Index: CMakeLists.txt =================================================================== --- CMakeLists.txt +++ CMakeLists.txt @@ -15,12 +15,14 @@ find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Core Gui) find_package(KF5 REQUIRED COMPONENTS KIO I18n Config) find_package(FFmpeg COMPONENTS AVCODEC AVFORMAT SWSCALE) +find_package(Taglib) include_directories( ${CMAKE_CURRENT_BINARY_DIR} ${PC_AVCODEC_INCLUDEDIR} ${PC_AVFORMAT_INCLUDEDIR} ${FFMPEG_INCLUDE_DIR} + ${TAGLIB_INCLUDES} ) # Certain versions of FFMPEG need this to be defined @@ -39,7 +41,7 @@ kconfig_add_kcfg_files(ffmpegthumbs_PART_SRCS ffmpegthumbnailersettings5.kcfgc) add_library(ffmpegthumbs MODULE ${ffmpegthumbs_PART_SRCS}) -target_link_libraries(ffmpegthumbs Qt5::Core Qt5::Gui KF5::KIOWidgets KF5::KIOCore KF5::I18n KF5::ConfigCore KF5::ConfigGui ${AVUTIL_LIBRARIES} ${AVFILTER_LIBRARIES} ${AVFORMAT_LIBRARIES} ${AVCODEC_LIBRARIES} ${SWSCALE_LIBRARIES} ) +target_link_libraries(ffmpegthumbs Qt5::Core Qt5::Gui KF5::KIOWidgets KF5::KIOCore KF5::I18n KF5::ConfigCore KF5::ConfigGui ${AVUTIL_LIBRARIES} ${AVFILTER_LIBRARIES} ${AVFORMAT_LIBRARIES} ${AVCODEC_LIBRARIES} ${SWSCALE_LIBRARIES} ${TAGLIB_LIBRARIES} ) install(FILES ffmpegthumbnailersettings5.kcfg DESTINATION ${KCFG_INSTALL_DIR}) install(TARGETS ffmpegthumbs DESTINATION ${PLUGIN_INSTALL_DIR}) Index: cmake/FindTaglib.cmake =================================================================== --- /dev/null +++ cmake/FindTaglib.cmake @@ -0,0 +1,93 @@ +# - Try to find the Taglib library +# Once done this will define +# +# TAGLIB_FOUND - system has the taglib library +# TAGLIB_INCLUDES - the taglib includes +# TAGLIB_LIBRARIES - The libraries needed to use taglib + +# Copyright (c) 2006, Laurent Montel, +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of the University nor the names of its contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. + +if(NOT TAGLIB_MIN_VERSION) + set(TAGLIB_MIN_VERSION "1.4") +endif(NOT TAGLIB_MIN_VERSION) + +if(NOT WIN32) + find_program(TAGLIBCONFIG_EXECUTABLE NAMES taglib-config PATHS + ${BIN_INSTALL_DIR} + ) +endif(NOT WIN32) + +#reset vars +set(TAGLIB_LIBRARIES) +set(TAGLIB_CFLAGS) + +# if taglib-config has been found +if(TAGLIBCONFIG_EXECUTABLE) + + exec_program(${TAGLIBCONFIG_EXECUTABLE} ARGS --version RETURN_VALUE _return_VALUE OUTPUT_VARIABLE TAGLIB_VERSION) + + exec_program(${TAGLIBCONFIG_EXECUTABLE} ARGS --libs RETURN_VALUE _return_VALUE OUTPUT_VARIABLE TAGLIB_LIBRARIES) + + exec_program(${TAGLIBCONFIG_EXECUTABLE} ARGS --cflags RETURN_VALUE _return_VALUE OUTPUT_VARIABLE TAGLIB_CFLAGS) + + # Assume software will include by things like #include instead of + string(REPLACE "/taglib" "" TAGLIB_STRIPPED_INCLUDE_PATHS "${TAGLIB_CFLAGS}") + string(REGEX REPLACE " *-I" ";" TAGLIB_INCLUDES "${TAGLIB_STRIPPED_INCLUDE_PATHS}") + + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(Taglib FOUND_VAR TAGLIB_FOUND + REQUIRED_VARS TAGLIB_LIBRARIES TAGLIB_INCLUDES + VERSION_VAR TAGLIB_VERSION) + mark_as_advanced(TAGLIB_CFLAGS TAGLIB_LIBRARIES TAGLIB_INCLUDES) + +else(TAGLIBCONFIG_EXECUTABLE) + + include(FindPackageHandleStandardArgs) + + # To avoid issues, make the same assumption as above: + # Assume software will include by things like #include instead of + find_path(TAGLIB_INCLUDES + NAMES + taglib/tag.h + PATHS + ${INCLUDE_INSTALL_DIR} + ) + + # TODO: this originally used find_library_with_debug(), + # which is only available with KDELibs4Support, with + # arguments "WIN32_DEBUG_POSTFIX d". It is equivalent + # to find_library on all platforms other than Win32. + find_library(TAGLIB_LIBRARIES + NAMES tag + PATHS + ${LIB_INSTALL_DIR} + ) + + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(Taglib DEFAULT_MSG + TAGLIB_INCLUDES TAGLIB_LIBRARIES) +endif(TAGLIBCONFIG_EXECUTABLE) Index: ffmpegthumbnailer.cpp =================================================================== --- ffmpegthumbnailer.cpp +++ ffmpegthumbnailer.cpp @@ -1,4 +1,5 @@ // Copyright (C) 2010 Dirk Vanden Boer +// Copyright (C) 2019 Heiko Schäfer // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -17,6 +18,8 @@ #include "ffmpegthumbnailer.h" #include "ffmpegthumbnailersettings5.h" +#include + #include #include #include @@ -44,6 +47,24 @@ bool FFMpegThumbnailer::create(const QString& path, int width, int /*height*/, QImage& img) { + TagLib::MP4::File f(path.toStdString().c_str(), false); + + if (f.isValid()) { + + TagLib::MP4::Tag* tag = f.tag(); + TagLib::MP4::ItemListMap itemsListMap = tag->itemListMap(); + TagLib::MP4::Item coverItem = itemsListMap["covr"]; + TagLib::MP4::CoverArtList coverArtList = coverItem.toCoverArtList(); + + if (!coverArtList.isEmpty()) { + TagLib::MP4::CoverArt coverArt = coverArtList.front(); + img.loadFromData((const uchar *)coverArt.data().data(), + coverArt.data().size()); + + if (!img.isNull()) return true; + } + } + m_Thumbnailer.setThumbnailSize(width); // 20% seek inside the video to generate the preview m_Thumbnailer.setSeekPercentage(20); Index: tests/CMakeLists.txt =================================================================== --- tests/CMakeLists.txt +++ tests/CMakeLists.txt @@ -20,7 +20,7 @@ add_executable(ffmpegthumbtest ${ffmpegthumbtest_SRCS} ) -target_link_libraries(ffmpegthumbtest Qt5::Core Qt5::Gui KF5::KIOWidgets KF5::KIOCore KF5::I18n KF5::ConfigCore KF5::ConfigGui ${AVUTIL_LIBRARIES} ${AVFILTER_LIBRARIES} ${AVFORMAT_LIBRARIES} ${AVCODEC_LIBRARIES} ${SWSCALE_LIBRARIES}) +target_link_libraries(ffmpegthumbtest Qt5::Core Qt5::Gui KF5::KIOWidgets KF5::KIOCore KF5::I18n KF5::ConfigCore KF5::ConfigGui ${AVUTIL_LIBRARIES} ${AVFILTER_LIBRARIES} ${AVFORMAT_LIBRARIES} ${AVCODEC_LIBRARIES} ${SWSCALE_LIBRARIES} ${TAGLIB_LIBRARIES})