annotate ffmpeg/libavformat/vc1testenc.c @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents f445c3017523
children
rev   line source
yading@11 1 /*
yading@11 2 * VC-1 test bitstreams format muxer.
yading@11 3 * Copyright (c) 2008 Konstantin Shishkov
yading@11 4 *
yading@11 5 * This file is part of FFmpeg.
yading@11 6 *
yading@11 7 * FFmpeg is free software; you can redistribute it and/or
yading@11 8 * modify it under the terms of the GNU Lesser General Public
yading@11 9 * License as published by the Free Software Foundation; either
yading@11 10 * version 2.1 of the License, or (at your option) any later version.
yading@11 11 *
yading@11 12 * FFmpeg is distributed in the hope that it will be useful,
yading@11 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@11 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@11 15 * Lesser General Public License for more details.
yading@11 16 *
yading@11 17 * You should have received a copy of the GNU Lesser General Public
yading@11 18 * License along with FFmpeg; if not, write to the Free Software
yading@11 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@11 20 */
yading@11 21 #include "avformat.h"
yading@11 22 #include "internal.h"
yading@11 23
yading@11 24 typedef struct RCVContext {
yading@11 25 int frames;
yading@11 26 } RCVContext;
yading@11 27
yading@11 28 static int vc1test_write_header(AVFormatContext *s)
yading@11 29 {
yading@11 30 AVCodecContext *avc = s->streams[0]->codec;
yading@11 31 AVIOContext *pb = s->pb;
yading@11 32
yading@11 33 if (avc->codec_id != AV_CODEC_ID_WMV3) {
yading@11 34 av_log(s, AV_LOG_ERROR, "Only WMV3 is accepted!\n");
yading@11 35 return -1;
yading@11 36 }
yading@11 37 avio_wl24(pb, 0); //frames count will be here
yading@11 38 avio_w8(pb, 0xC5);
yading@11 39 avio_wl32(pb, 4);
yading@11 40 avio_write(pb, avc->extradata, 4);
yading@11 41 avio_wl32(pb, avc->height);
yading@11 42 avio_wl32(pb, avc->width);
yading@11 43 avio_wl32(pb, 0xC);
yading@11 44 avio_wl24(pb, 0); // hrd_buffer
yading@11 45 avio_w8(pb, 0x80); // level|cbr|res1
yading@11 46 avio_wl32(pb, 0); // hrd_rate
yading@11 47 if (s->streams[0]->avg_frame_rate.den && s->streams[0]->avg_frame_rate.num == 1)
yading@11 48 avio_wl32(pb, s->streams[0]->avg_frame_rate.den);
yading@11 49 else
yading@11 50 avio_wl32(pb, 0xFFFFFFFF); //variable framerate
yading@11 51 avpriv_set_pts_info(s->streams[0], 32, 1, 1000);
yading@11 52
yading@11 53 return 0;
yading@11 54 }
yading@11 55
yading@11 56 static int vc1test_write_packet(AVFormatContext *s, AVPacket *pkt)
yading@11 57 {
yading@11 58 RCVContext *ctx = s->priv_data;
yading@11 59 AVIOContext *pb = s->pb;
yading@11 60
yading@11 61 if (!pkt->size)
yading@11 62 return 0;
yading@11 63 avio_wl32(pb, pkt->size | ((pkt->flags & AV_PKT_FLAG_KEY) ? 0x80000000 : 0));
yading@11 64 avio_wl32(pb, pkt->pts);
yading@11 65 avio_write(pb, pkt->data, pkt->size);
yading@11 66 ctx->frames++;
yading@11 67
yading@11 68 return 0;
yading@11 69 }
yading@11 70
yading@11 71 static int vc1test_write_trailer(AVFormatContext *s)
yading@11 72 {
yading@11 73 RCVContext *ctx = s->priv_data;
yading@11 74 AVIOContext *pb = s->pb;
yading@11 75
yading@11 76 if (s->pb->seekable) {
yading@11 77 avio_seek(pb, 0, SEEK_SET);
yading@11 78 avio_wl24(pb, ctx->frames);
yading@11 79 avio_flush(pb);
yading@11 80 }
yading@11 81 return 0;
yading@11 82 }
yading@11 83
yading@11 84 AVOutputFormat ff_vc1t_muxer = {
yading@11 85 .name = "vc1test",
yading@11 86 .long_name = NULL_IF_CONFIG_SMALL("VC-1 test bitstream"),
yading@11 87 .extensions = "rcv",
yading@11 88 .priv_data_size = sizeof(RCVContext),
yading@11 89 .audio_codec = AV_CODEC_ID_NONE,
yading@11 90 .video_codec = AV_CODEC_ID_WMV3,
yading@11 91 .write_header = vc1test_write_header,
yading@11 92 .write_packet = vc1test_write_packet,
yading@11 93 .write_trailer = vc1test_write_trailer,
yading@11 94 };