summaryrefslogtreecommitdiffstats
path: root/k9author/k9avidecode.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'k9author/k9avidecode.cpp')
-rw-r--r--k9author/k9avidecode.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/k9author/k9avidecode.cpp b/k9author/k9avidecode.cpp
index 731b1d3..77f8d2b 100644
--- a/k9author/k9avidecode.cpp
+++ b/k9author/k9avidecode.cpp
@@ -35,6 +35,7 @@
void *CodecHandle=0;
void *FormatHandle=0;
void *UtilHandle=0;
+void *SwscaleHandle=0;
int glibref=0;
#ifdef NEW_FFMPEG
@@ -49,12 +50,22 @@ void av_free_packet(AVPacket *pkt)
#endif
#endif
+#ifdef HAVE_SWSCALE
+#include "libswscale/swscale.h"
+static int sws_flags = SWS_BICUBIC;
+#endif
+
k9AviDecode::k9AviDecode(TQObject *parent, const char *name)
: TQObject(parent, name) {
if (glibref==0) {
CodecHandle=dlopen("libavcodec.so",RTLD_LAZY | RTLD_GLOBAL);
FormatHandle=dlopen("libavformat.so",RTLD_LAZY | RTLD_GLOBAL);
UtilHandle=dlopen("libavutil.so",RTLD_LAZY | RTLD_GLOBAL);
+# ifdef HAVE_SWSCALE
+ SwscaleHandle=dlopen("libswscale.so",RTLD_LAZY);
+ if (SwscaleHandle==0)
+ SwscaleHandle=dlopen("libswscale.so.2",RTLD_LAZY);
+# endif
}
if (!CodecHandle) {
m_error =i18n("Cannot open then library %1").arg("libavcodec");
@@ -70,6 +81,11 @@ k9AviDecode::k9AviDecode(TQObject *parent, const char *name)
return;
}
# endif
+# ifdef HAVE_SWSCALE
+ if (!SwscaleHandle) {
+ m_error =i18n("Cannot open the library %1").arg("libswscale");
+ }
+# endif
m_error="";
av_register_all = (av_register_all_t)dlsym(FormatHandle,"av_register_all");
# if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53, 2, 0)
@@ -98,7 +114,12 @@ k9AviDecode::k9AviDecode(TQObject *parent, const char *name)
# 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");
avcodec_close = (avcodec_close_t)dlsym(FormatHandle,"avcodec_close");
# if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53, 17, 0)
@@ -109,6 +130,11 @@ k9AviDecode::k9AviDecode(TQObject *parent, const char *name)
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");
@@ -139,6 +165,11 @@ k9AviDecode::~k9AviDecode() {
if(UtilHandle) {
dlclose(UtilHandle);
}
+# ifdef HAVE_SWSCALE
+ if (SwscaleHandle) {
+ dlclose(CodecHandle);
+ }
+# endif
}
}
@@ -257,6 +288,9 @@ void k9AviDecode::readFrame(double _seconds) {
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?
@@ -281,6 +315,7 @@ void k9AviDecode::readFrame(double _seconds) {
# 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,
@@ -289,6 +324,14 @@ void k9AviDecode::readFrame(double _seconds) {
// convert frame to TQImage
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);
+ 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
}
}
}