FFmpeg
mj2kdec.c
Go to the documentation of this file.
1 /*
2  * MJPEG 2000 Demuxer
3  * Copyright (c) 2016 StÃ¥le Kristoffersen
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 #include "config_components.h"
23 
24 #include "libavutil/intreadwrite.h"
25 #include "avformat.h"
26 #include "rawdec.h"
27 
28 #if CONFIG_MJPEG_2000_DEMUXER
29 static int mjpeg2000_probe(const AVProbeData *p)
30 {
31  const uint8_t *b = p->buf;
32  int i, marker, marker_size;
33  int frames = 0, invalid = 0;
34 
35  for (i = 0; i < p->buf_size - 5; i++) {
36  if (AV_RB32(b) == 0xff4fff51){
37  marker_size = AV_RB16(b+4);
38  if (marker_size + i < p->buf_size - 4) {
39  marker = AV_RB8(b+4+marker_size);
40  if (marker == 0xff)
41  frames++;
42  else
43  invalid++;
44  }
45  }
46  b += 1;
47  }
48  if (invalid*4 + 1 < frames) {
49  if (invalid == 0 && frames > 2)
50  return AVPROBE_SCORE_EXTENSION / 2;
51  return AVPROBE_SCORE_EXTENSION / 4;
52  }
53  return 0;
54 }
55 FF_DEF_RAWVIDEO_DEMUXER2(mjpeg_2000, "raw MJPEG 2000 video", mjpeg2000_probe, "j2k", AV_CODEC_ID_JPEG2000, AVFMT_GENERIC_INDEX|AVFMT_NOTIMESTAMPS)
56 #endif
AVFMT_NOTIMESTAMPS
#define AVFMT_NOTIMESTAMPS
Format does not need / have any timestamps.
Definition: avformat.h:481
b
#define b
Definition: input.c:34
AVProbeData::buf_size
int buf_size
Size of buf except extra allocated bytes.
Definition: avformat.h:456
frames
if it could not because there are no more frames
Definition: filter_design.txt:266
AVFMT_GENERIC_INDEX
#define AVFMT_GENERIC_INDEX
Use generic index building code.
Definition: avformat.h:482
intreadwrite.h
AVProbeData::buf
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:455
rawdec.h
AVProbeData
This structure contains the data a format has to probe a file.
Definition: avformat.h:453
AVPROBE_SCORE_EXTENSION
#define AVPROBE_SCORE_EXTENSION
score for file extension
Definition: avformat.h:463
AV_RB32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
Definition: bytestream.h:96
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
AV_CODEC_ID_JPEG2000
@ AV_CODEC_ID_JPEG2000
Definition: codec_id.h:138
avformat.h
FF_DEF_RAWVIDEO_DEMUXER2
#define FF_DEF_RAWVIDEO_DEMUXER2(shortname, longname, probe, ext, id, flag)
Definition: rawdec.h:52
AV_RB8
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_WB16 unsigned int_TMPL AV_RB8
Definition: bytestream.h:99
AV_RB16
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_RB16
Definition: bytestream.h:98