File k9copy-ffmpeg.patch of Package k9copy
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -58,10 +58,6 @@ INCLUDE(CMakeDetermineSystem)
INCLUDE(CheckIncludeFiles)
INCLUDE(FindLibMpeg2)
INCLUDE(FindXine)
-#INCLUDE(FindAvcodec)
-INCLUDE(FindAvformat)
-#INCLUDE(FindAvutil)
-INCLUDE(FindFFmpegScale)
include(FindPkgConfig)
pkg_check_modules(LIBDVD REQUIRED dvdnav dvdread)
@@ -70,6 +66,11 @@ MESSAGE(STATUS "Found dvd library ${LIBD
MESSAGE(STATUS "Found dvd include ${LIBDVD_INCLUDE_DIRS}")
include_directories(${LIBDVD_INCLUDE_DIRS})
+pkg_check_modules(FFMPEG REQUIRED libavcodec libavformat libavutil libswscale)
+MESSAGE(STATUS "Found ffmpeg library ${FFMPEG_FOUND}")
+MESSAGE(STATUS "Found ffmpeg library ${FFMPEG_LIBRARIES}")
+MESSAGE(STATUS "Found ffmpeg include ${FFMPEG_INCLUDE_DIRS}")
+
# usage: CHECK_INCLUDE_FILES (<header> <RESULT_VARIABLE> )
CHECK_INCLUDE_FILES(inttypes.h HAVE_INTTYPES_H) # inttypes.h
CHECK_INCLUDE_FILES(stddef.h HAVE_STDDEF_H) # stddef.h
@@ -81,7 +82,6 @@ CHECK_INCLUDE_FILES(sys/types.h HAVE
CHECK_INCLUDE_FILES(unistd.h HAVE_UNISTD_H) # unistd.h
CHECK_INCLUDE_FILES(malloc.h HAVE_MALLOC_H) # malloc.h
-FINDFFMPEGSCALE("swscale")
CONFIGURE_FILE(config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
@@ -110,9 +110,6 @@ ELSE (LIBDL_LIBRARY)
ENDIF (LIBDL_LIBRARY)
-#FINDAVFORMAT("avformat")
-#FINDAVCODEC("avcodec")
-#FINDAVUTIL("avutil")
add_definitions( -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS)
add_subdirectory( src/core )
@@ -143,11 +140,7 @@ include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/src/batch
${KDE4_INCLUDES} ${QT_INCLUDES}
#${LIBDVDREAD_INCLUDE_DIR}/dvdread
- ${AVCODEC_INCLUDE_DIR}
- ${AVFORMAT_INCLUDE_DIR}
- ${AVUTIL_INCLUDE_DIR}
- ${FFMPEGSCALE_INCLUDE_DIR}
- ${FFMPEG_INCLUDE_DIR}
+ ${FFMPEG_INCLUDE_DIRS}
)
@@ -487,7 +480,7 @@ endif()
if(QT5_BUILD)
message("Qt5 Version")
-target_link_libraries(k9copy k9copylib KF5::WidgetsAddons KF5::XmlGui KF5::IconThemes KF5::KIOCore KF5::KIOWidgets ${PHONON_LIBRARY} KF5::I18n ${LIBDVD_LIBRARIES})
+target_link_libraries(k9copy k9copylib KF5::WidgetsAddons KF5::XmlGui KF5::IconThemes KF5::KIOCore KF5::KIOWidgets ${PHONON_LIBRARY} KF5::I18n ${LIBDVD_LIBRARIES} ${FFMPEG_LIBRARIES})
target_link_libraries(k9play k9copylib KF5::WidgetsAddons KF5::XmlGui ${LIBDVD_LIBRARIES})
target_link_libraries(k9xineplayer KF5::WidgetsAddons KF5::XmlGui KF5::I18n Qt5::X11Extras ${XINE_LIBRARY} ${X11_X11_LIB} )
else()
--- a/src/import/k9avidecode.cpp
+++ b/src/import/k9avidecode.cpp
@@ -10,180 +10,42 @@
//
//
#include "k9avidecode.h"
-#include <libavcodec/avcodec.h>
#include <qimage.h>
#include <dlfcn.h>
#include "k9common.h"
-#ifdef HAVE_SWSCALE
-
-#include "swscale.h"
static int sws_flags = SWS_BICUBIC;
-#endif
-void av_free_packet_internal(AVPacket *pkt)
-{
- if (pkt) {
- if (pkt->destruct) pkt->destruct(pkt);
- pkt->data = NULL; pkt->size = 0;
- }
-}
k9AviDecode::k9AviDecode(QObject *parent, const char *)
: QObject(parent) {
- CodecHandle=0;
- FormatHandle=0;
- UtilHandle=0;
- SwscaleHandle=0;
- glibref=0;
- if (glibref==0) {
- CodecHandle=dlopen("libavcodec.so",RTLD_LAZY ); //| RTLD_GLOBAL
- FormatHandle=dlopen("libavformat.so",RTLD_LAZY);
- UtilHandle=dlopen("libavutil.so",RTLD_LAZY);
-#ifdef HAVE_SWSCALE
- SwscaleHandle=dlopen("libswscale.so",RTLD_LAZY);
- if (SwscaleHandle==0)
- SwscaleHandle=dlopen("libswscale.so.2",RTLD_LAZY);
-#endif
- }
- m_error="";
- QStringList errs;
- if (!CodecHandle) {
- errs << i18n("Cannot open the library %1").arg("libavcodec");
- }
- if (!FormatHandle ) {
- errs << i18n("Cannot open the library %1").arg("libavformat");
- }
-# if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(51, 33, 0)
- if (!UtilHandle) {
- m_error =i18n("Cannot open then library %1").arg("libavutil");
- return;
- }
-# endif
-#ifdef HAVE_SWSCALE
- if (!SwscaleHandle) {
- errs << i18n("Cannot open the library %1").arg("libswscale");
- }
-#endif
- av_register_all = (av_register_all_t)dlsym(FormatHandle,"av_register_all");
-# if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53, 2, 0)
- avformat_open_input = (avformat_open_input_t)dlsym(FormatHandle,"avformat_open_input");
-# else
- av_open_input_file = (av_open_input_file_t)dlsym(FormatHandle,"av_open_input_file");
-# endif
-# if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53, 6, 0)
- avformat_find_stream_info = (avformat_find_stream_info_t)dlsym(FormatHandle,"avformat_find_stream_info");
-# else
- av_find_stream_info = (av_find_stream_info_t)dlsym(FormatHandle,"av_find_stream_info");
-# endif
- avcodec_find_decoder =(avcodec_find_decoder_t) dlsym(CodecHandle,"avcodec_find_decoder");
-# if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53, 8, 0)
- avcodec_open2 = (avcodec_open2_t)dlsym(CodecHandle,"avcodec_open2");
-# else
- avcodec_open = (avcodec_open_t)dlsym(CodecHandle,"avcodec_open");
-# endif
- avcodec_alloc_frame = (avcodec_alloc_frame_t)dlsym(CodecHandle,"avcodec_alloc_frame");
- avpicture_get_size = (avpicture_get_size_t)dlsym(CodecHandle,"avpicture_get_size");
- av_malloc = (av_malloc_t)dlsym(CodecHandle,"av_malloc");
- avpicture_fill = (avpicture_fill_t)dlsym(CodecHandle,"avpicture_fill");
- av_read_frame = (av_read_frame_t)dlsym(FormatHandle,"av_read_frame");
-# if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52, 23, 0)
- avcodec_decode_video2 = (avcodec_decode_video2_t)dlsym(CodecHandle,"avcodec_decode_video2");
-# else
- avcodec_decode_video = (avcodec_decode_video_t)dlsym(CodecHandle,"avcodec_decode_video");
-# endif
-#ifndef HAVE_SWSCALE
- img_convert = (img_convert_t)dlsym(CodecHandle,"img_convert");
-//if img_convert is null (deprecated in ffmpeg), we need libswscale
- if (!img_convert)
- errs << i18n("Cannot open the library %1").arg("libswscale");
-#endif
- av_free = (av_free_t)dlsym(CodecHandle,"av_free");
- av_free_packet = (av_free_packet_t)dlsym(CodecHandle,"av_free_packet");
- if (av_free_packet==0)
- av_free_packet=av_free_packet_internal;
- avcodec_close = (avcodec_close_t)dlsym(FormatHandle,"avcodec_close");
-# if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53, 17, 0)
- avformat_close_input = (avformat_close_input_t)dlsym(FormatHandle,"avformat_close_input");
-# else
- av_close_input_file = (av_close_input_file_t)dlsym(FormatHandle,"av_close_input_file");
-# endif
- av_seek_frame=(av_seek_frame_t)dlsym(FormatHandle,"av_seek_frame");
- av_rescale_q=(av_rescale_q_t)dlsym(FormatHandle,"av_rescale_q");
- avcodec_flush_buffers=(avcodec_flush_buffers_t)dlsym(CodecHandle,"avcodec_flush_buffers");
-#ifdef HAVE_SWSCALE
- sws_freeContext= (sws_freeContext_t)dlsym(SwscaleHandle,"sws_freeContext");
- sws_getContext=(sws_getContext_t)dlsym(SwscaleHandle,"sws_getContext");
- sws_scale= (sws_scale_t)dlsym(SwscaleHandle,"sws_scale");
-#endif
-# if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(51, 33, 0)
- av_gettime=(av_gettime_t)dlsym(UtilHandle,"av_gettime");
-# else
- av_gettime=(av_gettime_t)dlsym(FormatHandle,"av_gettime");
-# endif
-
- if (errs.count() >0) {
- m_error=errs.join("\n");
- k9Dialogs::error(m_error,"k9copy",QStringList());
- return;
- }
- av_register_all();
- m_opened=false;
- glibref++;
}
k9AviDecode::~k9AviDecode() {
- if (m_opened)
- close();
- glibref--;
- if (glibref==0) {
- if (FormatHandle)
- dlclose(FormatHandle);
- if (CodecHandle)
- dlclose(CodecHandle);
- if(UtilHandle)
- dlclose(UtilHandle);
-#ifdef HAVE_SWSCALE
- if (SwscaleHandle)
- dlclose(CodecHandle);
-#endif
- FormatHandle=0;
- CodecHandle=0;
- }
}
bool k9AviDecode::open(const QString & _fileName) {
m_error="";
- if (m_opened)
- close();
// Open video file
if (
-# if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53, 2, 0)
avformat_open_input(&m_FormatCtx, _fileName.toUtf8(), 0, 0)!=0
-# else
- av_open_input_file(&m_FormatCtx, _fileName.toUtf8(), NULL, 0, NULL)!=0
-# endif
) {
m_error=i18n("Couldn't open the file %1").arg(_fileName);
return false; // Couldn't open file}
}
// Retrieve stream information
if (
-# if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53, 6, 0)
avformat_find_stream_info(m_FormatCtx, NULL)<0
-# else
- av_find_stream_info(m_FormatCtx)<0
-# endif
) {
m_error =i18n("Couldn't find stream information");
return false; // Couldn't find stream information
@@ -214,11 +76,7 @@ bool k9AviDecode::open(const QString & _
}
// Open codec
if (
-# if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53, 8, 0)
avcodec_open2(m_CodecCtx, m_Codec, NULL)<0
-# else
- avcodec_open(m_CodecCtx, m_Codec)<0
-# endif
) {
m_error =i18n("Could'nt open the codec");
return false; // Could not open codec
@@ -226,10 +84,10 @@ bool k9AviDecode::open(const QString & _
// Allocate video frame
- m_Frame=avcodec_alloc_frame();
+ m_Frame=av_frame_alloc();
// Allocate an AVFrame structure
- m_FrameRGB=avcodec_alloc_frame();
+ m_FrameRGB=av_frame_alloc();
if (m_FrameRGB==NULL) {
m_error =i18n ("Unable to allocate memory for frames");
return false;
@@ -238,20 +96,19 @@ bool k9AviDecode::open(const QString & _
int numBytes;
// Determine required buffer size and allocate buffer
- numBytes=avpicture_get_size(PIX_FMT_RGB24, m_CodecCtx->width,
+ numBytes=avpicture_get_size(AV_PIX_FMT_RGB24, m_CodecCtx->width,
m_CodecCtx->height);
m_buffer=(uint8_t *)av_malloc(numBytes*sizeof(uint8_t));
// Assign appropriate parts of buffer to image planes in pFrameRGB
// Note that pFrameRGB is an AVFrame, but AVFrame is a superset
// of AVPicture
- avpicture_fill((AVPicture *)m_FrameRGB, m_buffer, PIX_FMT_RGB24,
+ avpicture_fill((AVPicture *)m_FrameRGB, m_buffer, AV_PIX_FMT_RGB24,
m_CodecCtx->width, m_CodecCtx->height);
m_duration=(double)(calcDuration() + m_FormatCtx->start_time) / AV_TIME_BASE;
- m_opened=true;
m_fileName=_fileName;
return true;
}
@@ -277,7 +134,6 @@ void k9AviDecode::seek(double _seconds)
int64_t fspos = (int64_t)(_seconds * AV_TIME_BASE);
fspos=av_rescale_q(fspos, AV_TIME_BASE_Q, time_base);
int i=av_seek_frame(m_FormatCtx, m_videoStream, fspos, AVSEEK_FLAG_BACKWARD );
-// double pos=av_gettime() / 1000000;
}
void k9AviDecode::readFrame(double _seconds) {
@@ -288,48 +144,27 @@ void k9AviDecode::readFrame(double _seco
avcodec_flush_buffers(m_CodecCtx);
int frameFinished=0;
AVPacket packet;
-#ifdef HAVE_SWSCALE
struct SwsContext *toRGB_convert_ctx;
-#endif
bool bFound=false;
while (av_read_frame(m_FormatCtx, &packet)>=0 && !bFound) {
// Is this a packet from the video stream?
if (packet.stream_index==m_videoStream) {
// Decode video frame
-# if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52, 23, 0)
avcodec_decode_video2(m_CodecCtx, m_Frame, &frameFinished, &packet);
-# else
- avcodec_decode_video(m_CodecCtx, m_Frame, &frameFinished,
- packet.data, packet.size);
-# endif
// Did we get a video frame?
if (frameFinished) {
// if (m_Frame->pts >=fspos)
int64_t cur_dts=fspos;
-# if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(54, 2, 0)
cur_dts= packet.dts;
-# else
- if (m_FormatCtx->cur_st)
- cur_dts= m_FormatCtx->cur_st->cur_dts;
-# endif
if (cur_dts >=fspos) {
bFound=true;
-#ifndef HAVE_SWSCALE
- // Convert the image from its native format to RGB
- img_convert((AVPicture *)m_FrameRGB, PIX_FMT_RGB24,
- (AVPicture*)m_Frame, m_CodecCtx->pix_fmt,
- m_CodecCtx->width, m_CodecCtx->height);
- SaveFrame(m_FrameRGB, m_CodecCtx->width,
- m_CodecCtx->height);
-#else
- toRGB_convert_ctx=sws_getContext(m_CodecCtx->width, m_CodecCtx->height, m_CodecCtx->pix_fmt, m_CodecCtx->width, m_CodecCtx->height, PIX_FMT_RGB24, sws_flags,NULL,NULL,NULL);
+ toRGB_convert_ctx=sws_getContext(m_CodecCtx->width, m_CodecCtx->height, m_CodecCtx->pix_fmt, m_CodecCtx->width, m_CodecCtx->height, AV_PIX_FMT_RGB24, sws_flags,NULL,NULL,NULL);
sws_scale(toRGB_convert_ctx, m_Frame->data, m_Frame->linesize, 0, m_CodecCtx->height, m_FrameRGB->data,m_FrameRGB->linesize);
// convert frame to QImage
SaveFrame(m_FrameRGB, m_CodecCtx->width,
m_CodecCtx->height);
sws_freeContext(toRGB_convert_ctx);
-#endif
}
}
}
@@ -356,7 +191,6 @@ void k9AviDecode::SaveFrame(AVFrame *pFr
}
void k9AviDecode::close() {
- if (m_opened) {
// Free the RGB image
av_free(m_buffer);
av_free(m_FrameRGB);
@@ -368,13 +202,7 @@ void k9AviDecode::close() {
avcodec_close(m_CodecCtx);
// Close the video file
-# if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53, 17, 0)
avformat_close_input(&m_FormatCtx);
-# else
- av_close_input_file(m_FormatCtx);
-# endif
- m_opened=false;
- }
}
@@ -384,7 +212,7 @@ double k9AviDecode::getDuration() const
bool k9AviDecode::opened() const {
- return m_opened;
+ return true;
}
--- a/src/import/k9avidecode.h
+++ b/src/import/k9avidecode.h
@@ -14,68 +14,21 @@
#include "k9common.h"
#include <qobject.h>
-#include <libavformat/avformat.h>
-#include <libavutil/avutil.h>
#include <qimage.h>
#include <cstdlib>
#include <QObject>
-#ifdef HAVE_SWSCALE
-#include <swscale.h>
-#endif
+extern "C" {
+#include <libavcodec/avcodec.h>
+#include <libavformat/avformat.h>
+#include <libavutil/avutil.h>
+#include <libswscale/swscale.h>
+}
/**
@author Jean-Michel PETIT <k9copy@free.fr>
*/
//typedef dvd_file_t * (*DVDOpenFile_t) ( dvd_reader_t *, int, dvd_read_domain_t );
-typedef void (*av_register_all_t) (void);
-typedef int64_t (*av_gettime_t) (void);
-#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53, 2, 0)
-typedef int (*avformat_open_input_t)(AVFormatContext **, const char *, AVInputFormat *, AVDictionary **);
-#else
-typedef int (*av_open_input_file_t)(AVFormatContext **, const char *,AVInputFormat *,int, AVFormatParameters *);
-#endif
-#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53, 6, 0)
-typedef int (*avformat_find_stream_info_t)(AVFormatContext *, AVDictionary **);
-#else
-typedef int (*av_find_stream_info_t)(AVFormatContext *);
-#endif
-typedef AVCodec* (*avcodec_find_decoder_t)(enum AVCodecID);
-#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53, 8, 0)
-typedef int (*avcodec_open2_t)(AVCodecContext *, AVCodec *, AVDictionary **);
-#else
-typedef int (*avcodec_open_t)(AVCodecContext *, AVCodec *);
-#endif
-typedef AVFrame * (*avcodec_alloc_frame_t)(void);
-
-typedef int (*avpicture_get_size_t)(int , int , int );
-typedef void * (*av_malloc_t)(unsigned int );
-typedef int (*avpicture_fill_t)(AVPicture *, uint8_t *,int , int , int);
-typedef int (*av_read_frame_t)(AVFormatContext *, AVPacket *);
-
-#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52, 23, 0)
-typedef int (*avcodec_decode_video2_t)(AVCodecContext *, AVFrame *, int *, AVPacket *);
-#else
-typedef int (*avcodec_decode_video_t)(AVCodecContext *, AVFrame *,int *, uint8_t *, int );
-#endif
-typedef int (*img_convert_t)(AVPicture *, int , const AVPicture *, int ,int, int);
-typedef void (*av_free_t)(void *);
-typedef int (*avcodec_close_t)(AVCodecContext *);
-#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53, 17, 0)
-typedef void (*avformat_close_input_t)(AVFormatContext **);
-#else
-typedef void (*av_close_input_file_t)(AVFormatContext *);
-#endif
-typedef int (*av_seek_frame_t)(AVFormatContext *,int,int64_t timestamp,int flags); typedef int64_t (*av_rescale_q_t)(int64_t , AVRational , AVRational ) ;
-typedef void (*avcodec_flush_buffers_t)(AVCodecContext *);
-typedef void (*av_free_packet_t)(AVPacket *);
-
-#ifdef HAVE_SWSCALE
-typedef void (*sws_freeContext_t)(struct SwsContext *swsContext);
-typedef struct SwsContext* (*sws_getContext_t)(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat, int flags,
- SwsFilter *srcFilter, SwsFilter *dstFilter, double *param);
-typedef int (*sws_scale_t)(struct SwsContext *context, uint8_t* src[], int srcStride[], int srcSliceY,int srcSliceH, uint8_t* dst[], int dstStride[]);
-#endif
class k9AviDecode : public QObject
@@ -97,56 +50,6 @@ public:
QString getError() const;
private:
- av_register_all_t av_register_all;
-# if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53, 2, 0)
- avformat_open_input_t avformat_open_input;
-# else
- av_open_input_file_t av_open_input_file;
-# endif
-# if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53, 6, 0)
- avformat_find_stream_info_t avformat_find_stream_info;
-# else
- av_find_stream_info_t av_find_stream_info;
-# endif
- avcodec_find_decoder_t avcodec_find_decoder;
-# if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53, 8, 0)
- avcodec_open2_t avcodec_open2;
-# else
- avcodec_open_t avcodec_open;
-# endif
- avcodec_alloc_frame_t avcodec_alloc_frame;
- av_seek_frame_t av_seek_frame;
- avpicture_get_size_t avpicture_get_size;
- av_malloc_t av_malloc;
- avpicture_fill_t avpicture_fill;
- av_read_frame_t av_read_frame;
-# if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52, 23, 0)
- avcodec_decode_video2_t avcodec_decode_video2;
-# else
- avcodec_decode_video_t avcodec_decode_video;
-# endif
- img_convert_t img_convert;
- av_free_t av_free;
- avcodec_close_t avcodec_close;
-# if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53, 17, 0)
- avformat_close_input_t avformat_close_input;
-# else
- av_close_input_file_t av_close_input_file;
-# endif
- av_rescale_q_t av_rescale_q;
- av_gettime_t av_gettime;
- avcodec_flush_buffers_t avcodec_flush_buffers;
- av_free_packet_t av_free_packet;
-#ifdef HAVE_SWSCALE
- sws_freeContext_t sws_freeContext;
- sws_getContext_t sws_getContext;
- sws_scale_t sws_scale;
-#endif
- void *CodecHandle;
- void *FormatHandle;
- void *UtilHandle;
- void *SwscaleHandle;
- int glibref;
AVFormatContext *m_FormatCtx;
AVCodecContext *m_CodecCtx;