1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,69 @@ |
0 |
+/* |
|
1 |
+ * Copyright (c) 2010 Reimar Döffinger |
|
2 |
+ * |
|
3 |
+ * This file is part of FFmpeg. |
|
4 |
+ * |
|
5 |
+ * FFmpeg is free software; you can redistribute it and/or |
|
6 |
+ * modify it under the terms of the GNU Lesser General Public |
|
7 |
+ * License as published by the Free Software Foundation; either |
|
8 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
9 |
+ * |
|
10 |
+ * FFmpeg is distributed in the hope that it will be useful, |
|
11 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 |
+ * Lesser General Public License for more details. |
|
14 |
+ * |
|
15 |
+ * You should have received a copy of the GNU Lesser General Public |
|
16 |
+ * License along with FFmpeg; if not, write to the Free Software |
|
17 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
18 |
+ */ |
|
19 |
+#include "avformat.h" |
|
20 |
+#include "libavutil/intreadwrite.h" |
|
21 |
+ |
|
22 |
+static int ivf_write_header(AVFormatContext *s) |
|
23 |
+{ |
|
24 |
+ AVCodecContext *ctx; |
|
25 |
+ ByteIOContext *pb = s->pb; |
|
26 |
+ |
|
27 |
+ if (s->nb_streams != 1) { |
|
28 |
+ av_log(s, AV_LOG_ERROR, "Format supports only exactly one video stream\n"); |
|
29 |
+ return AVERROR(EINVAL); |
|
30 |
+ } |
|
31 |
+ ctx = s->streams[0]->codec; |
|
32 |
+ if (ctx->codec_type != CODEC_TYPE_VIDEO || ctx->codec_id != CODEC_ID_VP8) { |
|
33 |
+ av_log(s, AV_LOG_ERROR, "Currently only VP8 is supported!\n"); |
|
34 |
+ return AVERROR(EINVAL); |
|
35 |
+ } |
|
36 |
+ put_buffer(pb, "DKIF", 4); |
|
37 |
+ put_le16(pb, 0); // version |
|
38 |
+ put_le16(pb, 32); // header length |
|
39 |
+ put_le32(pb, ctx->codec_tag ? ctx->codec_tag : AV_RL32("VP80")); |
|
40 |
+ put_le16(pb, ctx->width); |
|
41 |
+ put_le16(pb, ctx->height); |
|
42 |
+ put_le32(pb, s->streams[0]->time_base.den); |
|
43 |
+ put_le32(pb, s->streams[0]->time_base.num); |
|
44 |
+ put_le64(pb, s->streams[0]->duration); // TODO: duration or number of frames?!? |
|
45 |
+ |
|
46 |
+ return 0; |
|
47 |
+} |
|
48 |
+ |
|
49 |
+static int ivf_write_packet(AVFormatContext *s, AVPacket *pkt) |
|
50 |
+{ |
|
51 |
+ ByteIOContext *pb = s->pb; |
|
52 |
+ put_le32(pb, pkt->size); |
|
53 |
+ put_le64(pb, pkt->pts); |
|
54 |
+ put_buffer(pb, pkt->data, pkt->size); |
|
55 |
+ put_flush_packet(pb); |
|
56 |
+ |
|
57 |
+ return 0; |
|
58 |
+} |
|
59 |
+ |
|
60 |
+AVOutputFormat ivf_muxer = { |
|
61 |
+ .name = "ivf", |
|
62 |
+ .long_name = NULL_IF_CONFIG_SMALL("On2 IVF"), |
|
63 |
+ .extensions = "ivf", |
|
64 |
+ .audio_codec = CODEC_ID_NONE, |
|
65 |
+ .video_codec = CODEC_ID_VP8, |
|
66 |
+ .write_header = ivf_write_header, |
|
67 |
+ .write_packet = ivf_write_packet, |
|
68 |
+}; |