Statistics
| Branch: | Revision:

ffmpeg / libavformat / ffmetaenc.c @ 14fa75ea

History | View | Annotate | Download (2.69 KB)

1
/*
2
 * Metadata muxer
3
 * Copyright (c) 2010 Anton Khirnov
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

    
22
#include "avformat.h"
23
#include "ffmeta.h"
24

    
25

    
26
static void write_escape_str(ByteIOContext *s, const uint8_t *str)
27
{
28
    const uint8_t *p = str;
29

    
30
    while (*p) {
31
        if (*p == '#' || *p == ';' || *p == '=' || *p == '\\' || *p == '\n')
32
            put_byte(s, '\\');
33
        put_byte(s, *p);
34
        p++;
35
    }
36
}
37

    
38
static void write_tags(ByteIOContext *s, AVMetadata *m)
39
{
40
    AVMetadataTag *t = NULL;
41
    while ((t = av_metadata_get(m, "", t, AV_METADATA_IGNORE_SUFFIX))) {
42
        write_escape_str(s, t->key);
43
        put_byte(s, '=');
44
        write_escape_str(s, t->value);
45
        put_byte(s, '\n');
46
    }
47
}
48

    
49
static int write_header(AVFormatContext *s)
50
{
51
    put_tag(s->pb, ID_STRING);
52
    put_byte(s->pb, '1');          // version
53
    put_byte(s->pb, '\n');
54
    put_flush_packet(s->pb);
55
    return 0;
56
}
57

    
58
static int write_trailer(AVFormatContext *s)
59
{
60
    int i;
61

    
62
    write_tags(s->pb, s->metadata);
63

    
64
    for (i = 0; i < s->nb_streams; i++) {
65
        put_tag(s->pb, ID_STREAM);
66
        put_byte(s->pb, '\n');
67
        write_tags(s->pb, s->streams[i]->metadata);
68
    }
69

    
70
    for (i = 0; i < s->nb_chapters; i++) {
71
        AVChapter *ch = s->chapters[i];
72
        put_tag(s->pb, ID_CHAPTER);
73
        put_byte(s->pb, '\n');
74
        url_fprintf(s->pb, "TIMEBASE=%d/%d\n", ch->time_base.num, ch->time_base.den);
75
        url_fprintf(s->pb, "START=%lld\n", ch->start);
76
        url_fprintf(s->pb, "END=%lld\n",   ch->end);
77
        write_tags(s->pb, ch->metadata);
78
    }
79

    
80
    put_flush_packet(s->pb);
81

    
82
    return 0;
83
}
84

    
85
static int write_packet(AVFormatContext *s, AVPacket *pkt)
86
{
87
    return 0;
88
}
89

    
90
AVOutputFormat ffmetadata_muxer = {
91
    .name          = "ffmetadata",
92
    .long_name     = NULL_IF_CONFIG_SMALL("FFmpeg metadata in text format"),
93
    .extensions    = "ffmeta",
94
    .write_header  = write_header,
95
    .write_packet  = write_packet,
96
    .write_trailer = write_trailer,
97
    .flags         = AVFMT_NOTIMESTAMPS | AVFMT_NOSTREAMS,
98
};