1 /*
2 * FLI/FLC Animation File Demuxer
3 * Copyright (c) 2003 The FFmpeg project
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * FLI/FLC file demuxer
25 * by Mike Melanson (melanson@pcisys.net)
26 * for more information on the .fli/.flc file format and all of its many
27 * variations, visit:
28 * http://www.compuphase.com/flic.htm
29 *
30 * This demuxer handles standard 0xAF11- and 0xAF12-type FLIs. It also handles
31 * special FLIs from the PC games "Magic Carpet" and "X-COM: Terror from the Deep".
32 */
33
38
39 #define FLIC_FILE_MAGIC_1 0xAF11
40 #define FLIC_FILE_MAGIC_2 0xAF12
41 #define FLIC_FILE_MAGIC_3 0xAF44 /* Flic Type for Extended FLX Format which
42 originated in Dave's Targa Animator (DTA) */
43 #define FLIC_CHUNK_MAGIC_1 0xF1FA
44 #define FLIC_CHUNK_MAGIC_2 0xF5FA
45 #define FLIC_MC_SPEED 5 /* speed for Magic Carpet game FLIs */
46 #define FLIC_DEFAULT_SPEED 5 /* for FLIs that have 0 speed */
47 #define FLIC_TFTD_CHUNK_AUDIO 0xAAAA /* Audio chunk. Used in Terror from the Deep.
48 Has 10 B extra header not accounted for in the chunk header */
49 #define FLIC_TFTD_SAMPLE_RATE 22050
50
51 #define FLIC_HEADER_SIZE 128
52 #define FLIC_PREAMBLE_SIZE 6
53
59
61 {
62 int magic_number;
63
65 return 0;
66
71 return 0;
72
75 return 0;
76 }
77
80 return 0;
81
82
84 }
85
87 {
92 int speed;
93 int magic_number;
95
97
98 /* load the whole header and pull out the width and height */
101
102 magic_number =
AV_RL16(&header[4]);
103 speed =
AV_RL32(&header[0x10]);
104 if (speed == 0)
106
107 /* initialize the decoder streams */
109 if (!st)
117
119 /* Ugly hack needed for the following sample: */
120 /* http://samples.mplayerhq.hu/fli-flc/fli-bugs/specular.flc */
122 "File with no specified width/height. Trying 640x480.\n");
125 }
126
127 /* send over the whole 128-byte FLIC header */
131
132 /* peek at the preamble to detect TFTD videos - they seem to always start with an audio chunk */
136 }
137
139
140 /* Time to figure out the framerate:
141 * If the first preamble's magic number is 0xAAAA then this file is from
142 * X-COM: Terror from the Deep. If on the other hand there is a FLIC chunk
143 * magic number at offset 0x10 assume this file is from Magic Carpet instead.
144 * If neither of the above is true then this is a normal FLIC file.
145 */
147 /* TFTD videos have an extra 22050 Hz 8-bit mono audio stream */
149 if (!ast)
151
153
154 /* all audio frames are the same size, so use the size of the first chunk for block_align */
165
166 /* Since the header information is incorrect we have to figure out the
167 * framerate using block_align and the fact that the audio is 22050 Hz.
168 * We usually have two cases: 2205 -> 10 fps and 1470 -> 15 fps */
173
174 /* rewind the stream since the first chunk is at offset 12 */
176
177 /* send over abbreviated FLIC header chunk */
182
188 } else {
191 }
192
193 return 0;
194 }
195
198 {
201 int packet_read = 0;
203 int magic;
204 int ret = 0;
206
208
212 break;
213 }
214
217
221 break;
222 }
232 }
233 packet_read = 1;
237 break;
238 }
239
240 /* skip useless 10B sub-header (yes, it's not accounted for in the chunk header) */
242
246
247 if (ret != size) {
250 }
251
252 packet_read = 1;
253 } else {
254 /* not interested in this chunk */
256 }
257 }
258
260 }
261
269 };
#define FLIC_CHUNK_MAGIC_2
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_WARNING
Something somehow does not look correct.
int64_t pos
byte position in stream, -1 if unknown
#define FLIC_FILE_MAGIC_2
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
int index
stream index in AVFormatContext
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_RL16
#define FLIC_TFTD_CHUNK_AUDIO
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
#define AVERROR_EOF
End of file.
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
static const uint8_t header[24]
uint64_t channel_layout
Audio only.
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
enum AVMediaType codec_type
General type of the encoded data.
#define FLIC_FILE_MAGIC_3
int extradata_size
Size of the extradata content in bytes.
int buf_size
Size of buf except extra allocated bytes.
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
int block_align
Audio only.
audio channel layout utility functions
static int flic_probe(AVProbeData *p)
#define FLIC_TFTD_SAMPLE_RATE
static int read_header(FFV1Context *f)
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
#define FLIC_FILE_MAGIC_1
static int flic_read_header(AVFormatContext *s)
AVIOContext * pb
I/O context.
AVInputFormat ff_flic_demuxer
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
#define FLIC_CHUNK_MAGIC_1
#define FLIC_PREAMBLE_SIZE
This structure contains the data a format has to probe a file.
int sample_rate
Audio only.
#define FLIC_DEFAULT_SPEED
void * priv_data
Format private data.
int bits_per_coded_sample
The number of bits per sample in the codedwords.
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
AVCodecParameters * codecpar
Codec parameters associated with this stream.
int avio_feof(AVIOContext *s)
feof() equivalent for AVIOContext.
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
#define AV_CH_LAYOUT_MONO
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
static int flic_read_packet(AVFormatContext *s, AVPacket *pkt)