Originally committed as revision 21212 to svn://svn.ffmpeg.org/ffmpeg/trunk
Peter Ross authored on 2010/01/14 21:55:44... | ... |
@@ -65,6 +65,8 @@ OBJS-$(CONFIG_EAC3_DEMUXER) += raw.o id3v2.o |
65 | 65 |
OBJS-$(CONFIG_EAC3_MUXER) += raw.o |
66 | 66 |
OBJS-$(CONFIG_FFM_DEMUXER) += ffmdec.o |
67 | 67 |
OBJS-$(CONFIG_FFM_MUXER) += ffmenc.o |
68 |
+OBJS-$(CONFIG_FILMSTRIP_DEMUXER) += filmstripdec.o |
|
69 |
+OBJS-$(CONFIG_FILMSTRIP_MUXER) += filmstripenc.o |
|
68 | 70 |
OBJS-$(CONFIG_FLAC_DEMUXER) += flacdec.o raw.o id3v1.o \ |
69 | 71 |
id3v2.o oggparsevorbis.o |
70 | 72 |
OBJS-$(CONFIG_FLAC_MUXER) += flacenc.o |
... | ... |
@@ -82,6 +82,7 @@ void av_register_all(void) |
82 | 82 |
REGISTER_DEMUXER (EA_CDATA, ea_cdata); |
83 | 83 |
REGISTER_MUXDEMUX (EAC3, eac3); |
84 | 84 |
REGISTER_MUXDEMUX (FFM, ffm); |
85 |
+ REGISTER_MUXDEMUX (FILMSTRIP, filmstrip); |
|
85 | 86 |
REGISTER_MUXDEMUX (FLAC, flac); |
86 | 87 |
REGISTER_DEMUXER (FLIC, flic); |
87 | 88 |
REGISTER_MUXDEMUX (FLV, flv); |
88 | 89 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,111 @@ |
0 |
+/* |
|
1 |
+ * Adobe Filmstrip demuxer |
|
2 |
+ * Copyright (c) 2010 Peter Ross |
|
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 libavformat/filmstripdec.c |
|
23 |
+ * Adobe Filmstrip demuxer |
|
24 |
+ */ |
|
25 |
+ |
|
26 |
+#include "libavutil/intreadwrite.h" |
|
27 |
+#include "avformat.h" |
|
28 |
+ |
|
29 |
+#define RAND_TAG MKBETAG('R','a','n','d') |
|
30 |
+ |
|
31 |
+typedef struct { |
|
32 |
+ int leading; |
|
33 |
+} FilmstripDemuxContext; |
|
34 |
+ |
|
35 |
+static int read_header(AVFormatContext *s, |
|
36 |
+ AVFormatParameters *ap) |
|
37 |
+{ |
|
38 |
+ FilmstripDemuxContext *film = s->priv_data; |
|
39 |
+ ByteIOContext *pb = s->pb; |
|
40 |
+ AVStream *st; |
|
41 |
+ |
|
42 |
+ if (url_is_streamed(s->pb)) |
|
43 |
+ return AVERROR(EIO); |
|
44 |
+ |
|
45 |
+ url_fseek(pb, url_fsize(pb) - 36, SEEK_SET); |
|
46 |
+ if (get_be32(pb) != RAND_TAG) { |
|
47 |
+ av_log(s, AV_LOG_ERROR, "magic number not found"); |
|
48 |
+ return AVERROR_INVALIDDATA; |
|
49 |
+ } |
|
50 |
+ |
|
51 |
+ st = av_new_stream(s, 0); |
|
52 |
+ if (!st) |
|
53 |
+ return AVERROR(ENOMEM); |
|
54 |
+ |
|
55 |
+ st->nb_frames = get_be32(pb); |
|
56 |
+ if (get_be16(pb) != 0) { |
|
57 |
+ av_log_ask_for_sample(s, "unsupported packing method\n"); |
|
58 |
+ return AVERROR_INVALIDDATA; |
|
59 |
+ } |
|
60 |
+ |
|
61 |
+ url_fskip(pb, 2); |
|
62 |
+ st->codec->codec_type = CODEC_TYPE_VIDEO; |
|
63 |
+ st->codec->codec_id = CODEC_ID_RAWVIDEO; |
|
64 |
+ st->codec->pix_fmt = PIX_FMT_RGBA; |
|
65 |
+ st->codec->codec_tag = 0; /* no fourcc */ |
|
66 |
+ st->codec->width = get_be16(pb); |
|
67 |
+ st->codec->height = get_be16(pb); |
|
68 |
+ film->leading = get_be16(pb); |
|
69 |
+ av_set_pts_info(st, 64, 1, get_be16(pb)); |
|
70 |
+ |
|
71 |
+ url_fseek(pb, 0, SEEK_SET); |
|
72 |
+ |
|
73 |
+ return 0; |
|
74 |
+} |
|
75 |
+ |
|
76 |
+static int read_packet(AVFormatContext *s, |
|
77 |
+ AVPacket *pkt) |
|
78 |
+{ |
|
79 |
+ FilmstripDemuxContext *film = s->priv_data; |
|
80 |
+ AVStream *st = s->streams[0]; |
|
81 |
+ |
|
82 |
+ if (url_feof(s->pb)) |
|
83 |
+ return AVERROR(EIO); |
|
84 |
+ pkt->dts = url_ftell(s->pb) / (st->codec->width * (st->codec->height + film->leading) * 4); |
|
85 |
+ pkt->size = av_get_packet(s->pb, pkt, st->codec->width * st->codec->height * 4); |
|
86 |
+ url_fskip(s->pb, st->codec->width * film->leading * 4); |
|
87 |
+ if (pkt->size < 0) |
|
88 |
+ return pkt->size; |
|
89 |
+ pkt->flags |= PKT_FLAG_KEY; |
|
90 |
+ return 0; |
|
91 |
+} |
|
92 |
+ |
|
93 |
+static int read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) |
|
94 |
+{ |
|
95 |
+ AVStream *st = s->streams[stream_index]; |
|
96 |
+ url_fseek(s->pb, FFMAX(timestamp, 0) * st->codec->width * st->codec->height * 4, SEEK_SET); |
|
97 |
+ return 0; |
|
98 |
+} |
|
99 |
+ |
|
100 |
+AVInputFormat filmstrip_demuxer = { |
|
101 |
+ "filmstrip", |
|
102 |
+ NULL_IF_CONFIG_SMALL("Adobe Filmstrip"), |
|
103 |
+ sizeof(FilmstripDemuxContext), |
|
104 |
+ NULL, |
|
105 |
+ read_header, |
|
106 |
+ read_packet, |
|
107 |
+ NULL, |
|
108 |
+ read_seek, |
|
109 |
+ .extensions = "flm", |
|
110 |
+}; |
0 | 111 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,85 @@ |
0 |
+/* |
|
1 |
+ * Adobe Filmstrip muxer |
|
2 |
+ * Copyright (c) 2010 Peter Ross |
|
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 libavformat/filmstripenc.c |
|
23 |
+ * Adobe Filmstrip muxer |
|
24 |
+ */ |
|
25 |
+ |
|
26 |
+#include "libavutil/intreadwrite.h" |
|
27 |
+#include "avformat.h" |
|
28 |
+ |
|
29 |
+#define RAND_TAG MKBETAG('R','a','n','d') |
|
30 |
+ |
|
31 |
+typedef struct { |
|
32 |
+ int nb_frames; |
|
33 |
+} FilmstripMuxContext; |
|
34 |
+ |
|
35 |
+static int write_header(AVFormatContext *s) |
|
36 |
+{ |
|
37 |
+ if (s->streams[0]->codec->pix_fmt != PIX_FMT_RGBA) { |
|
38 |
+ av_log(s, AV_LOG_ERROR, "only PIX_FMT_RGBA is supported\n"); |
|
39 |
+ return AVERROR_INVALIDDATA; |
|
40 |
+ } |
|
41 |
+ return 0; |
|
42 |
+} |
|
43 |
+ |
|
44 |
+static int write_packet(AVFormatContext *s, AVPacket *pkt) |
|
45 |
+{ |
|
46 |
+ FilmstripMuxContext *film = s->priv_data; |
|
47 |
+ put_buffer(s->pb, pkt->data, pkt->size); |
|
48 |
+ film->nb_frames++; |
|
49 |
+ return 0; |
|
50 |
+} |
|
51 |
+ |
|
52 |
+static int write_trailer(AVFormatContext *s) |
|
53 |
+{ |
|
54 |
+ FilmstripMuxContext *film = s->priv_data; |
|
55 |
+ ByteIOContext *pb = s->pb; |
|
56 |
+ AVStream *st = s->streams[0]; |
|
57 |
+ int i; |
|
58 |
+ |
|
59 |
+ put_be32(pb, RAND_TAG); |
|
60 |
+ put_be32(pb, film->nb_frames); |
|
61 |
+ put_be16(pb, 0); // packing method |
|
62 |
+ put_be16(pb, 0); // reserved |
|
63 |
+ put_be16(pb, st->codec->width); |
|
64 |
+ put_be16(pb, st->codec->height); |
|
65 |
+ put_be16(pb, 0); // leading |
|
66 |
+ put_be16(pb, 1/av_q2d(st->codec->time_base)); |
|
67 |
+ for (i = 0; i < 16; i++) |
|
68 |
+ put_byte(pb, 0x00); // reserved |
|
69 |
+ put_flush_packet(pb); |
|
70 |
+ return 0; |
|
71 |
+} |
|
72 |
+ |
|
73 |
+AVOutputFormat filmstrip_muxer = { |
|
74 |
+ "filmstrip", |
|
75 |
+ NULL_IF_CONFIG_SMALL("Adobe Filmstrip"), |
|
76 |
+ NULL, |
|
77 |
+ "flm", |
|
78 |
+ sizeof(FilmstripMuxContext), |
|
79 |
+ CODEC_ID_NONE, |
|
80 |
+ CODEC_ID_RAWVIDEO, |
|
81 |
+ write_header, |
|
82 |
+ write_packet, |
|
83 |
+ write_trailer, |
|
84 |
+}; |