ivfenc.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010 Reimar Döffinger
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 #include "avformat.h"
21 #include "libavutil/intreadwrite.h"
22 
24 {
25  AVCodecContext *ctx;
26  AVIOContext *pb = s->pb;
27 
28  if (s->nb_streams != 1) {
29  av_log(s, AV_LOG_ERROR, "Format supports only exactly one video stream\n");
30  return AVERROR(EINVAL);
31  }
32  ctx = s->streams[0]->codec;
33  if (ctx->codec_type != AVMEDIA_TYPE_VIDEO || ctx->codec_id != AV_CODEC_ID_VP8) {
34  av_log(s, AV_LOG_ERROR, "Currently only VP8 is supported!\n");
35  return AVERROR(EINVAL);
36  }
37  avio_write(pb, "DKIF", 4);
38  avio_wl16(pb, 0); // version
39  avio_wl16(pb, 32); // header length
40  avio_wl32(pb, ctx->codec_tag ? ctx->codec_tag : AV_RL32("VP80"));
41  avio_wl16(pb, ctx->width);
42  avio_wl16(pb, ctx->height);
43  avio_wl32(pb, s->streams[0]->time_base.den);
44  avio_wl32(pb, s->streams[0]->time_base.num);
45  avio_wl64(pb, s->streams[0]->duration); // TODO: duration or number of frames?!?
46 
47  return 0;
48 }
49 
51 {
52  AVIOContext *pb = s->pb;
53  avio_wl32(pb, pkt->size);
54  avio_wl64(pb, pkt->pts);
55  avio_write(pb, pkt->data, pkt->size);
56 
57  return 0;
58 }
59 
61  .name = "ivf",
62  .long_name = NULL_IF_CONFIG_SMALL("On2 IVF"),
63  .extensions = "ivf",
64  .audio_codec = AV_CODEC_ID_NONE,
65  .video_codec = AV_CODEC_ID_VP8,
66  .write_header = ivf_write_header,
67  .write_packet = ivf_write_packet,
68 };
void avio_wl16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:367
const char * s
Definition: avisynth_c.h:668
Bytestream IO Context.
Definition: avio.h:68
static int ivf_write_header(AVFormatContext *s)
Definition: ivfenc.c:23
int num
numerator
Definition: rational.h:44
AVOutputFormat ff_ivf_muxer
Definition: ivfenc.c:60
static int ivf_write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: ivfenc.c:50
Format I/O context.
Definition: avformat.h:944
void avio_wl32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:291
static AVPacket pkt
Definition: demuxing.c:56
AVStream ** streams
Definition: avformat.h:992
uint8_t * data
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:173
void avio_wl64(AVIOContext *s, uint64_t val)
Definition: aviobuf.c:355
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:662
unsigned int nb_streams
A list of all streams in the file.
Definition: avformat.h:991
int width
picture width / height.
const char * name
Definition: avformat.h:378
#define AV_RL32
enum AVMediaType codec_type
enum AVCodecID codec_id
AVIOContext * pb
I/O context.
Definition: avformat.h:977
main external API structure.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> (&#39;D&#39;<<24) + (&#39;C&#39;<<16) + (&#39;B&#39;<<8) + &#39;A&#39;).
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Buffer references ownership and permissions
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition: avformat.h:696
Main libavformat public API header.
int den
denominator
Definition: rational.h:45
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avformat.h:679
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...