FFmpeg
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
rawdec.c
Go to the documentation of this file.
1 /*
2  * RAW demuxers
3  * Copyright (c) 2001 Fabrice Bellard
4  * Copyright (c) 2005 Alex Beregszaszi
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #include "avformat.h"
24 #include "internal.h"
25 #include "avio_internal.h"
26 #include "rawdec.h"
27 #include "libavutil/opt.h"
28 #include "libavutil/parseutils.h"
29 #include "libavutil/pixdesc.h"
30 #include "libavutil/avassert.h"
31 
32 #define RAW_PACKET_SIZE 1024
33 
35 {
36  int ret, size;
37 
38  size = RAW_PACKET_SIZE;
39 
40  if (av_new_packet(pkt, size) < 0)
41  return AVERROR(ENOMEM);
42 
43  pkt->pos= avio_tell(s->pb);
44  pkt->stream_index = 0;
45  ret = ffio_read_partial(s->pb, pkt->data, size);
46  if (ret < 0) {
47  av_free_packet(pkt);
48  return ret;
49  }
50  av_shrink_packet(pkt, ret);
51  return ret;
52 }
53 
55 {
57  if (!st)
58  return AVERROR(ENOMEM);
62  st->start_time = 0;
63  /* the parameters will be extracted from the compressed bitstream */
64 
65  return 0;
66 }
67 
68 /* MPEG-1/H.263 input */
70 {
71  AVStream *st;
73  AVRational framerate;
74  int ret = 0;
75 
76 
77  st = avformat_new_stream(s, NULL);
78  if (!st) {
79  ret = AVERROR(ENOMEM);
80  goto fail;
81  }
82 
86 
87  if ((ret = av_parse_video_rate(&framerate, s1->framerate)) < 0) {
88  av_log(s, AV_LOG_ERROR, "Could not parse framerate: %s.\n", s1->framerate);
89  goto fail;
90  }
91 
92  st->codec->time_base = av_inv_q(framerate);
93  avpriv_set_pts_info(st, 64, 1, 1200000);
94 
95 fail:
96  return ret;
97 }
98 
99 /* Note: Do not forget to add new entries to the Makefile as well. */
100 
101 #define OFFSET(x) offsetof(FFRawVideoDemuxerContext, x)
102 #define DEC AV_OPT_FLAG_DECODING_PARAM
104  { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0, DEC},
105  { NULL },
106 };
107 
108 #if CONFIG_LATM_DEMUXER
109 AVInputFormat ff_latm_demuxer = {
110  .name = "latm",
111  .long_name = NULL_IF_CONFIG_SMALL("raw LOAS/LATM"),
112  .read_header = ff_raw_audio_read_header,
113  .read_packet = ff_raw_read_partial_packet,
114  .flags = AVFMT_GENERIC_INDEX,
115  .extensions = "latm",
116  .raw_codec_id = AV_CODEC_ID_AAC_LATM,
117 };
118 #endif
119 
120 #if CONFIG_MJPEG_DEMUXER
121 FF_DEF_RAWVIDEO_DEMUXER(mjpeg, "raw MJPEG video", NULL, "mjpg,mjpeg,mpo", AV_CODEC_ID_MJPEG)
122 #endif
123 
124 #if CONFIG_MLP_DEMUXER
125 AVInputFormat ff_mlp_demuxer = {
126  .name = "mlp",
127  .long_name = NULL_IF_CONFIG_SMALL("raw MLP"),
128  .read_header = ff_raw_audio_read_header,
129  .read_packet = ff_raw_read_partial_packet,
130  .flags = AVFMT_GENERIC_INDEX,
131  .extensions = "mlp",
132  .raw_codec_id = AV_CODEC_ID_MLP,
133 };
134 #endif
135 
136 #if CONFIG_TRUEHD_DEMUXER
137 AVInputFormat ff_truehd_demuxer = {
138  .name = "truehd",
139  .long_name = NULL_IF_CONFIG_SMALL("raw TrueHD"),
140  .read_header = ff_raw_audio_read_header,
141  .read_packet = ff_raw_read_partial_packet,
142  .flags = AVFMT_GENERIC_INDEX,
143  .extensions = "thd",
144  .raw_codec_id = AV_CODEC_ID_TRUEHD,
145 };
146 #endif
147 
148 #if CONFIG_SHORTEN_DEMUXER
149 AVInputFormat ff_shorten_demuxer = {
150  .name = "shn",
151  .long_name = NULL_IF_CONFIG_SMALL("raw Shorten"),
152  .read_header = ff_raw_audio_read_header,
153  .read_packet = ff_raw_read_partial_packet,
155  .extensions = "shn",
156  .raw_codec_id = AV_CODEC_ID_SHORTEN,
157 };
158 #endif
159 
160 #if CONFIG_VC1_DEMUXER
161 FF_DEF_RAWVIDEO_DEMUXER(vc1, "raw VC-1", NULL, "vc1", AV_CODEC_ID_VC1)
162 #endif