00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00027 #include "libavutil/intreadwrite.h"
00028 #include "avformat.h"
00029
00030 #define RAND_TAG MKBETAG('R','a','n','d')
00031
00032 typedef struct {
00033 int leading;
00034 } FilmstripDemuxContext;
00035
00036 static int read_header(AVFormatContext *s,
00037 AVFormatParameters *ap)
00038 {
00039 FilmstripDemuxContext *film = s->priv_data;
00040 AVIOContext *pb = s->pb;
00041 AVStream *st;
00042
00043 if (!s->pb->seekable)
00044 return AVERROR(EIO);
00045
00046 avio_seek(pb, avio_size(pb) - 36, SEEK_SET);
00047 if (avio_rb32(pb) != RAND_TAG) {
00048 av_log(s, AV_LOG_ERROR, "magic number not found");
00049 return AVERROR_INVALIDDATA;
00050 }
00051
00052 st = av_new_stream(s, 0);
00053 if (!st)
00054 return AVERROR(ENOMEM);
00055
00056 st->nb_frames = avio_rb32(pb);
00057 if (avio_rb16(pb) != 0) {
00058 av_log_ask_for_sample(s, "unsupported packing method\n");
00059 return AVERROR_INVALIDDATA;
00060 }
00061
00062 avio_skip(pb, 2);
00063 st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
00064 st->codec->codec_id = CODEC_ID_RAWVIDEO;
00065 st->codec->pix_fmt = PIX_FMT_RGBA;
00066 st->codec->codec_tag = 0;
00067 st->codec->width = avio_rb16(pb);
00068 st->codec->height = avio_rb16(pb);
00069 film->leading = avio_rb16(pb);
00070 av_set_pts_info(st, 64, 1, avio_rb16(pb));
00071
00072 avio_seek(pb, 0, SEEK_SET);
00073
00074 return 0;
00075 }
00076
00077 static int read_packet(AVFormatContext *s,
00078 AVPacket *pkt)
00079 {
00080 FilmstripDemuxContext *film = s->priv_data;
00081 AVStream *st = s->streams[0];
00082
00083 if (url_feof(s->pb))
00084 return AVERROR(EIO);
00085 pkt->dts = avio_tell(s->pb) / (st->codec->width * (st->codec->height + film->leading) * 4);
00086 pkt->size = av_get_packet(s->pb, pkt, st->codec->width * st->codec->height * 4);
00087 avio_skip(s->pb, st->codec->width * film->leading * 4);
00088 if (pkt->size < 0)
00089 return pkt->size;
00090 pkt->flags |= AV_PKT_FLAG_KEY;
00091 return 0;
00092 }
00093
00094 static int read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
00095 {
00096 AVStream *st = s->streams[stream_index];
00097 avio_seek(s->pb, FFMAX(timestamp, 0) * st->codec->width * st->codec->height * 4, SEEK_SET);
00098 return 0;
00099 }
00100
00101 AVInputFormat ff_filmstrip_demuxer = {
00102 "filmstrip",
00103 NULL_IF_CONFIG_SMALL("Adobe Filmstrip"),
00104 sizeof(FilmstripDemuxContext),
00105 NULL,
00106 read_header,
00107 read_packet,
00108 NULL,
00109 read_seek,
00110 .extensions = "flm",
00111 };