FFmpeg: libavformat/lrcenc.c Source File
Go to the documentation of this file. 1 /*
2 * LRC lyrics file format muxer
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
39 int precision;
///< precision of the fractional part of the timestamp, 2 for centiseconds
41
43 {
45
51 }
53
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;
67 char *delim;
68 if(!metadata_item->
value[0]) {
69 continue;
70 }
71 while((delim = strchr(metadata_item->
value,
'\n'))) {
72 *delim = ' ';
73 }
74 while((delim = strchr(metadata_item->
value,
'\r'))) {
75 *delim = ' ';
76 }
78 metadata_item->
key, metadata_item->
value);
79 }
81 return 0;
82 }
83
85 {
87
91
92 while (end >
line && (end[-1] ==
'\n' || end[-1] ==
'\r'))
93 end--;
95 while (
line[0] ==
'\n' ||
line[0] ==
'\r')
96 line++;
// Skip first empty lines
97 }
98
99 int frac_mult = 1;
100 for (
int i = 0;
i <
p->precision; ++
i)
101 frac_mult *= 10;
102
104 const uint8_t *next_line = memchr(
line,
'\n', end -
line);
106
107 if (next_line) {
109 if (next_line >
line && next_line[-1] ==
'\r')
111 next_line++;
112 }
115 "Subtitle starts with '[', may cause problems with LRC format.\n");
116 }
117
118 /* Offset feature of LRC can easily make pts negative,
119 * we just output it directly and let the player drop it. */
126 avio_printf(
s->pb,
"%02"PRIu64
":%02"PRIu64
".%0*"PRIu64
"]",
127 minutes, seconds,
p->precision, rescaled);
128
132 }
133 }
134 return 0;
135 }
136
137 #define OFFSET(x) offsetof(LRCSubtitleContext, x)
138 #define SE AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_ENCODING_PARAM
140 {
"precision",
"precision of the fractional part of the timestamp, 2 for centiseconds",
OFFSET(precision),
AV_OPT_TYPE_INT, {.i64 = 2}, 1, 6,
SE},
142 };
143
149 };
150
154 .p.extensions = "lrc",
165 };
#define AV_LOG_WARNING
Something somehow does not look correct.
Filter the word "frame" indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
int precision
precision of the fractional part of the timestamp, 2 for centiseconds
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
const FFOutputFormat ff_lrc_muxer
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int lrc_write_packet(AVFormatContext *s, AVPacket *pkt)
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
static const AVOption options[]
const AVMetadataConv ff_lrc_metadata_conv[]
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
Rational number (pair of numerator and denominator).
const char * av_default_item_name(void *ptr)
Return the context name.
void avio_w8(AVIOContext *s, int b)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int ff_standardize_creation_time(AVFormatContext *s)
Standardize creation_time metadata in AVFormatContext to an ISO-8601 timestamp string.
#define AV_NOPTS_VALUE
Undefined timestamp value.
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
#define i(width, name, range_min, range_max)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
#define AV_TIME_BASE
Internal time base represented as integer.
#define FF_OFMT_FLAG_MAX_ONE_OF_EACH
If this flag is set, it indicates that for each codec type whose corresponding default codec (i....
static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
@ AV_CODEC_ID_TEXT
raw UTF-8 text
int avio_printf(AVIOContext *s, const char *fmt,...) av_printf_format(2
Writes a formatted string to the context.
static const AVClass lrcenc_class
@ AV_OPT_TYPE_INT
Underlying C type is int.
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
This structure stores compressed data.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
static void write_header(FFV1Context *f)
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
The official guide to swscale for confused that consecutive non overlapping rectangles of slice_bottom special converter These generally are unscaled converters of common like for each output line the vertical scaler pulls lines from a ring buffer When the ring buffer does not contain the wanted line
static int lrc_write_header(AVFormatContext *s)
Generated on Tue Nov 18 2025 19:23:28 for FFmpeg by
doxygen
1.8.17