FFmpeg
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 "libavutil/imgutils.h"
29 #include "avformat.h"
30 #include "internal.h"
31 
32 #define RAND_TAG MKBETAG('R','a','n','d')
33 
34 typedef struct FilmstripDemuxContext {
35  int leading;
37 
39 {
40  FilmstripDemuxContext *film = s->priv_data;
41  AVIOContext *pb = s->pb;
42  AVStream *st;
43 
44  if (!(s->pb->seekable & AVIO_SEEKABLE_NORMAL))
45  return AVERROR(EIO);
46 
47  avio_seek(pb, avio_size(pb) - 36, SEEK_SET);
48  if (avio_rb32(pb) != RAND_TAG) {
49  av_log(s, AV_LOG_ERROR, "magic number not found\n");
50  return AVERROR_INVALIDDATA;
51  }
52 
53  st = avformat_new_stream(s, NULL);
54  if (!st)
55  return AVERROR(ENOMEM);
56 
57  st->nb_frames = avio_rb32(pb);
58  if (avio_rb16(pb) != 0) {
59  avpriv_request_sample(s, "Unsupported packing method");
60  return AVERROR_PATCHWELCOME;
61  }
62 
63  avio_skip(pb, 2);
67  st->codecpar->codec_tag = 0; /* no fourcc */
68  st->codecpar->width = avio_rb16(pb);
69  st->codecpar->height = avio_rb16(pb);
70  film->leading = avio_rb16(pb);
71 
72  if (av_image_check_size(st->codecpar->width, st->codecpar->height, 0, s) < 0)
73  return AVERROR_INVALIDDATA;
74 
75  avpriv_set_pts_info(st, 64, 1, avio_rb16(pb));
76 
77  avio_seek(pb, 0, SEEK_SET);
78 
79  return 0;
80 }
81 
83  AVPacket *pkt)
84 {
85  FilmstripDemuxContext *film = s->priv_data;
86  AVStream *st = s->streams[0];
87 
88  if (avio_feof(s->pb))
89  return AVERROR(EIO);
90  pkt->dts = avio_tell(s->pb) / (st->codecpar->width * (int64_t)(st->codecpar->height + film->leading) * 4);
91  pkt->size = av_get_packet(s->pb, pkt, st->codecpar->width * st->codecpar->height * 4);
92  avio_skip(s->pb, st->codecpar->width * (int64_t) film->leading * 4);
93  if (pkt->size < 0)
94  return pkt->size;
96  return 0;
97 }
98 
99 static int read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
100 {
101  AVStream *st = s->streams[stream_index];
102  if (avio_seek(s->pb, FFMAX(timestamp, 0) * st->codecpar->width * st->codecpar->height * 4, SEEK_SET) < 0)
103  return -1;
104  return 0;
105 }
106 
108  .name = "filmstrip",
109  .long_name = NULL_IF_CONFIG_SMALL("Adobe Filmstrip"),
110  .priv_data_size = sizeof(FilmstripDemuxContext),
113  .read_seek = read_seek,
114  .extensions = "flm",
115 };
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
avformat_new_stream
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: options.c:237
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:57
AV_CODEC_ID_RAWVIDEO
@ AV_CODEC_ID_RAWVIDEO
Definition: codec_id.h:63
AVCodecParameters::codec_tag
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition: codec_par.h:65
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
avio_size
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:352
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:429
avpriv_set_pts_info
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:697
avio_tell
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:505
read_packet
static int read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: filmstripdec.c:82
avio_rb32
unsigned int avio_rb32(AVIOContext *s)
Definition: aviobuf.c:790
pkt
AVPacket * pkt
Definition: movenc.c:59
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
AVInputFormat
Definition: avformat.h:656
read_header
static int read_header(AVFormatContext *s)
Definition: filmstripdec.c:38
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:256
ff_filmstrip_demuxer
const AVInputFormat ff_filmstrip_demuxer
Definition: filmstripdec.c:107
AVInputFormat::name
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:661
AVCodecParameters::width
int width
Video only.
Definition: codec_par.h:127
AV_PIX_FMT_RGBA
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:93
AVFormatContext
Format I/O context.
Definition: avformat.h:1213
internal.h
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1108
NULL
#define NULL
Definition: coverity.c:32
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
AVStream::nb_frames
int64_t nb_frames
number of frames in this stream if known or 0
Definition: avformat.h:1000
AVIOContext
Bytestream IO Context.
Definition: avio.h:162
AVPacket::size
int size
Definition: packet.h:375
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
read_seek
static int read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
Definition: filmstripdec.c:99
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:373
FilmstripDemuxContext::leading
int leading
Definition: filmstripdec.c:35
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:380
RAND_TAG
#define RAND_TAG
Definition: filmstripdec.c:32
AVCodecParameters::height
int height
Definition: codec_par.h:128
av_get_packet
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:102
AVStream
Stream structure.
Definition: avformat.h:948
avio_seek
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:260
avio_rb16
unsigned int avio_rb16(AVIOContext *s)
Definition: aviobuf.c:775
avformat.h
AVIO_SEEKABLE_NORMAL
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
Definition: avio.h:41
avio_skip
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:347
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
avpriv_request_sample
#define avpriv_request_sample(...)
Definition: tableprint_vlc.h:36
AVCodecParameters::format
int format
Definition: codec_par.h:85
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:61
AVPacket
This structure stores compressed data.
Definition: packet.h:351
imgutils.h
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
av_image_check_size
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
FilmstripDemuxContext
Definition: filmstripdec.c:34
avio_feof
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Definition: aviobuf.c:375