36 {
"start_time",
"set the start time (offset) of the subtitles, in ms",
38 { .i64 = 15000 }, INT64_MIN, INT64_MAX,
50 #define BETWEEN(a, amin, amax) ((unsigned)((a) - (amin)) <= (amax) - (amin))
52 #define HEX_DIGIT_TEST(c) (BETWEEN(c, '0', '9') || BETWEEN((c) | 32, 'a', 'z'))
53 #define HEX_DIGIT_VAL(c) ((c) <= '9' ? (c) - '0' : ((c) | 32) - 'a' + 10)
54 #define ERR_CODE(c) ((c) < 0 ? (c) : AVERROR_INVALIDDATA)
65 av_bprint_chars(bp, (c >> (bytes * 6)) | ((0xFF80 >> bytes) & 0xFF), 1);
66 for (i = bytes - 1; i >= 0; i--)
74 *cur_byte = ret > 0 ? b : ret == 0 ?
AVERROR_EOF : ret;
79 while (*cur_byte ==
' ' || *cur_byte ==
'\t' ||
80 *cur_byte ==
'\n' || *cur_byte ==
'\r')
101 while (*cur_byte > 0 && *cur_byte !=
'"') {
102 if (*cur_byte ==
'\\') {
108 if ((*cur_byte | 32) ==
'u') {
110 for (i = 0; i < 4; i++) {
156 static const char *
const text[] = {
"false",
"true" };
161 for (i = 0; i < 2; i++) {
168 if (
BETWEEN(*cur_byte | 32,
'a',
'z'))
181 if ((
unsigned)*cur_byte -
'0' > 9)
183 while (
BETWEEN(*cur_byte,
'0',
'9')) {
184 val = val * 10 + (*cur_byte -
'0');
193 int ret, cur_byte, start_of_par;
194 AVBPrint label, content;
203 if (ret < 0 || strcmp(label.str,
"captions"))
219 if (!strcmp(label.str,
"startOfParagraph")) {
223 }
else if (!strcmp(label.str,
"content")) {
227 }
else if (!strcmp(label.str,
"startTime")) {
231 }
else if (!strcmp(label.str,
"duration")) {
232 ret =
parse_int(pb, &cur_byte, &duration);
326 static const char *
const tags[] = {
327 "\"captions\"",
"\"duration\"",
"\"content\"",
328 "\"startOfParagraph\"",
"\"startTime\"",
330 unsigned i,
count = 0;
333 if (p->
buf[strspn(p->
buf,
" \t\r\n")] !=
'{')
336 if (!(t = strstr(p->
buf, tags[i])))
338 t += strlen(tags[i]);
339 t += strspn(t,
" \t\r\n");
348 int64_t min_ts, int64_t ts, int64_t max_ts,
353 min_ts, ts, max_ts, flags);
357 .
name =
"tedcaptions",
360 .priv_class = &tedcaptions_demuxer_class,
const char const char void * val
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static int tedcaptions_read_seek(AVFormatContext *avf, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
#define AV_OPT_FLAG_SUBTITLE_PARAM
#define LIBAVUTIL_VERSION_INT
int64_t pos
byte position in stream, -1 if unknown
int probe_packets
Number of packets to buffer for codec probing.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
void ff_subtitles_queue_clean(FFDemuxSubtitlesQueue *q)
Remove and destroy all the subtitles packets.
static void av_bprint_utf8(AVBPrint *bp, unsigned c)
AVInputFormat ff_tedcaptions_demuxer
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
#define BETWEEN(a, amin, amax)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
static const AVClass tedcaptions_demuxer_class
static int64_t start_time
FFDemuxSubtitlesQueue subs
int ff_subtitles_queue_read_packet(FFDemuxSubtitlesQueue *q, AVPacket *pkt)
Generic read_packet() callback for subtitles demuxers using this queue system.
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
static int tedcaptions_read_packet(AVFormatContext *avf, AVPacket *packet)
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
static void skip_spaces(AVIOContext *pb, int *cur_byte)
#define AVERROR_EOF
End of file.
static av_cold int read_close(AVFormatContext *ctx)
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.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
enum AVMediaType codec_type
General type of the encoded data.
static int parse_label(AVIOContext *pb, int *cur_byte, AVBPrint *bp)
static int tedcaptions_read_close(AVFormatContext *avf)
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
static int parse_file(AVIOContext *pb, FFDemuxSubtitlesQueue *subs)
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
static void next_byte(AVIOContext *pb, int *cur_byte)
static av_cold int tedcaptions_read_header(AVFormatContext *avf)
#define FF_ARRAY_ELEMS(a)
static int read_header(FFV1Context *f)
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
#define HEX_DIGIT_TEST(c)
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.
AVIOContext * pb
I/O context.
Describe the class of an AVClass context structure.
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
This structure contains the data a format has to probe a file.
int64_t duration
Decoding: duration of the stream, in stream time base.
static int expect_byte(AVIOContext *pb, int *cur_byte, uint8_t c)
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base...
static const AVOption tedcaptions_options[]
AVPacket * subs
array of subtitles packets
void * priv_data
Format private data.
static int parse_string(AVIOContext *pb, int *cur_byte, AVBPrint *bp, int full)
static int parse_boolean(AVIOContext *pb, int *cur_byte, int *result)
AVCodecParameters * codecpar
AVPacket * ff_subtitles_queue_insert(FFDemuxSubtitlesQueue *q, const uint8_t *event, size_t len, int merge)
Insert a new subtitle event.
This structure stores compressed data.
int nb_subs
number of subtitles packets
static av_cold int tedcaptions_read_probe(AVProbeData *p)
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...
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
#define AV_NOPTS_VALUE
Undefined timestamp value.
void av_bprint_chars(AVBPrint *buf, char c, unsigned n)
Append char c n times to a print buffer.
static int parse_int(AVIOContext *pb, int *cur_byte, int64_t *result)