1 /*
2 * LRC lyrics file format decoder
3 * Copyright (c) 2014 StarBrilliant <m13253@hotmail.com>
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 <inttypes.h>
23 #include <stdint.h>
24 #include <string.h>
25
36
38 {
40
44 "LRC supports only a single subtitle stream.\n");
46 }
52 }
54
57 /* LRC provides a metadata slot for specifying encoder version
58 * in addition to encoder name. We will store LIBAVFORMAT_VERSION
59 * to it.
60 */
62 } else {
64 }
65 for(metadata_item =
NULL;
68 char *delim;
69 if(!metadata_item->
value[0]) {
70 continue;
71 }
72 while((delim = strchr(metadata_item->
value,
'\n'))) {
73 *delim = ' ';
74 }
75 while((delim = strchr(metadata_item->
value,
'\r'))) {
76 *delim = ' ';
77 }
79 metadata_item->
key, metadata_item->
value);
80 }
82 return 0;
83 }
84
86 {
90 char *delim;
91
92 if(!data) {
94 }
96 data[pkt->
size] =
'0円';
97
98 for(delim = data + pkt->
size - 1;
99 delim >= data && (delim[0] == '\n' || delim[0] == '\r'); delim--) {
100 delim[0] = '0円'; // Strip last empty lines
101 }
103 while(line[0] == '\n' || line[0] == '\r') {
104 line++; // Skip first empty lines
105 }
106
107 while(line) {
108 delim = strchr(line, '\n');
109 if(delim) {
110 if(delim > line && delim[-1] == '\r') {
111 delim[-1] = '0円';
112 }
113 delim[0] = '0円';
114 delim++;
115 }
116 if(line[0] == '[') {
118 "Subtitle starts with '[', may cause problems with LRC format.\n");
119 }
120
124 ((pkt->
pts / 100) % 60),
126 } else {
127 /* Offset feature of LRC can easily make pts negative,
128 * we just output it directly and let the player drop it. */
131 ((-pkt->
pts) / 100) % 60,
133 }
135 line = delim;
136 }
138 }
139 return 0;
140 }
141
145 .extensions = "lrc",
146 .priv_data_size = 0,
152 };