Originally committed as revision 6667 to svn://svn.ffmpeg.org/ffmpeg/trunk
Reynaldo H. Verdejo Pinochet authored on 2006/10/12 10:04:32... | ... |
@@ -58,6 +58,7 @@ OBJS-$(CONFIG_MMF_DEMUXER) += mmf.o riff.o |
58 | 58 |
OBJS-$(CONFIG_MMF_MUXER) += mmf.o riff.o |
59 | 59 |
OBJS-$(CONFIG_MOV_DEMUXER) += mov.o riff.o isom.o |
60 | 60 |
OBJS-$(CONFIG_MOV_MUXER) += movenc.o riff.o isom.o |
61 |
+OBJS-$(CONFIG_MTV_DEMUXER) += mtv.o |
|
61 | 62 |
OBJS-$(CONFIG_TGP_MUXER) += movenc.o riff.o isom.o |
62 | 63 |
OBJS-$(CONFIG_MP4_MUXER) += movenc.o riff.o isom.o |
63 | 64 |
OBJS-$(CONFIG_PSP_MUXER) += movenc.o riff.o isom.o |
... | ... |
@@ -200,6 +200,9 @@ void av_register_all(void) |
200 | 200 |
#ifdef CONFIG_MOV_MUXER |
201 | 201 |
av_register_output_format(&mov_muxer); |
202 | 202 |
#endif |
203 |
+#ifdef CONFIG_MTV_DEMUXER |
|
204 |
+ av_register_input_format(&mtv_demuxer); |
|
205 |
+#endif |
|
203 | 206 |
#ifdef CONFIG_TGP_MUXER |
204 | 207 |
av_register_output_format(&tgp_muxer); |
205 | 208 |
#endif |
... | ... |
@@ -91,6 +91,7 @@ extern AVInputFormat mpegps_demuxer; |
91 | 91 |
extern AVInputFormat mpegts_demuxer; |
92 | 92 |
extern AVOutputFormat mpegts_muxer; |
93 | 93 |
extern AVOutputFormat mpjpeg_muxer; |
94 |
+extern AVInputFormat mtv_demuxer; |
|
94 | 95 |
extern AVInputFormat mxf_demuxer; |
95 | 96 |
extern AVInputFormat nsv_demuxer; |
96 | 97 |
extern AVInputFormat nut_demuxer; |
97 | 98 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,186 @@ |
0 |
+/* |
|
1 |
+ * mtv demuxer |
|
2 |
+ * Copyright (c) 2006 Reynaldo H. Verdejo Pinochet |
|
3 |
+ * |
|
4 |
+ * This file is part of FFmpeg. |
|
5 |
+ * |
|
6 |
+ * FFmpeg is free software; you can redistribute it and/or |
|
7 |
+ * modify it under the terms of the GNU Lesser General Public |
|
8 |
+ * License as published by the Free Software Foundation; either |
|
9 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
10 |
+ * |
|
11 |
+ * FFmpeg is distributed in the hope that it will be useful, |
|
12 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 |
+ * Lesser General Public License for more details. |
|
15 |
+ * |
|
16 |
+ * You should have received a copy of the GNU Lesser General Public |
|
17 |
+ * License along with FFmpeg; if not, write to the Free Software |
|
18 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
19 |
+ */ |
|
20 |
+ |
|
21 |
+/** |
|
22 |
+ * @file mtv.c |
|
23 |
+ * MTV demuxer. |
|
24 |
+ */ |
|
25 |
+ |
|
26 |
+#include "avformat.h" |
|
27 |
+#include "bswap.h" |
|
28 |
+ |
|
29 |
+#define MTV_ASUBCHUNK_DATA_SIZE 500 |
|
30 |
+#define MTV_HEADER_SIZE 512 |
|
31 |
+#define MTV_AUDIO_PADDING_SIZE 12 |
|
32 |
+#define AUDIO_SAMPLING_RATE 44100 |
|
33 |
+#define VIDEO_SID 0 |
|
34 |
+#define AUDIO_SID 1 |
|
35 |
+ |
|
36 |
+typedef struct MTVDemuxContext { |
|
37 |
+ |
|
38 |
+ unsigned int file_size; ///< filesize, not always right |
|
39 |
+ unsigned int segments; ///< number of 512 byte segments |
|
40 |
+ unsigned int audio_identifier; ///< 'MP3' on all files I have seen |
|
41 |
+ unsigned int audio_br; ///< bitrate of audio chanel (mp3) |
|
42 |
+ unsigned int img_colorfmt; ///< frame colorfmt rgb 565/555 |
|
43 |
+ unsigned int img_bpp; ///< frame bits per pixel |
|
44 |
+ unsigned int img_width; // |
|
45 |
+ unsigned int img_height; // |
|
46 |
+ unsigned int img_segment_size; ///< size of image segment |
|
47 |
+ unsigned int video_fps; // |
|
48 |
+ unsigned int audio_subsegments; ///< audio subsegments on one segment |
|
49 |
+ |
|
50 |
+ uint8_t audio_packet_count; |
|
51 |
+ |
|
52 |
+} MTVDemuxContext; |
|
53 |
+ |
|
54 |
+static int mtv_probe(AVProbeData *p) |
|
55 |
+{ |
|
56 |
+ if(p->buf_size < 3) |
|
57 |
+ return 0; |
|
58 |
+ |
|
59 |
+ /* Magic is 'AMV' */ |
|
60 |
+ |
|
61 |
+ if(*(p->buf) != 'A' || *(p->buf+1) != 'M' || *(p->buf+2) != 'V') |
|
62 |
+ return 0; |
|
63 |
+ |
|
64 |
+ return AVPROBE_SCORE_MAX; |
|
65 |
+} |
|
66 |
+ |
|
67 |
+static int mtv_read_header(AVFormatContext *s, AVFormatParameters *ap) |
|
68 |
+{ |
|
69 |
+ MTVDemuxContext *mtv = s->priv_data; |
|
70 |
+ ByteIOContext *pb = &s->pb; |
|
71 |
+ AVStream *st; |
|
72 |
+ |
|
73 |
+ |
|
74 |
+ url_fskip(pb, 3); |
|
75 |
+ mtv->file_size = get_le32(pb); |
|
76 |
+ mtv->segments = get_le32(pb); |
|
77 |
+ url_fskip(pb, 32); |
|
78 |
+ mtv->audio_identifier = get_le24(pb); |
|
79 |
+ mtv->audio_br = get_le16(pb); |
|
80 |
+ mtv->img_colorfmt = get_le24(pb); |
|
81 |
+ mtv->img_bpp = get_byte(pb); |
|
82 |
+ mtv->img_width = get_le16(pb); |
|
83 |
+ mtv->img_height = get_le16(pb); |
|
84 |
+ mtv->img_segment_size = get_le16(pb); |
|
85 |
+ url_fskip(pb, 4); |
|
86 |
+ mtv->audio_subsegments = get_le16(pb); |
|
87 |
+ mtv->video_fps = (mtv->audio_br / 4) / mtv->audio_subsegments; |
|
88 |
+ |
|
89 |
+ /* FIXME Add sanity check here */ |
|
90 |
+ |
|
91 |
+ /* first packet is allways audio*/ |
|
92 |
+ |
|
93 |
+ mtv->audio_packet_count = 1; |
|
94 |
+ |
|
95 |
+ /* all systems go! init decoders */ |
|
96 |
+ |
|
97 |
+ /* video - raw rgb565 */ |
|
98 |
+ |
|
99 |
+ st = av_new_stream(s, VIDEO_SID); |
|
100 |
+ if(!st) |
|
101 |
+ return AVERROR_NOMEM; |
|
102 |
+ |
|
103 |
+ av_set_pts_info(st, 64, 1, mtv->video_fps); |
|
104 |
+ st->codec->codec_type = CODEC_TYPE_VIDEO; |
|
105 |
+ st->codec->codec_id = CODEC_ID_RAWVIDEO; |
|
106 |
+ st->codec->width = mtv->img_width; |
|
107 |
+ st->codec->height = mtv->img_height; |
|
108 |
+ st->codec->bits_per_sample = mtv->img_bpp; |
|
109 |
+ st->codec->sample_rate = mtv->video_fps; |
|
110 |
+ |
|
111 |
+ /* audio - mp3 */ |
|
112 |
+ |
|
113 |
+ st = av_new_stream(s, AUDIO_SID); |
|
114 |
+ if(!st) |
|
115 |
+ return AVERROR_NOMEM; |
|
116 |
+ |
|
117 |
+ av_set_pts_info(st, 64, 1, AUDIO_SAMPLING_RATE); |
|
118 |
+ st->codec->codec_type = CODEC_TYPE_AUDIO; |
|
119 |
+ st->codec->codec_id = CODEC_ID_MP3; |
|
120 |
+ st->codec->bit_rate = mtv->audio_br; |
|
121 |
+ st->need_parsing=1; |
|
122 |
+ |
|
123 |
+ /* Jump over header */ |
|
124 |
+ |
|
125 |
+ if(url_fseek(pb, MTV_HEADER_SIZE, SEEK_SET) != MTV_HEADER_SIZE) |
|
126 |
+ return AVERROR_IO; |
|
127 |
+ |
|
128 |
+ return(0); |
|
129 |
+ |
|
130 |
+} |
|
131 |
+ |
|
132 |
+static int mtv_read_packet(AVFormatContext *s, AVPacket *pkt) |
|
133 |
+{ |
|
134 |
+ MTVDemuxContext *mtv = s->priv_data; |
|
135 |
+ ByteIOContext *pb = &s->pb; |
|
136 |
+ int ret; |
|
137 |
+#ifndef WORDS_BIGENDIAN |
|
138 |
+ int i; |
|
139 |
+#endif |
|
140 |
+ |
|
141 |
+ ret = 0; |
|
142 |
+ |
|
143 |
+ if(mtv->audio_subsegments >= mtv->audio_packet_count) |
|
144 |
+ { |
|
145 |
+ url_fskip(pb, MTV_AUDIO_PADDING_SIZE); |
|
146 |
+ |
|
147 |
+ ret = av_get_packet(pb, pkt, MTV_ASUBCHUNK_DATA_SIZE); |
|
148 |
+ if(ret != MTV_ASUBCHUNK_DATA_SIZE) |
|
149 |
+ return AVERROR_IO; |
|
150 |
+ |
|
151 |
+ mtv->audio_packet_count++; |
|
152 |
+ pkt->stream_index = AUDIO_SID; |
|
153 |
+ |
|
154 |
+ }else |
|
155 |
+ { |
|
156 |
+ ret = av_get_packet(pb, pkt, mtv->img_segment_size); |
|
157 |
+ if(ret != mtv->img_segment_size) |
|
158 |
+ return AVERROR_IO; |
|
159 |
+ |
|
160 |
+#ifndef WORDS_BIGENDIAN |
|
161 |
+ |
|
162 |
+ /* pkt->data is GGGRRRR BBBBBGGG |
|
163 |
+ * and we need RRRRRGGG GGGBBBBB |
|
164 |
+ * for PIX_FMT_RGB565 so here we |
|
165 |
+ * just swap bytes as they come |
|
166 |
+ */ |
|
167 |
+ |
|
168 |
+ for(i=0;i<mtv->img_segment_size/2;i++) |
|
169 |
+ *((uint16_t *)pkt->data+i) = bswap_16(*((uint16_t *)pkt->data+i)); |
|
170 |
+#endif |
|
171 |
+ mtv->audio_packet_count = 1; |
|
172 |
+ pkt->stream_index = VIDEO_SID; |
|
173 |
+ } |
|
174 |
+ |
|
175 |
+ return(ret); |
|
176 |
+} |
|
177 |
+ |
|
178 |
+AVInputFormat mtv_demuxer = { |
|
179 |
+ "MTV", |
|
180 |
+ "MTV format", |
|
181 |
+ sizeof(MTVDemuxContext), |
|
182 |
+ mtv_probe, |
|
183 |
+ mtv_read_header, |
|
184 |
+ mtv_read_packet, |
|
185 |
+}; |