Libav 0.7.1
libavformat/ivfenc.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2010 Reimar Döffinger
00003  *
00004  * This file is part of Libav.
00005  *
00006  * Libav is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * Libav is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with Libav; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019  */
00020 #include "avformat.h"
00021 #include "libavutil/intreadwrite.h"
00022 
00023 static int ivf_write_header(AVFormatContext *s)
00024 {
00025     AVCodecContext *ctx;
00026     AVIOContext *pb = s->pb;
00027 
00028     if (s->nb_streams != 1) {
00029         av_log(s, AV_LOG_ERROR, "Format supports only exactly one video stream\n");
00030         return AVERROR(EINVAL);
00031     }
00032     ctx = s->streams[0]->codec;
00033     if (ctx->codec_type != AVMEDIA_TYPE_VIDEO || ctx->codec_id != CODEC_ID_VP8) {
00034         av_log(s, AV_LOG_ERROR, "Currently only VP8 is supported!\n");
00035         return AVERROR(EINVAL);
00036     }
00037     avio_write(pb, "DKIF", 4);
00038     avio_wl16(pb, 0); // version
00039     avio_wl16(pb, 32); // header length
00040     avio_wl32(pb, ctx->codec_tag ? ctx->codec_tag : AV_RL32("VP80"));
00041     avio_wl16(pb, ctx->width);
00042     avio_wl16(pb, ctx->height);
00043     avio_wl32(pb, s->streams[0]->time_base.den);
00044     avio_wl32(pb, s->streams[0]->time_base.num);
00045     avio_wl64(pb, s->streams[0]->duration); // TODO: duration or number of frames?!?
00046 
00047     return 0;
00048 }
00049 
00050 static int ivf_write_packet(AVFormatContext *s, AVPacket *pkt)
00051 {
00052     AVIOContext *pb = s->pb;
00053     avio_wl32(pb, pkt->size);
00054     avio_wl64(pb, pkt->pts);
00055     avio_write(pb, pkt->data, pkt->size);
00056     avio_flush(pb);
00057 
00058     return 0;
00059 }
00060 
00061 AVOutputFormat ff_ivf_muxer = {
00062     .name = "ivf",
00063     .long_name = NULL_IF_CONFIG_SMALL("On2 IVF"),
00064     .extensions = "ivf",
00065     .audio_codec = CODEC_ID_NONE,
00066     .video_codec = CODEC_ID_VP8,
00067     .write_header = ivf_write_header,
00068     .write_packet = ivf_write_packet,
00069 };