00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "avformat.h"
00022 #include "riff.h"
00023 #include "libavutil/intreadwrite.h"
00024
00025 static int probe(AVProbeData *p)
00026 {
00027 if (AV_RL32(p->buf) == MKTAG('D','K','I','F')
00028 && !AV_RL16(p->buf+4) && AV_RL16(p->buf+6) == 32)
00029 return AVPROBE_SCORE_MAX-2;
00030
00031 return 0;
00032 }
00033
00034 static int read_header(AVFormatContext *s, AVFormatParameters *ap)
00035 {
00036 AVStream *st;
00037 AVRational time_base;
00038
00039 avio_rl32(s->pb);
00040 avio_rl16(s->pb);
00041 avio_rl16(s->pb);
00042
00043 st = av_new_stream(s, 0);
00044 if (!st)
00045 return AVERROR(ENOMEM);
00046
00047
00048 st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
00049 st->codec->codec_tag = avio_rl32(s->pb);
00050 st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, st->codec->codec_tag);
00051 st->codec->width = avio_rl16(s->pb);
00052 st->codec->height = avio_rl16(s->pb);
00053 time_base.den = avio_rl32(s->pb);
00054 time_base.num = avio_rl32(s->pb);
00055 st->duration = avio_rl64(s->pb);
00056
00057 st->need_parsing = AVSTREAM_PARSE_HEADERS;
00058
00059 if (!time_base.den || !time_base.num) {
00060 av_log(s, AV_LOG_ERROR, "Invalid frame rate\n");
00061 return AVERROR_INVALIDDATA;
00062 }
00063
00064 av_set_pts_info(st, 64, time_base.num, time_base.den);
00065
00066 return 0;
00067 }
00068
00069 static int read_packet(AVFormatContext *s, AVPacket *pkt)
00070 {
00071 int ret, size = avio_rl32(s->pb);
00072 int64_t pts = avio_rl64(s->pb);
00073
00074 ret = av_get_packet(s->pb, pkt, size);
00075 pkt->stream_index = 0;
00076 pkt->pts = pts;
00077 pkt->pos -= 12;
00078
00079 return ret;
00080 }
00081
00082 AVInputFormat ff_ivf_demuxer = {
00083 "ivf",
00084 NULL_IF_CONFIG_SMALL("On2 IVF"),
00085 0,
00086 probe,
00087 read_header,
00088 read_packet,
00089 .flags= AVFMT_GENERIC_INDEX,
00090 .codec_tag = (const AVCodecTag*[]){ff_codec_bmp_tags, 0},
00091 };