FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
filmstripdec.c
Go to the documentation of this file.
1 /*
2  * Adobe Filmstrip demuxer
3  * Copyright (c) 2010 Peter Ross
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  * Adobe Filmstrip demuxer
25  */
26 
27 #include "libavutil/intreadwrite.h"
28 #include "avformat.h"
29 #include "internal.h"
30 
31 #define RAND_TAG MKBETAG('R','a','n','d')
32 
33 typedef struct FilmstripDemuxContext {
34  int leading;
36 
38 {
40  AVIOContext *pb = s->pb;
41  AVStream *st;
42 
43  if (!s->pb->seekable)
44  return AVERROR(EIO);
45 
46  avio_seek(pb, avio_size(pb) - 36, SEEK_SET);
47  if (avio_rb32(pb) != RAND_TAG) {
48  av_log(s, AV_LOG_ERROR, "magic number not found\n");
49  return AVERROR_INVALIDDATA;
50  }
51 
52  st = avformat_new_stream(s, NULL);
53  if (!st)
54  return AVERROR(ENOMEM);
55 
56  st->nb_frames = avio_rb32(pb);
57  if (avio_rb16(pb) != 0) {
58  avpriv_request_sample(s, "Unsupported packing method");
59  return AVERROR_PATCHWELCOME;
60  }
61 
62  avio_skip(pb, 2);
66  st->codecpar->codec_tag = 0; /* no fourcc */
67  st->codecpar->width = avio_rb16(pb);
68  st->codecpar->height = avio_rb16(pb);
69  film->leading = avio_rb16(pb);
70 
71  if (st->codecpar->width * 4LL * st->codecpar->height >= INT_MAX) {
72  av_log(s, AV_LOG_ERROR, "dimensions too large\n");
73  return AVERROR_PATCHWELCOME;
74  }
75 
76  avpriv_set_pts_info(st, 64, 1, avio_rb16(pb));
77 
78  avio_seek(pb, 0, SEEK_SET);
79 
80  return 0;
81 }
82 
84  AVPacket *pkt)
85 {
87  AVStream *st = s->streams[0];
88 
89  if (avio_feof(s->pb))
90  return AVERROR(EIO);
91  pkt->dts = avio_tell(s->pb) / (st->codecpar->width * (int64_t)(st->codecpar->height + film->leading) * 4);
92  pkt->size = av_get_packet(s->pb, pkt, st->codecpar->width * st->codecpar->height * 4);
93  avio_skip(s->pb, st->codecpar->width * (int64_t) film->leading * 4);
94  if (pkt->size < 0)
95  return pkt->size;
96  pkt->flags |= AV_PKT_FLAG_KEY;
97  return 0;
98 }
99 
100 static int read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
101 {
102  AVStream *st = s->streams[stream_index];
103  if (avio_seek(s->pb, FFMAX(timestamp, 0) * st->codecpar->width * st->codecpar->height * 4, SEEK_SET) < 0)
104  return -1;
105  return 0;
106 }
107 
109  .name = "filmstrip",
110  .long_name = NULL_IF_CONFIG_SMALL("Adobe Filmstrip"),
111  .priv_data_size = sizeof(FilmstripDemuxContext),
114  .read_seek = read_seek,
115  .extensions = "flm",
116 };
#define NULL
Definition: coverity.c:32
const char * s
Definition: avisynth_c.h:768
Bytestream IO Context.
Definition: avio.h:147
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:309
void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition: utils.c:4560
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:3980
int size
Definition: avcodec.h:1602
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:230
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:304
static AVPacket pkt
unsigned int avio_rb16(AVIOContext *s)
Definition: aviobuf.c:742
Format I/O context.
Definition: avformat.h:1338
static int read_header(AVFormatContext *s)
Definition: filmstripdec.c:37
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
int width
Video only.
Definition: avcodec.h:4046
unsigned int avio_rb32(AVIOContext *s)
Definition: aviobuf.c:757
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:4193
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1406
int av_get_packet(AVIOContext *s, AVPacket *pkt, int size)
Allocate and read the payload of a packet and initialize its fields with default values.
Definition: utils.c:289
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:511
#define av_log(a,...)
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1633
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
#define AVERROR(e)
Definition: error.h:43
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:176
enum AVMediaType codec_type
General type of the encoded data.
Definition: avcodec.h:3976
#define FFMAX(a, b)
Definition: common.h:94
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:94
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:1607
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:243
#define RAND_TAG
Definition: filmstripdec.c:31
static int read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
Definition: filmstripdec.c:100
static int read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: filmstripdec.c:83
Stream structure.
Definition: avformat.h:889
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
AVIOContext * pb
I/O context.
Definition: avformat.h:1380
AVInputFormat ff_filmstrip_demuxer
Definition: filmstripdec.c:108
static int flags
Definition: cpu.c:47
Main libavformat public API header.
int64_t nb_frames
number of frames in this stream if known or 0
Definition: avformat.h:945
void * priv_data
Format private data.
Definition: avformat.h:1366
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: avcodec.h:1600
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:664
AVCodecParameters * codecpar
Definition: avformat.h:1241
int avio_feof(AVIOContext *s)
feof() equivalent for AVIOContext.
Definition: aviobuf.c:328
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition: avcodec.h:3984
This structure stores compressed data.
Definition: avcodec.h:1578