00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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 != AV_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);
00039 avio_wl16(pb, 32);
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);
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 = AV_CODEC_ID_NONE,
00066 .video_codec = AV_CODEC_ID_VP8,
00067 .write_header = ivf_write_header,
00068 .write_packet = ivf_write_packet,
00069 };