3 * Copyright (c) 2001 Fabrice Bellard
4 * Copyright (c) 2005 Alex Beregszaszi
6 * This file is part of FFmpeg.
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.
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.
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
25 #include "avio_internal.h"
27 #include "libavutil/opt.h"
28 #include "libavutil/parseutils.h"
29 #include "libavutil/pixdesc.h"
30 #include "libavutil/avassert.h"
32 #define RAW_PACKET_SIZE 1024
34 int ff_raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
38 size = RAW_PACKET_SIZE;
40 if (av_new_packet(pkt, size) < 0)
41 return AVERROR(ENOMEM);
43 pkt->pos= avio_tell(s->pb);
44 pkt->stream_index = 0;
45 ret = ffio_read_partial(s->pb, pkt->data, size);
50 av_shrink_packet(pkt, ret);
54 int ff_raw_audio_read_header(AVFormatContext *s)
56 AVStream *st = avformat_new_stream(s, NULL);
58 return AVERROR(ENOMEM);
59 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
60 st->codec->codec_id = s->iformat->raw_codec_id;
61 st->need_parsing = AVSTREAM_PARSE_FULL_RAW;
63 /* the parameters will be extracted from the compressed bitstream */
68 /* MPEG-1/H.263 input */
69 int ff_raw_video_read_header(AVFormatContext *s)
72 FFRawVideoDemuxerContext *s1 = s->priv_data;
76 st = avformat_new_stream(s, NULL);
78 ret = AVERROR(ENOMEM);
82 st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
83 st->codec->codec_id = s->iformat->raw_codec_id;
84 st->need_parsing = AVSTREAM_PARSE_FULL_RAW;
86 st->codec->time_base = av_inv_q(s1->framerate);
87 avpriv_set_pts_info(st, 64, 1, 1200000);
93 /* Note: Do not forget to add new entries to the Makefile as well. */
95 #define OFFSET(x) offsetof(FFRawVideoDemuxerContext, x)
96 #define DEC AV_OPT_FLAG_DECODING_PARAM
97 const AVOption ff_rawvideo_options[] = {
98 { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, 0, DEC},
102 #if CONFIG_LATM_DEMUXER
103 AVInputFormat ff_latm_demuxer = {
105 .long_name = NULL_IF_CONFIG_SMALL("raw LOAS/LATM"),
106 .read_header = ff_raw_audio_read_header,
107 .read_packet = ff_raw_read_partial_packet,
108 .flags = AVFMT_GENERIC_INDEX,
109 .extensions = "latm",
110 .raw_codec_id = AV_CODEC_ID_AAC_LATM,
114 #if CONFIG_MJPEG_DEMUXER
115 FF_DEF_RAWVIDEO_DEMUXER(mjpeg, "raw MJPEG video", NULL, "mjpg,mjpeg,mpo", AV_CODEC_ID_MJPEG)
118 #if CONFIG_MLP_DEMUXER
119 AVInputFormat ff_mlp_demuxer = {
121 .long_name = NULL_IF_CONFIG_SMALL("raw MLP"),
122 .read_header = ff_raw_audio_read_header,
123 .read_packet = ff_raw_read_partial_packet,
124 .flags = AVFMT_GENERIC_INDEX,
126 .raw_codec_id = AV_CODEC_ID_MLP,
130 #if CONFIG_TRUEHD_DEMUXER
131 AVInputFormat ff_truehd_demuxer = {
133 .long_name = NULL_IF_CONFIG_SMALL("raw TrueHD"),
134 .read_header = ff_raw_audio_read_header,
135 .read_packet = ff_raw_read_partial_packet,
136 .flags = AVFMT_GENERIC_INDEX,
138 .raw_codec_id = AV_CODEC_ID_TRUEHD,
142 #if CONFIG_SHORTEN_DEMUXER
143 AVInputFormat ff_shorten_demuxer = {
145 .long_name = NULL_IF_CONFIG_SMALL("raw Shorten"),
146 .read_header = ff_raw_audio_read_header,
147 .read_packet = ff_raw_read_partial_packet,
148 .flags = AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK,
150 .raw_codec_id = AV_CODEC_ID_SHORTEN,
154 #if CONFIG_VC1_DEMUXER
155 FF_DEF_RAWVIDEO_DEMUXER(vc1, "raw VC-1", NULL, "vc1", AV_CODEC_ID_VC1)