ffmpeg / libavformat / ivfenc.c @ 9dd94f83
History | View | Annotate | Download (2.23 KB)
1 | 326851b9 | Reimar Döffinger | /*
|
---|---|---|---|
2 | * Copyright (c) 2010 Reimar Döffinger
|
||
3 | *
|
||
4 | 2912e87a | Mans Rullgard | * This file is part of Libav.
|
5 | 326851b9 | Reimar Döffinger | *
|
6 | 2912e87a | Mans Rullgard | * Libav is free software; you can redistribute it and/or
|
7 | 326851b9 | Reimar Döffinger | * 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 | 2912e87a | Mans Rullgard | * Libav is distributed in the hope that it will be useful,
|
12 | 326851b9 | Reimar Döffinger | * 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 | 2912e87a | Mans Rullgard | * License along with Libav; if not, write to the Free Software
|
18 | 326851b9 | Reimar Döffinger | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
19 | */
|
||
20 | #include "avformat.h" |
||
21 | #include "libavutil/intreadwrite.h" |
||
22 | |||
23 | static int ivf_write_header(AVFormatContext *s) |
||
24 | { |
||
25 | AVCodecContext *ctx; |
||
26 | ae628ec1 | Anton Khirnov | AVIOContext *pb = s->pb; |
27 | 326851b9 | Reimar Döffinger | |
28 | if (s->nb_streams != 1) { |
||
29 | av_log(s, AV_LOG_ERROR, "Format supports only exactly one video stream\n");
|
||
30 | return AVERROR(EINVAL);
|
||
31 | } |
||
32 | ctx = s->streams[0]->codec;
|
||
33 | b2ed95ec | Anton Khirnov | if (ctx->codec_type != AVMEDIA_TYPE_VIDEO || ctx->codec_id != CODEC_ID_VP8) {
|
34 | 326851b9 | Reimar Döffinger | av_log(s, AV_LOG_ERROR, "Currently only VP8 is supported!\n");
|
35 | return AVERROR(EINVAL);
|
||
36 | } |
||
37 | 77eb5504 | Anton Khirnov | avio_write(pb, "DKIF", 4); |
38 | avio_wl16(pb, 0); // version |
||
39 | avio_wl16(pb, 32); // header length |
||
40 | avio_wl32(pb, ctx->codec_tag ? ctx->codec_tag : AV_RL32("VP80"));
|
||
41 | avio_wl16(pb, ctx->width); |
||
42 | avio_wl16(pb, ctx->height); |
||
43 | avio_wl32(pb, s->streams[0]->time_base.den);
|
||
44 | avio_wl32(pb, s->streams[0]->time_base.num);
|
||
45 | avio_wl64(pb, s->streams[0]->duration); // TODO: duration or number of frames?!? |
||
46 | 326851b9 | Reimar Döffinger | |
47 | return 0; |
||
48 | } |
||
49 | |||
50 | static int ivf_write_packet(AVFormatContext *s, AVPacket *pkt) |
||
51 | { |
||
52 | ae628ec1 | Anton Khirnov | AVIOContext *pb = s->pb; |
53 | 77eb5504 | Anton Khirnov | avio_wl32(pb, pkt->size); |
54 | avio_wl64(pb, pkt->pts); |
||
55 | avio_write(pb, pkt->data, pkt->size); |
||
56 | b7f2fdde | Anton Khirnov | avio_flush(pb); |
57 | 326851b9 | Reimar Döffinger | |
58 | return 0; |
||
59 | } |
||
60 | |||
61 | c6610a21 | Diego Elio Pettenò | AVOutputFormat ff_ivf_muxer = { |
62 | 326851b9 | Reimar Döffinger | .name = "ivf",
|
63 | .long_name = NULL_IF_CONFIG_SMALL("On2 IVF"),
|
||
64 | .extensions = "ivf",
|
||
65 | .audio_codec = CODEC_ID_NONE, |
||
66 | .video_codec = CODEC_ID_VP8, |
||
67 | .write_header = ivf_write_header, |
||
68 | .write_packet = ivf_write_packet, |
||
69 | }; |