1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
//
// C++ Interface: k9avidecode
//
// Description:
//
//
// Author: Jean-Michel PETIT <[email protected]>, (C) 2007
//
// Copyright: See COPYING file that comes with this distribution
//
//
#ifndef K9AVIDECODE_H
#define K9AVIDECODE_H
#include "k9common.h"
#include <tqobject.h>
#ifdef OLD_FFMPEG
#include <ffmpeg/avformat.h>
#endif
#ifdef NEW_FFMPEG
#include <libavformat/avformat.h>
#include <libavutil/avutil.h>
#endif
#ifdef HAVE_SWSCALE
#include <libswscale/swscale.h>
#endif
#include <tqimage.h>
/**
@author Jean-Michel PETIT <[email protected]>
*/
//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
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(54, 25, 0)
typedef AVCodec* (*avcodec_find_decoder_t)(enum AVCodecID);
#else
typedef AVCodec* (*avcodec_find_decoder_t)(enum CodecID);
#endif
#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 *);
#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 TQObject
{
Q_OBJECT
public:
k9AviDecode(TQObject *parent = 0, const char *name = 0);
~k9AviDecode();
bool open(const TQString & _fileName);
void readFrame(double _seconds);
void seek(double _seconds);
void close();
double getDuration() const;
bool opened() const;
TQString getFileName() const;
TQString 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;
# ifdef HAVE_SWSCALE
sws_freeContext_t sws_freeContext;
sws_getContext_t sws_getContext;
sws_scale_t sws_scale;
# endif
AVFormatContext *m_FormatCtx;
AVCodecContext *m_CodecCtx;
AVCodec *m_Codec;
AVFrame *m_Frame,*m_FrameRGB;
uint8_t *m_buffer;
int m_videoStream;
bool m_opened;
double m_duration;
TQString m_fileName;
TQString m_error;
void SaveFrame(AVFrame *pFrame, int width, int height);
signals:
void drawFrame(TQImage*);
};
#endif
|