annotate ffmpeg/libavformat/ffmetaenc.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 * Metadata muxer
yading@11 3 * Copyright (c) 2010 Anton Khirnov
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
yading@11 22 #include <inttypes.h>
yading@11 23
yading@11 24 #include "avformat.h"
yading@11 25 #include "ffmeta.h"
yading@11 26 #include "libavutil/dict.h"
yading@11 27
yading@11 28
yading@11 29 static void write_escape_str(AVIOContext *s, const uint8_t *str)
yading@11 30 {
yading@11 31 const uint8_t *p = str;
yading@11 32
yading@11 33 while (*p) {
yading@11 34 if (*p == '#' || *p == ';' || *p == '=' || *p == '\\' || *p == '\n')
yading@11 35 avio_w8(s, '\\');
yading@11 36 avio_w8(s, *p);
yading@11 37 p++;
yading@11 38 }
yading@11 39 }
yading@11 40
yading@11 41 static void write_tags(AVIOContext *s, AVDictionary *m)
yading@11 42 {
yading@11 43 AVDictionaryEntry *t = NULL;
yading@11 44 while ((t = av_dict_get(m, "", t, AV_DICT_IGNORE_SUFFIX))) {
yading@11 45 write_escape_str(s, t->key);
yading@11 46 avio_w8(s, '=');
yading@11 47 write_escape_str(s, t->value);
yading@11 48 avio_w8(s, '\n');
yading@11 49 }
yading@11 50 }
yading@11 51
yading@11 52 static int write_header(AVFormatContext *s)
yading@11 53 {
yading@11 54 avio_write(s->pb, ID_STRING, sizeof(ID_STRING) - 1);
yading@11 55 avio_w8(s->pb, '1'); // version
yading@11 56 avio_w8(s->pb, '\n');
yading@11 57 avio_flush(s->pb);
yading@11 58 return 0;
yading@11 59 }
yading@11 60
yading@11 61 static int write_trailer(AVFormatContext *s)
yading@11 62 {
yading@11 63 int i;
yading@11 64
yading@11 65 write_tags(s->pb, s->metadata);
yading@11 66
yading@11 67 for (i = 0; i < s->nb_streams; i++) {
yading@11 68 avio_write(s->pb, ID_STREAM, sizeof(ID_STREAM) - 1);
yading@11 69 avio_w8(s->pb, '\n');
yading@11 70 write_tags(s->pb, s->streams[i]->metadata);
yading@11 71 }
yading@11 72
yading@11 73 for (i = 0; i < s->nb_chapters; i++) {
yading@11 74 AVChapter *ch = s->chapters[i];
yading@11 75 avio_write(s->pb, ID_CHAPTER, sizeof(ID_CHAPTER) - 1);
yading@11 76 avio_w8(s->pb, '\n');
yading@11 77 avio_printf(s->pb, "TIMEBASE=%d/%d\n", ch->time_base.num, ch->time_base.den);
yading@11 78 avio_printf(s->pb, "START=%"PRId64"\n", ch->start);
yading@11 79 avio_printf(s->pb, "END=%"PRId64"\n", ch->end);
yading@11 80 write_tags(s->pb, ch->metadata);
yading@11 81 }
yading@11 82
yading@11 83 return 0;
yading@11 84 }
yading@11 85
yading@11 86 static int write_packet(AVFormatContext *s, AVPacket *pkt)
yading@11 87 {
yading@11 88 return 0;
yading@11 89 }
yading@11 90
yading@11 91 AVOutputFormat ff_ffmetadata_muxer = {
yading@11 92 .name = "ffmetadata",
yading@11 93 .long_name = NULL_IF_CONFIG_SMALL("FFmpeg metadata in text"),
yading@11 94 .extensions = "ffmeta",
yading@11 95 .write_header = write_header,
yading@11 96 .write_packet = write_packet,
yading@11 97 .write_trailer = write_trailer,
yading@11 98 .flags = AVFMT_NOTIMESTAMPS | AVFMT_NOSTREAMS,
yading@11 99 };