forked from DC-SWAT/DreamShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFFMPEG.pkg
More file actions
274 lines (201 loc) · 7.98 KB
/
Copy pathFFMPEG.pkg
File metadata and controls
274 lines (201 loc) · 7.98 KB
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
/*
by SWAT
*/
$#include "ds.h"
$#include "SDL.h"
$#include "SDL_ffmpeg.h"
$
module FFMPEG
{
enum SDL_ffmpegStreamType
{
SDL_ffmpegUninitialized = 0,
SDL_ffmpegOutputStream,
SDL_ffmpegInputStream
};
typedef void (*SDL_ffmpegCallback)(void *userdata, Uint8 *stream, int len);
typedef struct SDL_ffmpegConversionContext
{
int inWidth, inHeight, inFormat,
outWidth, outHeight, outFormat;
struct SwsContext *context;
struct SDL_ffmpegConversionContext *next;
} SDL_ffmpegConversionContext;
/** Struct to hold codec values */
typedef struct
{
/** video codec ID */
int32_t videoCodecID;
/** width of the output stream */
int32_t width;
/** height of the output stream */
int32_t height;
/** numinator part of the framerate */
int32_t framerateNum;
/** denominator part of the framerate */
int32_t framerateDen;
/** bitrate of video stream in bytes */
int32_t videoBitrate;
/** when variable bitrate is desired, this holds the minimal video bitrate */
int32_t videoMinRate;
/** when variable bitrate is desired, this holds the maximal video bitrate */
int32_t videoMaxRate;
/** audio codec ID */
int32_t audioCodecID;
/** number of audio channels in stream */
int32_t channels;
/** audio samplerate of output stream */
int32_t sampleRate;
/** bitrate of audio stream in bytes */
int32_t audioBitrate;
/** when variable bitrate is desired, this holds the minimal audio bitrate */
int32_t audioMinRate;
/** when variable bitrate is desired, this holds the maximal audio bitrate */
int32_t audiooMaxRate;
} SDL_ffmpegCodec;
/** predefined codec for PAL DVD */
extern const SDL_ffmpegCodec SDL_ffmpegCodecPALDVD;
/** predefined codec for DV */
extern const SDL_ffmpegCodec SDL_ffmpegCodecPALDV;
/** predefined codec based on extension of output file */
extern const SDL_ffmpegCodec SDL_ffmpegCodecAUTO;
/** Struct to hold packet buffers */
typedef struct SDL_ffmpegPacket {
struct AVPacket *data;
struct SDL_ffmpegPacket *next;
} SDL_ffmpegPacket;
/** Struct to hold audio data */
typedef struct
{
/** Presentation timestamp, time at which this data should be used. */
int64_t pts;
/** Pointer to audio buffer, user adjustable. */
uint8_t *buffer;
/** Size of this audio frame. */
uint32_t size;
/** Size of the complete audio frame. */
uint32_t capacity;
/** Value indicating wheter or not this is the last frame before EOF */
int last;
} SDL_ffmpegAudioFrame;
/** Struct to hold audio data */
typedef struct
{
/** Presentation timestamp, time at which this data should be used. */
int64_t pts;
/** Pointer to video buffer, user adjustable. */
SDL_Surface *surface;
/** Pointer to overlay buffer, user adjustable. */
SDL_Overlay *overlay;
/** Value indicating if this frame holds data, or that it can be overwritten. */
int ready;
/** Value indicating wheter or not this is the last frame before EOF */
int last;
} SDL_ffmpegVideoFrame;
/** This is the basic stream for SDL_ffmpeg */
typedef struct SDL_ffmpegStream
{
/** Pointer to ffmpeg data, internal use only! */
struct AVStream *_ffmpeg;
/** Intermediate frame which will be used when decoding */
struct AVFrame *decodeFrame;
/** Intermediate frame which will be used when encoding */
struct AVFrame *encodeFrame;
/** Store conversion context for this stream */
struct SDL_ffmpegConversionContext *conversionContext;
int encodeFrameBufferSize;
uint8_t *encodeFrameBuffer;
int encodeAudioInputSize;
uint64_t frameCount;
/** buffer for decoded audio data */
int8_t *sampleBuffer;
/** amount of data in samplebuffer */
int sampleBufferSize;
/** position of data in samplebuffer */
int sampleBufferOffset;
/** timestamp which fits the data in samplebuffer */
int64_t sampleBufferTime;
/** packet buffer */
SDL_ffmpegPacket *buffer;
/** mutex for multi threaded acces to buffer */
SDL_mutex *mutex;
/** Id of the stream */
int id;
/** This holds the lastTimeStamp calculated, usefull when frames don't provide
a usefull dts/pts, also used for determining at what point we are in the file */
int64_t lastTimeStamp;
/** pointer to the next stream, or NULL if current stream is the last one */
struct SDL_ffmpegStream *next;
} SDL_ffmpegStream;
/** Struct to hold information about file */
typedef struct
{
/** type of file */
enum SDL_ffmpegStreamType type;
/** Pointer to ffmpeg data, internal use only! */
struct AVFormatContext *_ffmpeg;
/** Video streams */
SDL_ffmpegStream *vs,
/** Audio streams */
*as;
/** stream mutex */
SDL_mutex *streamMutex;
/** Amount of video streams in file */
uint32_t videoStreams,
/** Amount of audio streams in file */
audioStreams;
/** Pointer to active videoStream, NULL if no video stream is active */
SDL_ffmpegStream *videoStream,
/** Pointer to active audioStream, NULL if no audio stream is active */
*audioStream;
/** Holds the lowest timestamp which will be decoded */
int64_t minimalTimestamp;
} SDL_ffmpegFile;
/* error handling */
const char* SDL_ffmpegGetError();
void SDL_ffmpegClearError();
/* SDL_ffmpegFile create / destroy */
SDL_ffmpegFile* SDL_ffmpegOpen( const char* filename );
SDL_ffmpegFile* SDL_ffmpegCreate( const char* filename );
void SDL_ffmpegFree( SDL_ffmpegFile* file );
/* general */
int SDL_ffmpegSeek( SDL_ffmpegFile* file, uint64_t timestamp );
int SDL_ffmpegSeekRelative( SDL_ffmpegFile* file, int64_t timestamp );
uint64_t SDL_ffmpegDuration( SDL_ffmpegFile *file );
int64_t SDL_ffmpegGetPosition( SDL_ffmpegFile *file );
float SDL_ffmpegGetFrameRate( SDL_ffmpegStream *stream, int *numerator, int *denominator );
/* video stream */
SDL_ffmpegStream* SDL_ffmpegAddVideoStream( SDL_ffmpegFile *file, SDL_ffmpegCodec );
SDL_ffmpegStream* SDL_ffmpegGetVideoStream( SDL_ffmpegFile *file, uint32_t videoID );
int SDL_ffmpegSelectVideoStream( SDL_ffmpegFile* file, int videoID);
/* video frame */
SDL_ffmpegVideoFrame* SDL_ffmpegCreateVideoFrame();
int SDL_ffmpegAddVideoFrame( SDL_ffmpegFile *file, SDL_Surface *frame );
int SDL_ffmpegGetVideoFrame( SDL_ffmpegFile *file, SDL_ffmpegVideoFrame *frame );
void SDL_ffmpegFreeVideoFrame( SDL_ffmpegVideoFrame* frame );
/* video specs */
int SDL_ffmpegGetVideoSize( SDL_ffmpegFile *file, int *w, int *h);
/* general video */
int SDL_ffmpegValidVideo( SDL_ffmpegFile *file );
uint64_t SDL_ffmpegVideoDuration( SDL_ffmpegFile *file );
/* audio stream */
SDL_ffmpegStream* SDL_ffmpegAddAudioStream( SDL_ffmpegFile *file, SDL_ffmpegCodec );
SDL_ffmpegStream* SDL_ffmpegGetAudioStream( SDL_ffmpegFile *file, uint32_t audioID);
int SDL_ffmpegSelectAudioStream( SDL_ffmpegFile* file, int audioID);
/* audio frame */
SDL_ffmpegAudioFrame* SDL_ffmpegCreateAudioFrame( SDL_ffmpegFile *file, uint32_t bytes );
int SDL_ffmpegAddAudioFrame( SDL_ffmpegFile *file, SDL_ffmpegAudioFrame *frame );
int SDL_ffmpegGetAudioFrame( SDL_ffmpegFile *file, SDL_ffmpegAudioFrame *frame );
void SDL_ffmpegFreeAudioFrame( SDL_ffmpegAudioFrame* frame );
/* audio specs */
SDL_AudioSpec SDL_ffmpegGetAudioSpec( SDL_ffmpegFile *file, uint16_t samples, SDL_ffmpegCallback callback );
/* general audio */
int SDL_ffmpegValidAudio( SDL_ffmpegFile *file );
uint64_t SDL_ffmpegAudioDuration( SDL_ffmpegFile *file );
/** \cond */
/* these functions are not public */
SDL_ffmpegFile* SDL_ffmpegCreateFile();
int SDL_ffmpegFlush( SDL_ffmpegFile *file );
/* Ends C function definitions when using C++ */
} /* end tolua module DS */
/* Some code to be included in the generated .c file */