3 * Copyright (c) 2020 Paul B Mahol
5 * This file is part of FFmpeg.
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.
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.
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
22 #include "libavutil/intreadwrite.h"
27 static int mods_probe(const AVProbeData *p)
29 if (memcmp(p->buf, "MODSN3\x0a\x00", 8))
31 if (AV_RB32(p->buf + 8) == 0)
33 if (AV_RB32(p->buf + 12) == 0)
35 if (AV_RB32(p->buf + 16) == 0)
37 return AVPROBE_SCORE_MAX;
40 static int mods_read_header(AVFormatContext *s)
42 AVIOContext *pb = s->pb;
46 AVStream *st = avformat_new_stream(s, NULL);
48 return AVERROR(ENOMEM);
52 st->nb_frames = avio_rl32(pb);
53 st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
54 st->codecpar->codec_id = AV_CODEC_ID_MOBICLIP;
55 st->codecpar->width = avio_rl32(pb);
56 st->codecpar->height = avio_rl32(pb);
58 fps.num = avio_rl32(pb);
60 avpriv_set_pts_info(st, 64, fps.den, fps.num);
64 pos = avio_rl32(pb) + 4;
65 avio_seek(pb, pos, SEEK_SET);
67 avio_seek(pb, pos, SEEK_SET);
72 static int mods_read_packet(AVFormatContext *s, AVPacket *pkt)
74 AVIOContext *pb = s->pb;
83 size = avio_rl32(pb) >> 14;
84 ret = av_get_packet(pb, pkt, size);
86 pkt->stream_index = 0;
87 pkt->flags |= AV_PKT_FLAG_KEY;
92 AVInputFormat ff_mods_demuxer = {
94 .long_name = NULL_IF_CONFIG_SMALL("MobiClip MODS"),
95 .read_probe = mods_probe,
96 .read_header = mods_read_header,
97 .read_packet = mods_read_packet,
99 .flags = AVFMT_GENERIC_INDEX,