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