Merge remote-tracking branch 'libav/master'
[FFMpeg-mirror/mplayer-patches.git] / libavformat / filmstripenc.c
blob90d9a7685c6076703b58085eabe9b379422be294
1 /*
2 * Adobe Filmstrip muxer
3 * Copyright (c) 2010 Peter Ross
5 * This file is part of Libav.
7 * Libav 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.
12 * Libav 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.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with Libav; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 /**
23 * @file
24 * Adobe Filmstrip muxer
27 #include "libavutil/intreadwrite.h"
28 #include "avformat.h"
30 #define RAND_TAG MKBETAG('R','a','n','d')
32 typedef struct {
33 int nb_frames;
34 } FilmstripMuxContext;
36 static int write_header(AVFormatContext *s)
38 if (s->streams[0]->codec->pix_fmt != AV_PIX_FMT_RGBA) {
39 av_log(s, AV_LOG_ERROR, "only AV_PIX_FMT_RGBA is supported\n");
40 return AVERROR_INVALIDDATA;
42 return 0;
45 static int write_packet(AVFormatContext *s, AVPacket *pkt)
47 FilmstripMuxContext *film = s->priv_data;
48 avio_write(s->pb, pkt->data, pkt->size);
49 film->nb_frames++;
50 return 0;
53 static int write_trailer(AVFormatContext *s)
55 FilmstripMuxContext *film = s->priv_data;
56 AVIOContext *pb = s->pb;
57 AVStream *st = s->streams[0];
58 int i;
60 avio_wb32(pb, RAND_TAG);
61 avio_wb32(pb, film->nb_frames);
62 avio_wb16(pb, 0); // packing method
63 avio_wb16(pb, 0); // reserved
64 avio_wb16(pb, st->codec->width);
65 avio_wb16(pb, st->codec->height);
66 avio_wb16(pb, 0); // leading
67 avio_wb16(pb, 1/av_q2d(st->codec->time_base));
68 for (i = 0; i < 16; i++)
69 avio_w8(pb, 0x00); // reserved
71 return 0;
74 AVOutputFormat ff_filmstrip_muxer = {
75 .name = "filmstrip",
76 .long_name = NULL_IF_CONFIG_SMALL("Adobe Filmstrip"),
77 .extensions = "flm",
78 .priv_data_size = sizeof(FilmstripMuxContext),
79 .audio_codec = AV_CODEC_ID_NONE,
80 .video_codec = AV_CODEC_ID_RAWVIDEO,
81 .write_header = write_header,
82 .write_packet = write_packet,
83 .write_trailer = write_trailer,