37 {
"start_time",
"set the start time (offset) of the subtitles, in ms",
39 { .i64 = 15000 }, INT64_MIN, INT64_MAX,
45 .class_name =
"tedcaptions_demuxer",
51#define BETWEEN(a, amin, amax) ((unsigned)((a) - (amin)) <= (amax) - (amin))
53#define HEX_DIGIT_TEST(c) (BETWEEN(c, '0', '9') || BETWEEN((c) | 32, 'a', 'z'))
54#define HEX_DIGIT_VAL(c) ((c) <= '9' ? (c) - '0' : ((c) | 32) - 'a' + 10)
55#define ERR_CODE(c) ((c) < 0 ? (c) : AVERROR_INVALIDDATA)
67 for (
i = bytes - 1;
i >= 0;
i--)
80 while (*cur_byte ==
' ' || *cur_byte ==
'\t' ||
81 *cur_byte ==
'\n' || *cur_byte ==
'\r')
101 while (*cur_byte > 0 && *cur_byte !=
'"') {
102 if (*cur_byte ==
'\\') {
106 if ((*cur_byte | 32) ==
'u') {
108 for (
i = 0;
i < 4;
i++) {
148 static const char *
const text[] = {
"false",
"true" };
153 for (
i = 0;
i < 2;
i++) {
160 if (
BETWEEN(*cur_byte | 32,
'a',
'z'))
173 if ((
unsigned)*cur_byte -
'0' > 9)
175 while (
BETWEEN(*cur_byte,
'0',
'9')) {
176 if (
val > INT_MAX/10 - (*cur_byte -
'0'))
178 val =
val * 10 + (*cur_byte -
'0');
187 int ret, cur_byte, start_of_par;
188 AVBPrint label, content;
199 if (ret < 0 || strcmp(label.str,
"captions"))
214 if (!strcmp(label.str,
"startOfParagraph")) {
218 }
else if (!strcmp(label.str,
"content")) {
222 }
else if (!strcmp(label.str,
"startTime")) {
226 }
else if (!strcmp(label.str,
"duration")) {
329 static const char *
const tags[] = {
330 "\"captions\"",
"\"duration\"",
"\"content\"",
331 "\"startOfParagraph\"",
"\"startTime\"",
333 unsigned i, count = 0;
336 if (p->buf[strspn(p->buf,
" \t\r\n")] !=
'{')
339 if (!(t = strstr(p->buf, tags[
i])))
341 t += strlen(tags[
i]);
342 t += strspn(t,
" \t\r\n");
356 min_ts, ts, max_ts,
flags);
360 .p.name =
"tedcaptions",
static double val(void *priv, double ch)
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
#define AV_BPRINT_SIZE_UNLIMITED
#define AV_BPRINT_SIZE_AUTOMATIC
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
static int read_probe(const AVProbeData *p)
#define FF_INFMT_FLAG_INIT_CLEANUP
For an FFInputFormat with this flag set read_close() needs to be called by the caller upon read_heade...
static int64_t start_time
static int read_header(FFV1Context *f, RangeCoder *c)
#define AV_OPT_FLAG_DECODING_PARAM
A generic parameter which can be set by the user for demuxing or decoding.
#define AV_OPT_FLAG_SUBTITLE_PARAM
@ AV_OPT_TYPE_INT64
Underlying C type is int64_t.
@ AV_CODEC_ID_TEXT
raw UTF-8 text
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
void av_bprint_chars(AVBPrint *buf, char c, unsigned n)
Append char c n times to a print buffer.
void av_bprint_clear(AVBPrint *buf)
Reset the string to "" but keep internal allocated data.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AVERROR_EOF
End of file.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define LIBAVUTIL_VERSION_INT
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static av_cold int read_close(AVFormatContext *ctx)
#define FF_ARRAY_ELEMS(a)
Describe the class of an AVClass context structure.
enum AVMediaType codec_type
General type of the encoded data.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
AVIOContext * pb
I/O context.
void * priv_data
Format private data.
This structure stores compressed data.
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
This structure contains the data a format has to probe a file.
AVCodecParameters * codecpar
Codec parameters associated with this stream.
int64_t duration
Decoding: duration of the stream, in stream time base.
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base.
int nb_subs
number of subtitles packets
AVPacket ** subs
array of subtitles packets
int probe_packets
Number of packets to buffer for codec probing.
FFDemuxSubtitlesQueue subs
int ff_subtitles_queue_seek(FFDemuxSubtitlesQueue *q, AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
Update current_sub_idx to emulate a seek.
int ff_subtitles_queue_read_packet(FFDemuxSubtitlesQueue *q, AVPacket *pkt)
Generic read_packet() callback for subtitles demuxers using this queue system.
AVPacket * ff_subtitles_queue_insert_bprint(FFDemuxSubtitlesQueue *q, const AVBPrint *event, int merge)
Same as ff_subtitles_queue_insert but takes an AVBPrint input.
void ff_subtitles_queue_finalize(void *log_ctx, FFDemuxSubtitlesQueue *q)
Set missing durations, sort subtitles by PTS (and then byte position), and drop duplicated events.
void ff_subtitles_queue_clean(FFDemuxSubtitlesQueue *q)
Remove and destroy all the subtitles packets.
#define BETWEEN(a, amin, amax)
static int tedcaptions_read_close(AVFormatContext *avf)
static int tedcaptions_read_packet(AVFormatContext *avf, AVPacket *packet)
static void skip_spaces(AVIOContext *pb, int *cur_byte)
static const AVClass tedcaptions_demuxer_class
static void next_byte(AVIOContext *pb, int *cur_byte)
static int parse_string(AVIOContext *pb, int *cur_byte, AVBPrint *bp, int full)
static int parse_boolean(AVIOContext *pb, int *cur_byte, int *result)
static int parse_int(AVIOContext *pb, int *cur_byte, int64_t *result)
static int parse_label(AVIOContext *pb, int *cur_byte, AVBPrint *bp)
static const AVOption tedcaptions_options[]
static int expect_byte(AVIOContext *pb, int *cur_byte, uint8_t c)
static int tedcaptions_read_seek(AVFormatContext *avf, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
static av_cold int tedcaptions_read_header(AVFormatContext *avf)
static av_cold int tedcaptions_read_probe(const AVProbeData *p)
#define HEX_DIGIT_TEST(c)
static void av_bprint_utf8(AVBPrint *bp, unsigned c)
static int parse_file(AVIOContext *pb, FFDemuxSubtitlesQueue *subs)