FFmpeg
Loading...
Searching...
No Matches
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
28#include "libavutil/imgutils.h"
29#include "avformat.h"
30#include "demux.h"
31#include "internal.h"
32
33#define RAND_TAG MKBETAG('R','a','n','d')
34
38
40{
41 FilmstripDemuxContext *film = s->priv_data;
42 AVIOContext *pb = s->pb;
43 AVStream *st;
44
45 if (!(s->pb->seekable & AVIO_SEEKABLE_NORMAL))
46 return AVERROR(ENOSYS);
47
48 avio_seek(pb, avio_size(pb) - 36, SEEK_SET);
49 if (avio_rb32(pb) != RAND_TAG) {
50 av_log(s, AV_LOG_ERROR, "magic number not found\n");
52 }
53
55 if (!st)
56 return AVERROR(ENOMEM);
57
58 st->nb_frames = avio_rb32(pb);
59 if (avio_rb16(pb) != 0) {
60 avpriv_request_sample(s, "Unsupported packing method");
62 }
63
64 avio_skip(pb, 2);
68 st->codecpar->codec_tag = 0; /* no fourcc */
69 st->codecpar->width = avio_rb16(pb);
70 st->codecpar->height = avio_rb16(pb);
71 film->leading = avio_rb16(pb);
72
73 if (av_image_check_size(st->codecpar->width, st->codecpar->height, 0, s) < 0)
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
85{
86 FilmstripDemuxContext *film = s->priv_data;
87 AVStream *st = s->streams[0];
88
89 if (avio_feof(s->pb))
90 return AVERROR_EOF;
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
100static 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 .p.name = "filmstrip",
110 .p.long_name = NULL_IF_CONFIG_SMALL("Adobe Filmstrip"),
111 .p.extensions = "flm",
112 .priv_data_size = sizeof(FilmstripDemuxContext),
116};
const FFInputFormat ff_filmstrip_demuxer
void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition avformat.c:834
Main libavformat public API header.
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:98
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition aviobuf.c:236
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
Definition avio.h:41
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition aviobuf.c:326
unsigned int avio_rb16(AVIOContext *s)
Definition aviobuf.c:749
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Definition aviobuf.c:349
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition avio.h:494
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition aviobuf.c:321
unsigned int avio_rb32(AVIOContext *s)
Definition aviobuf.c:764
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define s(width, name)
Definition cbs_vp9.c:198
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
static AVPacket * pkt
static int read_header(FFV1Context *f, RangeCoder *c)
Definition ffv1dec.c:578
static int read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
#define RAND_TAG
static int read_packet(AVFormatContext *s, AVPacket *pkt)
static int read_header(AVFormatContext *s)
@ AV_CODEC_ID_RAWVIDEO
Definition codec_id.h:63
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition packet.h:650
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition error.h:64
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR_EOF
End of file.
Definition error.h:57
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
Definition imgutils.c:318
misc image utilities
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
Definition libcdio.c:151
#define FFMAX(a, b)
Definition macros.h:47
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition pixfmt.h:100
int height
The height of the video frame in pixels.
Definition codec_par.h:150
int width
The width of the video frame in pixels.
Definition codec_par.h:143
enum AVMediaType codec_type
General type of the encoded data.
Definition codec_par.h:53
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition codec_par.h:61
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition codec_par.h:57
Format I/O context.
Definition avformat.h:1333
Bytestream IO Context.
Definition avio.h:160
This structure stores compressed data.
Definition packet.h:580
Stream structure.
Definition avformat.h:766
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition avformat.h:789
int64_t nb_frames
number of frames in this stream if known or 0
Definition avformat.h:827
#define avpriv_request_sample(...)
#define av_log(a,...)