FFmpeg
vc1testenc.c
Go to the documentation of this file.
1 /*
2  * VC-1 test bitstreams format muxer.
3  * Copyright (c) 2008 Konstantin Shishkov
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 #include "avformat.h"
22 #include "internal.h"
23 #include "mux.h"
24 
25 typedef struct RCVContext {
26  int frames;
27 } RCVContext;
28 
30 {
31  AVCodecParameters *par = s->streams[0]->codecpar;
32  AVIOContext *pb = s->pb;
33 
34  if (par->codec_id != AV_CODEC_ID_WMV3) {
35  av_log(s, AV_LOG_ERROR, "Only WMV3 is accepted!\n");
36  return -1;
37  }
38  avio_wl24(pb, 0); //frames count will be here
39  avio_w8(pb, 0xC5);
40  avio_wl32(pb, 4);
41  avio_write(pb, par->extradata, 4);
42  avio_wl32(pb, par->height);
43  avio_wl32(pb, par->width);
44  avio_wl32(pb, 0xC);
45  avio_wl24(pb, 0); // hrd_buffer
46  avio_w8(pb, 0x80); // level|cbr|res1
47  avio_wl32(pb, 0); // hrd_rate
48  if (s->streams[0]->avg_frame_rate.den && s->streams[0]->avg_frame_rate.num == 1)
49  avio_wl32(pb, s->streams[0]->avg_frame_rate.den);
50  else
51  avio_wl32(pb, 0xFFFFFFFF); //variable framerate
52  avpriv_set_pts_info(s->streams[0], 32, 1, 1000);
53 
54  return 0;
55 }
56 
58 {
59  RCVContext *ctx = s->priv_data;
60  AVIOContext *pb = s->pb;
61 
62  if (!pkt->size)
63  return 0;
64  avio_wl32(pb, pkt->size | ((pkt->flags & AV_PKT_FLAG_KEY) ? 0x80000000 : 0));
65  avio_wl32(pb, pkt->pts);
66  avio_write(pb, pkt->data, pkt->size);
67  ctx->frames++;
68 
69  return 0;
70 }
71 
73 {
74  RCVContext *ctx = s->priv_data;
75  AVIOContext *pb = s->pb;
76 
77  if (s->pb->seekable & AVIO_SEEKABLE_NORMAL) {
78  avio_seek(pb, 0, SEEK_SET);
79  avio_wl24(pb, ctx->frames);
80  }
81  return 0;
82 }
83 
85  .p.name = "vc1test",
86  .p.long_name = NULL_IF_CONFIG_SMALL("VC-1 test bitstream"),
87  .p.extensions = "rcv",
88  .priv_data_size = sizeof(RCVContext),
89  .p.audio_codec = AV_CODEC_ID_NONE,
90  .p.video_codec = AV_CODEC_ID_WMV3,
91  .write_header = vc1test_write_header,
92  .write_packet = vc1test_write_packet,
93  .write_trailer = vc1test_write_trailer,
94 };
AVCodecParameters::extradata
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: codec_par.h:76
AVOutputFormat::name
const char * name
Definition: avformat.h:508
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: codec_par.h:54
AVPacket::data
uint8_t * data
Definition: packet.h:374
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:429
FFOutputFormat::p
AVOutputFormat p
The public AVOutputFormat.
Definition: mux.h:34
avpriv_set_pts_info
void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition: avformat.c:771
ff_vc1t_muxer
const FFOutputFormat ff_vc1t_muxer
Definition: vc1testenc.c:84
RCVContext
Definition: vc1testenc.c:25
pkt
AVPacket * pkt
Definition: movenc.c:59
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
s
#define s(width, name)
Definition: cbs_vp9.c:256
AVCodecParameters::width
int width
Video only.
Definition: codec_par.h:128
ctx
AVFormatContext * ctx
Definition: movenc.c:48
AVFormatContext
Format I/O context.
Definition: avformat.h:1104
AV_CODEC_ID_WMV3
@ AV_CODEC_ID_WMV3
Definition: codec_id.h:123
internal.h
FFOutputFormat
Definition: mux.h:30
avio_w8
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:200
AVIOContext
Bytestream IO Context.
Definition: avio.h:166
vc1test_write_packet
static int vc1test_write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: vc1testenc.c:57
AVPacket::size
int size
Definition: packet.h:375
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:115
avio_write
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:222
avio_wl32
void avio_wl32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:378
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:380
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: codec_id.h:50
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:367
RCVContext::frames
int frames
Definition: vc1testenc.c:26
AVCodecParameters::height
int height
Definition: codec_par.h:129
avio_seek
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:252
avformat.h
AVIO_SEEKABLE_NORMAL
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
Definition: avio.h:41
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:62
AVPacket
This structure stores compressed data.
Definition: packet.h:351
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
avio_wl24
void avio_wl24(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:470
vc1test_write_trailer
static int vc1test_write_trailer(AVFormatContext *s)
Definition: vc1testenc.c:72
mux.h
vc1test_write_header
static int vc1test_write_header(AVFormatContext *s)
Definition: vc1testenc.c:29