Libav
|
00001 /* 00002 * VC-1 test bitstreams format muxer. 00003 * Copyright (c) 2008 Konstantin Shishkov 00004 * 00005 * This file is part of FFmpeg. 00006 * 00007 * FFmpeg 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 * FFmpeg 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 FFmpeg; 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 ByteIOContext *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 put_le24(pb, 0); //frames count will be here 00037 put_byte(pb, 0xC5); 00038 put_le32(pb, 4); 00039 put_buffer(pb, avc->extradata, 4); 00040 put_le32(pb, avc->height); 00041 put_le32(pb, avc->width); 00042 put_le32(pb, 0xC); 00043 put_le24(pb, 0); // hrd_buffer 00044 put_byte(pb, 0x80); // level|cbr|res1 00045 put_le32(pb, 0); // hrd_rate 00046 if (s->streams[0]->r_frame_rate.den && s->streams[0]->r_frame_rate.num == 1) 00047 put_le32(pb, s->streams[0]->r_frame_rate.den); 00048 else 00049 put_le32(pb, 0xFFFFFFFF); //variable framerate 00050 00051 return 0; 00052 } 00053 00054 static int vc1test_write_packet(AVFormatContext *s, AVPacket *pkt) 00055 { 00056 RCVContext *ctx = s->priv_data; 00057 ByteIOContext *pb = s->pb; 00058 00059 if (!pkt->size) 00060 return 0; 00061 put_le32(pb, pkt->size | ((pkt->flags & AV_PKT_FLAG_KEY) ? 0x80000000 : 0)); 00062 put_le32(pb, pkt->pts); 00063 put_buffer(pb, pkt->data, pkt->size); 00064 put_flush_packet(pb); 00065 ctx->frames++; 00066 00067 return 0; 00068 } 00069 00070 static int vc1test_write_trailer(AVFormatContext *s) 00071 { 00072 RCVContext *ctx = s->priv_data; 00073 ByteIOContext *pb = s->pb; 00074 00075 if (!url_is_streamed(s->pb)) { 00076 url_fseek(pb, 0, SEEK_SET); 00077 put_le24(pb, ctx->frames); 00078 put_flush_packet(pb); 00079 } 00080 return 0; 00081 } 00082 00083 AVOutputFormat vc1t_muxer = { 00084 "rcv", 00085 NULL_IF_CONFIG_SMALL("VC-1 test bitstream"), 00086 "", 00087 "rcv", 00088 sizeof(RCVContext), 00089 CODEC_ID_NONE, 00090 CODEC_ID_WMV3, 00091 vc1test_write_header, 00092 vc1test_write_packet, 00093 vc1test_write_trailer, 00094 };