Libav 0.7.1
|
00001 /* 00002 * VC-1 test bitstreams format muxer. 00003 * Copyright (c) 2008 Konstantin Shishkov 00004 * 00005 * This file is part of Libav. 00006 * 00007 * Libav is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * Libav is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with Libav; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00020 */ 00021 #include "avformat.h" 00022 00023 typedef struct RCVContext { 00024 int frames; 00025 } RCVContext; 00026 00027 static int vc1test_write_header(AVFormatContext *s) 00028 { 00029 AVCodecContext *avc = s->streams[0]->codec; 00030 AVIOContext *pb = s->pb; 00031 00032 if (avc->codec_id != CODEC_ID_WMV3) { 00033 av_log(s, AV_LOG_ERROR, "Only WMV3 is accepted!\n"); 00034 return -1; 00035 } 00036 avio_wl24(pb, 0); //frames count will be here 00037 avio_w8(pb, 0xC5); 00038 avio_wl32(pb, 4); 00039 avio_write(pb, avc->extradata, 4); 00040 avio_wl32(pb, avc->height); 00041 avio_wl32(pb, avc->width); 00042 avio_wl32(pb, 0xC); 00043 avio_wl24(pb, 0); // hrd_buffer 00044 avio_w8(pb, 0x80); // level|cbr|res1 00045 avio_wl32(pb, 0); // hrd_rate 00046 if (s->streams[0]->r_frame_rate.den && s->streams[0]->r_frame_rate.num == 1) 00047 avio_wl32(pb, s->streams[0]->r_frame_rate.den); 00048 else 00049 avio_wl32(pb, 0xFFFFFFFF); //variable framerate 00050 av_set_pts_info(s->streams[0], 32, 1, 1000); 00051 00052 return 0; 00053 } 00054 00055 static int vc1test_write_packet(AVFormatContext *s, AVPacket *pkt) 00056 { 00057 RCVContext *ctx = s->priv_data; 00058 AVIOContext *pb = s->pb; 00059 00060 if (!pkt->size) 00061 return 0; 00062 avio_wl32(pb, pkt->size | ((pkt->flags & AV_PKT_FLAG_KEY) ? 0x80000000 : 0)); 00063 avio_wl32(pb, pkt->pts); 00064 avio_write(pb, pkt->data, pkt->size); 00065 avio_flush(pb); 00066 ctx->frames++; 00067 00068 return 0; 00069 } 00070 00071 static int vc1test_write_trailer(AVFormatContext *s) 00072 { 00073 RCVContext *ctx = s->priv_data; 00074 AVIOContext *pb = s->pb; 00075 00076 if (s->pb->seekable) { 00077 avio_seek(pb, 0, SEEK_SET); 00078 avio_wl24(pb, ctx->frames); 00079 avio_flush(pb); 00080 } 00081 return 0; 00082 } 00083 00084 AVOutputFormat ff_vc1t_muxer = { 00085 "rcv", 00086 NULL_IF_CONFIG_SMALL("VC-1 test bitstream"), 00087 "", 00088 "rcv", 00089 sizeof(RCVContext), 00090 CODEC_ID_NONE, 00091 CODEC_ID_WMV3, 00092 vc1test_write_header, 00093 vc1test_write_packet, 00094 vc1test_write_trailer, 00095 };