annotate filmstripenc.c @ 6337:8788871cbc99 libavformat

add seeking support in ASS demuxer
author aurel
date Thu, 29 Jul 2010 22:10:22 +0000
parents 178de7695c6c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5547
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
1 /*
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
2 * Adobe Filmstrip muxer
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
3 * Copyright (c) 2010 Peter Ross
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
4 *
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
5 * This file is part of FFmpeg.
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
6 *
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
11 *
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
15 * Lesser General Public License for more details.
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
16 *
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
20 */
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
21
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
22 /**
5969
178de7695c6c Remove explicit filename from Doxygen @file commands.
diego
parents: 5547
diff changeset
23 * @file
5547
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
24 * Adobe Filmstrip muxer
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
25 */
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
26
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
27 #include "libavutil/intreadwrite.h"
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
28 #include "avformat.h"
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
29
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
30 #define RAND_TAG MKBETAG('R','a','n','d')
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
31
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
32 typedef struct {
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
33 int nb_frames;
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
34 } FilmstripMuxContext;
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
35
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
36 static int write_header(AVFormatContext *s)
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
37 {
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
38 if (s->streams[0]->codec->pix_fmt != PIX_FMT_RGBA) {
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
39 av_log(s, AV_LOG_ERROR, "only PIX_FMT_RGBA is supported\n");
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
40 return AVERROR_INVALIDDATA;
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
41 }
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
42 return 0;
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
43 }
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
44
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
45 static int write_packet(AVFormatContext *s, AVPacket *pkt)
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
46 {
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
47 FilmstripMuxContext *film = s->priv_data;
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
48 put_buffer(s->pb, pkt->data, pkt->size);
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
49 film->nb_frames++;
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
50 return 0;
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
51 }
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
52
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
53 static int write_trailer(AVFormatContext *s)
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
54 {
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
55 FilmstripMuxContext *film = s->priv_data;
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
56 ByteIOContext *pb = s->pb;
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
57 AVStream *st = s->streams[0];
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
58 int i;
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
59
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
60 put_be32(pb, RAND_TAG);
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
61 put_be32(pb, film->nb_frames);
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
62 put_be16(pb, 0); // packing method
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
63 put_be16(pb, 0); // reserved
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
64 put_be16(pb, st->codec->width);
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
65 put_be16(pb, st->codec->height);
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
66 put_be16(pb, 0); // leading
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
67 put_be16(pb, 1/av_q2d(st->codec->time_base));
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
68 for (i = 0; i < 16; i++)
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
69 put_byte(pb, 0x00); // reserved
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
70 put_flush_packet(pb);
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
71 return 0;
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
72 }
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
73
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
74 AVOutputFormat filmstrip_muxer = {
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
75 "filmstrip",
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
76 NULL_IF_CONFIG_SMALL("Adobe Filmstrip"),
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
77 NULL,
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
78 "flm",
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
79 sizeof(FilmstripMuxContext),
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
80 CODEC_ID_NONE,
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
81 CODEC_ID_RAWVIDEO,
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
82 write_header,
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
83 write_packet,
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
84 write_trailer,
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
85 };