FFmpeg
Loading...
Searching...
No Matches
frmdec.c
Go to the documentation of this file.
1/*
2 * Megalux Frame demuxer
3 * Copyright (c) 2010 Peter Ross <pross@xvid.org>
4 *
5 * This file is part of FFmpeg.
6 *
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.
11 *
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.
16 *
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
20 */
21
22/**
23 * @file
24 * Megalux Frame demuxer
25 */
26
27#include "libavutil/imgutils.h"
29#include "avformat.h"
30#include "demux.h"
31
39
40typedef struct {
41 int count;
43
44static int frm_read_probe(const AVProbeData *p)
45{
46 if (p->buf_size > 8 &&
47 p->buf[0] == 'F' && p->buf[1] == 'R' && p->buf[2] == 'M' &&
48 AV_RL16(&p->buf[4]) && AV_RL16(&p->buf[6]))
49 return AVPROBE_SCORE_MAX / 4;
50 return 0;
51}
52
54{
55 AVIOContext *pb = avctx->pb;
56 AVStream *st = avformat_new_stream(avctx, 0);
57 unsigned idx;
58
59 if (!st)
60 return AVERROR(ENOMEM);
61
64 avio_skip(pb, 3);
65
66 idx = avio_r8(pb) - 1;
70
71 st->codecpar->codec_tag = 0;
72 st->codecpar->width = avio_rl16(pb);
73 st->codecpar->height = avio_rl16(pb);
74 return 0;
75}
76
78{
79 FrmContext *s = avctx->priv_data;
80 AVCodecParameters *par = avctx->streams[0]->codecpar;
81 int packet_size, ret;
82
83 if (s->count)
84 return AVERROR_EOF;
85
86 packet_size = av_image_get_buffer_size(par->format, par->width, par->height, 1);
87 if (packet_size < 0)
89
90 ret = av_get_packet(avctx->pb, pkt, packet_size);
91 if (ret < 0)
92 return ret;
93
94 if (par->format == AV_PIX_FMT_BGRA) {
95 int i;
96 for (i = 3; i + 1 <= pkt->size; i += 4)
97 pkt->data[i] = 0xFF - pkt->data[i];
98 }
99
100 pkt->stream_index = 0;
101 s->count++;
102
103 return 0;
104}
105
107 .p.name = "frm",
108 .p.long_name = NULL_IF_CONFIG_SMALL("Megalux Frame"),
109 .priv_data_size = sizeof(FrmContext),
113};
const FFInputFormat ff_frm_demuxer
Definition frmdec.c:106
Main libavformat public API header.
#define AVPROBE_SCORE_MAX
maximum score
Definition avformat.h:483
int av_get_packet(AVIOContext *s, AVPacket *pkt, int size)
Allocate and read the payload of a packet and initialize its fields with default values.
Definition utils.c:98
unsigned int avio_rl16(AVIOContext *s)
Definition aviobuf.c:717
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition aviobuf.c:321
int avio_r8(AVIOContext *s)
Definition aviobuf.c:606
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
static int read_probe(const AVProbeData *p)
Definition cdg.c:30
static AVPacket * pkt
static int read_header(FFV1Context *f, RangeCoder *c)
Definition ffv1dec.c:578
static int frm_read_packet(AVFormatContext *avctx, AVPacket *pkt)
Definition frmdec.c:77
static int frm_read_probe(const AVProbeData *p)
Definition frmdec.c:44
static enum AVPixelFormat frm_pix_fmt_tags[]
Definition frmdec.c:32
static int frm_read_header(AVFormatContext *avctx)
Definition frmdec.c:53
@ AV_CODEC_ID_RAWVIDEO
Definition codec_id.h:63
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR_EOF
End of file.
Definition error.h:57
#define AVERROR(e)
Definition error.h:45
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
int av_image_get_buffer_size(enum AVPixelFormat pix_fmt, int width, int height, int align)
Return the size in bytes of the amount of data required to store an image with the given parameters.
Definition imgutils.c:466
misc image utilities
#define AV_RL16(p)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition pixfmt.h:75
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
Definition pixfmt.h:265
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition pixfmt.h:102
@ AV_PIX_FMT_RGB0
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
Definition pixfmt.h:263
#define AV_PIX_FMT_RGB555
Definition pixfmt.h:533
#define FF_ARRAY_ELEMS(a)
This struct describes the properties of an encoded stream.
Definition codec_par.h:49
int height
The height of the video frame in pixels.
Definition codec_par.h:150
int width
The width of the video frame in pixels.
Definition codec_par.h:143
enum AVMediaType codec_type
General type of the encoded data.
Definition codec_par.h:53
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition codec_par.h:61
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition codec_par.h:57
Format I/O context.
Definition avformat.h:1333
AVIOContext * pb
I/O context.
Definition avformat.h:1375
void * priv_data
Format private data.
Definition avformat.h:1361
AVStream ** streams
A list of all streams in the file.
Definition avformat.h:1401
Bytestream IO Context.
Definition avio.h:160
This structure stores compressed data.
Definition packet.h:580
This structure contains the data a format has to probe a file.
Definition avformat.h:471
Stream structure.
Definition avformat.h:766
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition avformat.h:789
int count
Definition frmdec.c:41