ffmpeg / libavformat / assenc.c @ 56a10009
History | View | Annotate | Download (2.55 KB)
1 | 88caf345 | Michael Niedermayer | /*
|
---|---|---|---|
2 | * SSA/ASS muxer
|
||
3 | * Copyright (c) 2008 Michael Niedermayer
|
||
4 | *
|
||
5 | 2912e87a | Mans Rullgard | * This file is part of Libav.
|
6 | 88caf345 | Michael Niedermayer | *
|
7 | 2912e87a | Mans Rullgard | * Libav is free software; you can redistribute it and/or
|
8 | 88caf345 | Michael Niedermayer | * 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 | 2912e87a | Mans Rullgard | * Libav is distributed in the hope that it will be useful,
|
13 | 88caf345 | Michael Niedermayer | * 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 | 2912e87a | Mans Rullgard | * License along with Libav; if not, write to the Free Software
|
19 | 88caf345 | Michael Niedermayer | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
20 | */
|
||
21 | |||
22 | #include "avformat.h" |
||
23 | |||
24 | typedef struct ASSContext{ |
||
25 | unsigned int extra_index; |
||
26 | }ASSContext; |
||
27 | |||
28 | static int write_header(AVFormatContext *s) |
||
29 | { |
||
30 | ASSContext *ass = s->priv_data; |
||
31 | AVCodecContext *avctx= s->streams[0]->codec;
|
||
32 | uint8_t *last= NULL;
|
||
33 | |||
34 | if(s->nb_streams != 1 || avctx->codec_id != CODEC_ID_SSA){ |
||
35 | av_log(s, AV_LOG_ERROR, "Exactly one ASS/SSA stream is needed.\n");
|
||
36 | return -1; |
||
37 | } |
||
38 | |||
39 | while(ass->extra_index < avctx->extradata_size){
|
||
40 | uint8_t *p = avctx->extradata + ass->extra_index; |
||
41 | uint8_t *end= strchr(p, '\n');
|
||
42 | if(!end) end= avctx->extradata + avctx->extradata_size;
|
||
43 | else end++;
|
||
44 | |||
45 | 77eb5504 | Anton Khirnov | avio_write(s->pb, p, end-p); |
46 | 88caf345 | Michael Niedermayer | ass->extra_index += end-p; |
47 | |||
48 | if(last && !memcmp(last, "[Events]", 8)) |
||
49 | break;
|
||
50 | last=p; |
||
51 | } |
||
52 | |||
53 | b7f2fdde | Anton Khirnov | avio_flush(s->pb); |
54 | 88caf345 | Michael Niedermayer | |
55 | return 0; |
||
56 | } |
||
57 | |||
58 | static int write_packet(AVFormatContext *s, AVPacket *pkt) |
||
59 | { |
||
60 | 77eb5504 | Anton Khirnov | avio_write(s->pb, pkt->data, pkt->size); |
61 | 88caf345 | Michael Niedermayer | |
62 | b7f2fdde | Anton Khirnov | avio_flush(s->pb); |
63 | 88caf345 | Michael Niedermayer | |
64 | return 0; |
||
65 | } |
||
66 | |||
67 | static int write_trailer(AVFormatContext *s) |
||
68 | { |
||
69 | ASSContext *ass = s->priv_data; |
||
70 | AVCodecContext *avctx= s->streams[0]->codec;
|
||
71 | |||
72 | 77eb5504 | Anton Khirnov | avio_write(s->pb, avctx->extradata + ass->extra_index, |
73 | 88caf345 | Michael Niedermayer | avctx->extradata_size - ass->extra_index); |
74 | |||
75 | b7f2fdde | Anton Khirnov | avio_flush(s->pb); |
76 | 88caf345 | Michael Niedermayer | |
77 | return 0; |
||
78 | } |
||
79 | |||
80 | c6610a21 | Diego Elio Pettenò | AVOutputFormat ff_ass_muxer = { |
81 | 87d69d32 | Aurelien Jacobs | .name = "ass",
|
82 | .long_name = NULL_IF_CONFIG_SMALL("Advanced SubStation Alpha subtitle format"),
|
||
83 | .mime_type = "text/x-ssa",
|
||
84 | .extensions = "ass,ssa",
|
||
85 | .priv_data_size = sizeof(ASSContext),
|
||
86 | 5bdbf64c | Aurelien Jacobs | .subtitle_codec = CODEC_ID_SSA, |
87 | 87d69d32 | Aurelien Jacobs | .write_header = write_header, |
88 | .write_packet = write_packet, |
||
89 | .write_trailer = write_trailer, |
||
90 | 908dc2a0 | Aurelien Jacobs | .flags = AVFMT_GLOBALHEADER | AVFMT_NOTIMESTAMPS, |
91 | 88caf345 | Michael Niedermayer | }; |