|
|
|
@ -17,6 +17,7 @@
|
|
|
|
|
#ifdef NEW_FFMPEG
|
|
|
|
|
#include <libavcodec/avcodec.h>
|
|
|
|
|
#include <libavformat/avformat.h>
|
|
|
|
|
#include <libavutil/avutil.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// This is probably the incorrect revision for when CODEC_TYPE_VIDEO was removed
|
|
|
|
@ -33,6 +34,7 @@
|
|
|
|
|
|
|
|
|
|
void *CodecHandle=0;
|
|
|
|
|
void *FormatHandle=0;
|
|
|
|
|
void *UtilHandle=0;
|
|
|
|
|
int glibref=0;
|
|
|
|
|
|
|
|
|
|
#ifdef NEW_FFMPEG
|
|
|
|
@ -52,6 +54,7 @@ k9AviDecode::k9AviDecode(TQObject *parent, const char *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);
|
|
|
|
|
}
|
|
|
|
|
if (!CodecHandle) {
|
|
|
|
|
m_error =i18n("Cannot open then library %1").arg("libavcodec");
|
|
|
|
@ -61,27 +64,57 @@ k9AviDecode::k9AviDecode(TQObject *parent, const char *name)
|
|
|
|
|
m_error =i18n("Cannot open then library %1").arg("libavformat");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
# if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(51, 33, 0)
|
|
|
|
|
if (!UtilHandle) {
|
|
|
|
|
m_error =i18n("Cannot open then library %1").arg("libavutil");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
# 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)
|
|
|
|
|
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
|
|
|
|
|
img_convert = (img_convert_t)dlsym(CodecHandle,"img_convert");
|
|
|
|
|
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)
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
av_register_all();
|
|
|
|
|
m_opened=false;
|
|
|
|
|
|
|
|
|
@ -96,6 +129,9 @@ k9AviDecode::~k9AviDecode() {
|
|
|
|
|
if (glibref==0) {
|
|
|
|
|
dlclose(FormatHandle);
|
|
|
|
|
dlclose(CodecHandle);
|
|
|
|
|
if(UtilHandle) {
|
|
|
|
|
dlclose(UtilHandle);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@ -110,12 +146,24 @@ bool k9AviDecode::open(const TQString & _fileName) {
|
|
|
|
|
close();
|
|
|
|
|
|
|
|
|
|
// Open video file
|
|
|
|
|
if (av_open_input_file(&m_FormatCtx, _fileName.utf8(), NULL, 0, NULL)!=0) {
|
|
|
|
|
if (
|
|
|
|
|
# if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53, 2, 0)
|
|
|
|
|
avformat_open_input(&m_FormatCtx, _fileName.utf8(), 0, 0)!=0
|
|
|
|
|
# else
|
|
|
|
|
av_open_input_file(&m_FormatCtx, _fileName.utf8(), 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 (av_find_stream_info(m_FormatCtx)<0) {
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
@ -144,7 +192,13 @@ bool k9AviDecode::open(const TQString & _fileName) {
|
|
|
|
|
return false; // Codec not found
|
|
|
|
|
}
|
|
|
|
|
// Open codec
|
|
|
|
|
if (avcodec_open(m_CodecCtx, m_Codec)<0) {
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
@ -201,15 +255,23 @@ void k9AviDecode::readFrame(double _seconds) {
|
|
|
|
|
// 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;
|
|
|
|
|
// Convert the image from its native format to RGB
|
|
|
|
@ -258,7 +320,11 @@ 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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|