Libav
|
00001 /* 00002 * Adobe Filmstrip demuxer 00003 * Copyright (c) 2010 Peter Ross 00004 * 00005 * This file is part of FFmpeg. 00006 * 00007 * FFmpeg is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * FFmpeg is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with FFmpeg; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 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 ByteIOContext *pb = s->pb; 00041 AVStream *st; 00042 00043 if (url_is_streamed(s->pb)) 00044 return AVERROR(EIO); 00045 00046 url_fseek(pb, url_fsize(pb) - 36, SEEK_SET); 00047 if (get_be32(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 = get_be32(pb); 00057 if (get_be16(pb) != 0) { 00058 av_log_ask_for_sample(s, "unsupported packing method\n"); 00059 return AVERROR_INVALIDDATA; 00060 } 00061 00062 url_fskip(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; /* no fourcc */ 00067 st->codec->width = get_be16(pb); 00068 st->codec->height = get_be16(pb); 00069 film->leading = get_be16(pb); 00070 av_set_pts_info(st, 64, 1, get_be16(pb)); 00071 00072 url_fseek(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 = url_ftell(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 url_fskip(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 url_fseek(s->pb, FFMAX(timestamp, 0) * st->codec->width * st->codec->height * 4, SEEK_SET); 00098 return 0; 00099 } 00100 00101 AVInputFormat 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 };