2 * Adobe Filmstrip demuxer
3 * Copyright (c) 2010 Peter Ross
5 * This file is part of Libav.
7 * Libav 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.
12 * Libav 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.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with Libav; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 * Adobe Filmstrip demuxer
27 #include "libavutil/intreadwrite.h"
31 #define RAND_TAG MKBETAG('R','a','n','d')
35 } FilmstripDemuxContext
;
37 static int read_header(AVFormatContext
*s
)
39 FilmstripDemuxContext
*film
= s
->priv_data
;
40 AVIOContext
*pb
= s
->pb
;
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");
49 return AVERROR_INVALIDDATA
;
52 st
= avformat_new_stream(s
, NULL
);
54 return AVERROR(ENOMEM
);
56 st
->nb_frames
= avio_rb32(pb
);
57 if (avio_rb16(pb
) != 0) {
58 av_log_ask_for_sample(s
, "unsupported packing method\n");
59 return AVERROR_PATCHWELCOME
;
63 st
->codec
->codec_type
= AVMEDIA_TYPE_VIDEO
;
64 st
->codec
->codec_id
= AV_CODEC_ID_RAWVIDEO
;
65 st
->codec
->pix_fmt
= AV_PIX_FMT_RGBA
;
66 st
->codec
->codec_tag
= 0; /* no fourcc */
67 st
->codec
->width
= avio_rb16(pb
);
68 st
->codec
->height
= avio_rb16(pb
);
69 film
->leading
= avio_rb16(pb
);
70 avpriv_set_pts_info(st
, 64, 1, avio_rb16(pb
));
72 avio_seek(pb
, 0, SEEK_SET
);
77 static int read_packet(AVFormatContext
*s
,
80 FilmstripDemuxContext
*film
= s
->priv_data
;
81 AVStream
*st
= s
->streams
[0];
83 if (s
->pb
->eof_reached
)
85 pkt
->dts
= avio_tell(s
->pb
) / (st
->codec
->width
* (st
->codec
->height
+ film
->leading
) * 4);
86 pkt
->size
= av_get_packet(s
->pb
, pkt
, st
->codec
->width
* st
->codec
->height
* 4);
87 avio_skip(s
->pb
, st
->codec
->width
* film
->leading
* 4);
90 pkt
->flags
|= AV_PKT_FLAG_KEY
;
94 static int read_seek(AVFormatContext
*s
, int stream_index
, int64_t timestamp
, int flags
)
96 AVStream
*st
= s
->streams
[stream_index
];
97 if (avio_seek(s
->pb
, FFMAX(timestamp
, 0) * st
->codec
->width
* st
->codec
->height
* 4, SEEK_SET
) < 0)
102 AVInputFormat ff_filmstrip_demuxer
= {
104 .long_name
= NULL_IF_CONFIG_SMALL("Adobe Filmstrip"),
105 .priv_data_size
= sizeof(FilmstripDemuxContext
),
106 .read_header
= read_header
,
107 .read_packet
= read_packet
,
108 .read_seek
= read_seek
,