FFmpeg
subtitles.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2013 Clément Bœsch <u pkh me>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "avformat.h"
22 #include "subtitles.h"
23 #include "avio_internal.h"
24 #include "libavutil/avstring.h"
25 
27 {
28  int i;
29  r->pb = pb;
30  r->buf_pos = r->buf_len = 0;
31  r->type = FF_UTF_8;
32  for (i = 0; i < 2; i++)
33  r->buf[r->buf_len++] = avio_r8(r->pb);
34  if (strncmp("\xFF\xFE", r->buf, 2) == 0) {
35  r->type = FF_UTF16LE;
36  r->buf_pos += 2;
37  } else if (strncmp("\xFE\xFF", r->buf, 2) == 0) {
38  r->type = FF_UTF16BE;
39  r->buf_pos += 2;
40  } else {
41  r->buf[r->buf_len++] = avio_r8(r->pb);
42  if (strncmp("\xEF\xBB\xBF", r->buf, 3) == 0) {
43  // UTF8
44  r->buf_pos += 3;
45  }
46  }
47  if (s && (r->type == FF_UTF16LE || r->type == FF_UTF16BE))
49  "UTF16 is automatically converted to UTF8, do not specify a character encoding\n");
50 }
51 
52 void ff_text_init_buf(FFTextReader *r, const void *buf, size_t size)
53 {
54  ffio_init_read_context(&r->buf_pb, buf, size);
55  ff_text_init_avio(NULL, r, &r->buf_pb.pub);
56 }
57 
59 {
60  return avio_tell(r->pb) - r->buf_len + r->buf_pos;
61 }
62 
64 {
65  uint32_t val;
66  uint8_t tmp;
67  if (r->buf_pos < r->buf_len)
68  return r->buf[r->buf_pos++];
69  if (r->type == FF_UTF16LE) {
70  GET_UTF16(val, avio_rl16(r->pb), return 0;)
71  } else if (r->type == FF_UTF16BE) {
72  GET_UTF16(val, avio_rb16(r->pb), return 0;)
73  } else {
74  return avio_r8(r->pb);
75  }
76  if (!val)
77  return 0;
78  r->buf_pos = 0;
79  r->buf_len = 0;
80  PUT_UTF8(val, tmp, r->buf[r->buf_len++] = tmp;)
81  return r->buf[r->buf_pos++]; // buf_len is at least 1
82 }
83 
84 void ff_text_read(FFTextReader *r, char *buf, size_t size)
85 {
86  for ( ; size > 0; size--)
87  *buf++ = ff_text_r8(r);
88 }
89 
91 {
92  return r->buf_pos >= r->buf_len && avio_feof(r->pb);
93 }
94 
96 {
97  int c;
98  if (r->buf_pos < r->buf_len)
99  return r->buf[r->buf_pos];
100  c = ff_text_r8(r);
101  if (!avio_feof(r->pb)) {
102  r->buf_pos = 0;
103  r->buf_len = 1;
104  r->buf[0] = c;
105  }
106  return c;
107 }
108 
110  const uint8_t *event, size_t len, int merge)
111 {
112  AVPacket **subs, *sub;
113 
114  if (merge && q->nb_subs > 0) {
115  /* merge with previous event */
116 
117  int old_len;
118  sub = q->subs[q->nb_subs - 1];
119  old_len = sub->size;
120  if (av_grow_packet(sub, len) < 0)
121  return NULL;
122  memcpy(sub->data + old_len, event, len);
123  } else {
124  /* new event */
125 
126  if (q->nb_subs >= INT_MAX/sizeof(*q->subs) - 1)
127  return NULL;
128  subs = av_fast_realloc(q->subs, &q->allocated_size,
129  (q->nb_subs + 1) * sizeof(*q->subs));
130  if (!subs)
131  return NULL;
132  q->subs = subs;
133  sub = av_packet_alloc();
134  if (!sub)
135  return NULL;
136  if (av_new_packet(sub, len) < 0) {
137  av_packet_free(&sub);
138  return NULL;
139  }
140  subs[q->nb_subs++] = sub;
141  sub->flags |= AV_PKT_FLAG_KEY;
142  sub->pts = sub->dts = 0;
143  memcpy(sub->data, event, len);
144  }
145  return sub;
146 }
147 
149  const AVBPrint *event, int merge)
150 {
151  if (!av_bprint_is_complete(event))
152  return NULL;
153  return ff_subtitles_queue_insert(q, event->str, event->len, merge);
154 }
155 
156 static int cmp_pkt_sub_ts_pos(const void *a, const void *b)
157 {
158  const AVPacket *s1 = *(const AVPacket **)a;
159  const AVPacket *s2 = *(const AVPacket **)b;
160  if (s1->pts == s2->pts)
161  return FFDIFFSIGN(s1->pos, s2->pos);
162  return FFDIFFSIGN(s1->pts , s2->pts);
163 }
164 
165 static int cmp_pkt_sub_pos_ts(const void *a, const void *b)
166 {
167  const AVPacket *s1 = *(const AVPacket **)a;
168  const AVPacket *s2 = *(const AVPacket **)b;
169  if (s1->pos == s2->pos) {
170  if (s1->pts == s2->pts)
171  return 0;
172  return s1->pts > s2->pts ? 1 : -1;
173  }
174  return s1->pos > s2->pos ? 1 : -1;
175 }
176 
177 static void drop_dups(void *log_ctx, FFDemuxSubtitlesQueue *q)
178 {
179  int i, drop = 0;
180 
181  for (i = 1; i < q->nb_subs; i++) {
182  const int last_id = i - 1 - drop;
183  const AVPacket *last = q->subs[last_id];
184 
185  if (q->subs[i]->pts == last->pts &&
186  q->subs[i]->duration == last->duration &&
187  q->subs[i]->stream_index == last->stream_index &&
188  !strcmp(q->subs[i]->data, last->data)) {
189 
190  av_packet_free(&q->subs[i]);
191  drop++;
192  } else if (drop) {
193  q->subs[last_id + 1] = q->subs[i];
194  q->subs[i] = NULL;
195  }
196  }
197 
198  if (drop) {
199  q->nb_subs -= drop;
200  av_log(log_ctx, AV_LOG_WARNING, "Dropping %d duplicated subtitle events\n", drop);
201  }
202 }
203 
205 {
206  int i;
207 
208  if (!q->nb_subs)
209  return;
210 
211  qsort(q->subs, q->nb_subs, sizeof(*q->subs),
214  for (i = 0; i < q->nb_subs; i++)
215  if (q->subs[i]->duration < 0 && i < q->nb_subs - 1 && q->subs[i + 1]->pts - (uint64_t)q->subs[i]->pts <= INT64_MAX)
216  q->subs[i]->duration = q->subs[i + 1]->pts - q->subs[i]->pts;
217 
218  if (!q->keep_duplicates)
219  drop_dups(log_ctx, q);
220 }
221 
223 {
224  AVPacket *sub;
225  int ret;
226 
227  if (q->current_sub_idx == q->nb_subs)
228  return AVERROR_EOF;
229  sub = q->subs[q->current_sub_idx];
230  if ((ret = av_packet_ref(pkt, sub)) < 0) {
231  return ret;
232  }
233 
234  pkt->dts = pkt->pts;
235  q->current_sub_idx++;
236  return 0;
237 }
238 
239 static int search_sub_ts(const FFDemuxSubtitlesQueue *q, int64_t ts)
240 {
241  int s1 = 0, s2 = q->nb_subs - 1;
242 
243  if (s2 < s1)
244  return AVERROR(ERANGE);
245 
246  for (;;) {
247  int mid;
248 
249  if (s1 == s2)
250  return s1;
251  if (s1 == s2 - 1)
252  return q->subs[s1]->pts <= q->subs[s2]->pts ? s1 : s2;
253  mid = (s1 + s2) / 2;
254  if (q->subs[mid]->pts <= ts)
255  s1 = mid;
256  else
257  s2 = mid;
258  }
259 }
260 
262  int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
263 {
264  if (flags & AVSEEK_FLAG_BYTE) {
265  return AVERROR(ENOSYS);
266  } else if (flags & AVSEEK_FLAG_FRAME) {
267  if (ts < 0 || ts >= q->nb_subs)
268  return AVERROR(ERANGE);
269  q->current_sub_idx = ts;
270  } else {
271  int i, idx = search_sub_ts(q, ts);
272  int64_t ts_selected;
273 
274  if (idx < 0)
275  return idx;
276  for (i = idx; i < q->nb_subs && q->subs[i]->pts < min_ts; i++)
277  if (stream_index == -1 || q->subs[i]->stream_index == stream_index)
278  idx = i;
279  for (i = idx; i > 0 && q->subs[i]->pts > max_ts; i--)
280  if (stream_index == -1 || q->subs[i]->stream_index == stream_index)
281  idx = i;
282 
283  ts_selected = q->subs[idx]->pts;
284  if (ts_selected < min_ts || ts_selected > max_ts)
285  return AVERROR(ERANGE);
286 
287  /* look back in the latest subtitles for overlapping subtitles */
288  for (i = idx - 1; i >= 0; i--) {
289  int64_t pts = q->subs[i]->pts;
290  if (q->subs[i]->duration <= 0 ||
291  (stream_index != -1 && q->subs[i]->stream_index != stream_index))
292  continue;
293  if (pts >= min_ts && pts > ts_selected - q->subs[i]->duration)
294  idx = i;
295  else
296  break;
297  }
298 
299  /* If the queue is used to store multiple subtitles streams (like with
300  * VobSub) and the stream index is not specified, we need to make sure
301  * to focus on the smallest file position offset for a same timestamp;
302  * queue is ordered by pts and then filepos, so we can take the first
303  * entry for a given timestamp. */
304  if (stream_index == -1)
305  while (idx > 0 && q->subs[idx - 1]->pts == q->subs[idx]->pts)
306  idx--;
307 
308  q->current_sub_idx = idx;
309  }
310  return 0;
311 }
312 
314 {
315  int i;
316 
317  for (i = 0; i < q->nb_subs; i++)
318  av_packet_free(&q->subs[i]);
319  av_freep(&q->subs);
320  q->nb_subs = q->allocated_size = q->current_sub_idx = 0;
321 }
322 
324 {
325  FFDemuxSubtitlesQueue *q = s->priv_data;
327 }
328 
329 int ff_subtitles_read_seek(AVFormatContext *s, int stream_index,
330  int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
331 {
332  FFDemuxSubtitlesQueue *q = s->priv_data;
333  return ff_subtitles_queue_seek(q, s, stream_index,
334  min_ts, ts, max_ts, flags);
335 }
336 
338 {
339  FFDemuxSubtitlesQueue *q = s->priv_data;
341  return 0;
342 }
343 
344 int ff_smil_extract_next_text_chunk(FFTextReader *tr, AVBPrint *buf, char *c)
345 {
346  int i = 0;
347  char end_chr;
348 
349  if (!*c) // cached char?
350  *c = ff_text_r8(tr);
351  if (!*c)
352  return 0;
353 
354  end_chr = *c == '<' ? '>' : '<';
355  do {
356  av_bprint_chars(buf, *c, 1);
357  *c = ff_text_r8(tr);
358  if (i == INT_MAX)
359  return AVERROR_INVALIDDATA;
360  i++;
361  } while (*c != end_chr && *c);
362  if (end_chr == '>') {
363  av_bprint_chars(buf, '>', 1);
364  *c = 0;
365  }
366  return av_bprint_is_complete(buf) ? i : AVERROR(ENOMEM);
367 }
368 
369 const char *ff_smil_get_attr_ptr(const char *s, const char *attr)
370 {
371  int in_quotes = 0;
372  const size_t len = strlen(attr);
373 
374  while (*s) {
375  while (*s) {
376  if (!in_quotes && av_isspace(*s))
377  break;
378  in_quotes ^= *s == '"'; // XXX: support escaping?
379  s++;
380  }
381  while (av_isspace(*s))
382  s++;
383  if (!av_strncasecmp(s, attr, len) && s[len] == '=')
384  return s + len + 1 + (s[len + 1] == '"');
385  }
386  return NULL;
387 }
388 
389 static inline int is_eol(char c)
390 {
391  return c == '\r' || c == '\n';
392 }
393 
395 {
396  char eol_buf[5], last_was_cr = 0;
397  int n = 0, i = 0, nb_eol = 0;
398 
399  av_bprint_clear(buf);
400 
401  for (;;) {
402  char c = ff_text_r8(tr);
403 
404  if (!c)
405  break;
406 
407  /* ignore all initial line breaks */
408  if (n == 0 && is_eol(c))
409  continue;
410 
411  /* line break buffering: we don't want to add the trailing \r\n */
412  if (is_eol(c)) {
413  nb_eol += c == '\n' || last_was_cr;
414  if (nb_eol == 2)
415  break;
416  eol_buf[i++] = c;
417  if (i == sizeof(eol_buf) - 1)
418  break;
419  last_was_cr = c == '\r';
420  continue;
421  }
422 
423  /* only one line break followed by data: we flush the line breaks
424  * buffer */
425  if (i) {
426  eol_buf[i] = 0;
427  av_bprintf(buf, "%s", eol_buf);
428  i = nb_eol = 0;
429  }
430 
431  av_bprint_chars(buf, c, 1);
432  n++;
433  }
434  return av_bprint_is_complete(buf) ? 0 : AVERROR(ENOMEM);
435 }
436 
437 int ff_subtitles_read_chunk(AVIOContext *pb, AVBPrint *buf)
438 {
439  FFTextReader tr;
440  tr.buf_pos = tr.buf_len = 0;
441  tr.type = 0;
442  tr.pb = pb;
443  return ff_subtitles_read_text_chunk(&tr, buf);
444 }
445 
446 ptrdiff_t ff_subtitles_read_line(FFTextReader *tr, char *buf, size_t size)
447 {
448  size_t cur = 0;
449  if (!size)
450  return 0;
451  buf[0] = '\0';
452  while (cur + 1 < size) {
453  unsigned char c = ff_text_r8(tr);
454  if (!c)
455  return ff_text_eof(tr) ? cur : AVERROR_INVALIDDATA;
456  if (c == '\r' || c == '\n')
457  break;
458  buf[cur++] = c;
459  buf[cur] = '\0';
460  }
461  while (ff_text_peek_r8(tr) == '\r')
462  ff_text_r8(tr);
463  if (ff_text_peek_r8(tr) == '\n')
464  ff_text_r8(tr);
465  return cur;
466 }
ff_subtitles_read_close
int ff_subtitles_read_close(AVFormatContext *s)
Definition: subtitles.c:337
is_eol
static int is_eol(char c)
Definition: subtitles.c:389
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
ff_text_r8
int ff_text_r8(FFTextReader *r)
Return the next byte.
Definition: subtitles.c:63
PUT_UTF8
#define PUT_UTF8(val, tmp, PUT_BYTE)
Definition: common.h:523
av_bprint_is_complete
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
Definition: bprint.h:218
r
const char * r
Definition: vf_curves.c:126
AVERROR
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
ff_smil_extract_next_text_chunk
int ff_smil_extract_next_text_chunk(FFTextReader *tr, AVBPrint *buf, char *c)
SMIL helper to load next chunk ("<...>" or untagged content) in buf.
Definition: subtitles.c:344
FFTextReader::buf_pos
int buf_pos
Definition: subtitles.h:45
AVSEEK_FLAG_FRAME
#define AVSEEK_FLAG_FRAME
seeking based on frame number
Definition: avformat.h:2227
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
FFDemuxSubtitlesQueue::nb_subs
int nb_subs
number of subtitles packets
Definition: subtitles.h:105
av_grow_packet
int av_grow_packet(AVPacket *pkt, int grow_by)
Increase packet size, correctly zeroing padding.
Definition: avpacket.c:121
FFTextReader::type
int type
Definition: subtitles.h:42
av_isspace
static av_const int av_isspace(int c)
Locale-independent conversion of ASCII isspace.
Definition: avstring.h:218
merge
static void merge(GetBitContext *gb, uint8_t *dst, uint8_t *src, int size)
Merge two consequent lists of equal size depending on bits read.
Definition: bink.c:221
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
ff_subtitles_read_text_chunk
int ff_subtitles_read_text_chunk(FFTextReader *tr, AVBPrint *buf)
Read a subtitles chunk from FFTextReader.
Definition: subtitles.c:394
AVPacket::data
uint8_t * data
Definition: packet.h:491
b
#define b
Definition: input.c:41
FFDemuxSubtitlesQueue::keep_duplicates
int keep_duplicates
set to 1 to keep duplicated subtitle events
Definition: subtitles.h:109
AVSEEK_FLAG_BYTE
#define AVSEEK_FLAG_BYTE
seeking based on position in bytes
Definition: avformat.h:2225
AVPacket::duration
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: packet.h:509
FF_UTF16LE
@ FF_UTF16LE
Definition: subtitles.h:37
FFTextReader
Definition: subtitles.h:41
ffio_init_read_context
void ffio_init_read_context(FFIOContext *s, const uint8_t *buffer, int buffer_size)
Wrap a buffer in an AVIOContext for reading.
Definition: aviobuf.c:134
ff_subtitles_read_line
ptrdiff_t ff_subtitles_read_line(FFTextReader *tr, char *buf, size_t size)
Read a line of text.
Definition: subtitles.c:446
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:546
av_packet_free
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Definition: avpacket.c:74
ff_subtitles_read_chunk
int ff_subtitles_read_chunk(AVIOContext *pb, AVBPrint *buf)
Same as ff_subtitles_read_text_chunk(), but read from an AVIOContext.
Definition: subtitles.c:437
FFDemuxSubtitlesQueue::current_sub_idx
int current_sub_idx
current position for the read packet callback
Definition: subtitles.h:107
cmp_pkt_sub_ts_pos
static int cmp_pkt_sub_ts_pos(const void *a, const void *b)
Definition: subtitles.c:156
avio_tell
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:513
val
static double val(void *priv, double ch)
Definition: aeval.c:78
pts
static int64_t pts
Definition: transcode_aac.c:643
avio_rl16
unsigned int avio_rl16(AVIOContext *s)
Definition: aviobuf.c:761
FFDIFFSIGN
#define FFDIFFSIGN(x, y)
Comparator.
Definition: macros.h:45
ff_subtitles_queue_seek
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.
Definition: subtitles.c:261
pkt
AVPacket * pkt
Definition: movenc.c:59
ff_subtitles_read_packet
int ff_subtitles_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: subtitles.c:323
av_fast_realloc
void * av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
Reallocate the given buffer if it is not large enough, otherwise do nothing.
Definition: mem.c:495
s
#define s(width, name)
Definition: cbs_vp9.c:198
av_new_packet
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition: avpacket.c:98
s1
#define s1
Definition: regdef.h:38
FFTextReader::pb
AVIOContext * pb
Definition: subtitles.h:43
ff_subtitles_queue_read_packet
int ff_subtitles_queue_read_packet(FFDemuxSubtitlesQueue *q, AVPacket *pkt)
Generic read_packet() callback for subtitles demuxers using this queue system.
Definition: subtitles.c:222
AVFormatContext
Format I/O context.
Definition: avformat.h:1115
ff_text_read
void ff_text_read(FFTextReader *r, char *buf, size_t size)
Read the given number of bytes (in UTF-8).
Definition: subtitles.c:84
NULL
#define NULL
Definition: coverity.c:32
av_packet_ref
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
Definition: avpacket.c:431
ff_subtitles_queue_insert
AVPacket * ff_subtitles_queue_insert(FFDemuxSubtitlesQueue *q, const uint8_t *event, size_t len, int merge)
Insert a new subtitle event.
Definition: subtitles.c:109
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
ff_text_init_avio
void ff_text_init_avio(void *s, FFTextReader *r, AVIOContext *pb)
Initialize the FFTextReader from the given AVIOContext.
Definition: subtitles.c:26
av_strncasecmp
int av_strncasecmp(const char *a, const char *b, size_t n)
Locale-independent case-insensitive compare.
Definition: avstring.c:217
s2
#define s2
Definition: regdef.h:39
AVIOContext
Bytestream IO Context.
Definition: avio.h:166
AVPacket::size
int size
Definition: packet.h:492
size
int size
Definition: twinvq_data.h:10344
ff_subtitles_queue_finalize
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.
Definition: subtitles.c:204
FFDemuxSubtitlesQueue
Definition: subtitles.h:103
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:490
avio_r8
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:650
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
ff_subtitles_queue_clean
void ff_subtitles_queue_clean(FFDemuxSubtitlesQueue *q)
Remove and destroy all the subtitles packets.
Definition: subtitles.c:313
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:497
av_packet_alloc
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition: avpacket.c:63
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
FF_UTF16BE
@ FF_UTF16BE
Definition: subtitles.h:38
ff_subtitles_queue_insert_bprint
AVPacket * ff_subtitles_queue_insert_bprint(FFDemuxSubtitlesQueue *q, const AVBPrint *event, int merge)
Same as ff_subtitles_queue_insert but takes an AVBPrint input.
Definition: subtitles.c:148
drop_dups
static void drop_dups(void *log_ctx, FFDemuxSubtitlesQueue *q)
Definition: subtitles.c:177
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:484
FFDemuxSubtitlesQueue::subs
AVPacket ** subs
array of subtitles packets
Definition: subtitles.h:104
avio_internal.h
SUB_SORT_TS_POS
@ SUB_SORT_TS_POS
sort by timestamps, then position
Definition: subtitles.h:31
ff_text_pos
int64_t ff_text_pos(FFTextReader *r)
Return the byte position of the next byte returned by ff_text_r8().
Definition: subtitles.c:58
ff_subtitles_read_seek
int ff_subtitles_read_seek(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
Definition: subtitles.c:329
GET_UTF16
#define GET_UTF16(val, GET_16BIT, ERROR)
Convert a UTF-16 character (2 or 4 bytes) to its 32-bit UCS-4 encoded form.
Definition: common.h:495
len
int len
Definition: vorbis_enc_data.h:426
ret
ret
Definition: filter_design.txt:187
avio_rb16
unsigned int avio_rb16(AVIOContext *s)
Definition: aviobuf.c:793
avformat.h
av_bprintf
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition: bprint.c:99
ff_text_peek_r8
int ff_text_peek_r8(FFTextReader *r)
Like ff_text_r8(), but don't remove the byte from the buffer.
Definition: subtitles.c:95
subtitles.h
search_sub_ts
static int search_sub_ts(const FFDemuxSubtitlesQueue *q, int64_t ts)
Definition: subtitles.c:239
av_bprint_clear
void av_bprint_clear(AVBPrint *buf)
Reset the string to "" but keep internal allocated data.
Definition: bprint.c:232
ff_text_init_buf
void ff_text_init_buf(FFTextReader *r, const void *buf, size_t size)
Similar to ff_text_init_avio(), but sets it up to read from a bounded buffer.
Definition: subtitles.c:52
AVPacket::stream_index
int stream_index
Definition: packet.h:493
FFTextReader::buf_len
int buf_len
Definition: subtitles.h:45
FF_UTF_8
@ FF_UTF_8
Definition: subtitles.h:36
ff_text_eof
int ff_text_eof(FFTextReader *r)
Return non-zero if EOF was reached.
Definition: subtitles.c:90
AVPacket
This structure stores compressed data.
Definition: packet.h:468
FFDemuxSubtitlesQueue::allocated_size
int allocated_size
allocated size for subs
Definition: subtitles.h:106
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:474
FFDemuxSubtitlesQueue::sort
enum sub_sort sort
sort method to use when finalizing subtitles
Definition: subtitles.h:108
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
cmp_pkt_sub_pos_ts
static int cmp_pkt_sub_pos_ts(const void *a, const void *b)
Definition: subtitles.c:165
av_bprint_chars
void av_bprint_chars(AVBPrint *buf, char c, unsigned n)
Append char c n times to a print buffer.
Definition: bprint.c:145
avstring.h
ff_smil_get_attr_ptr
const char * ff_smil_get_attr_ptr(const char *s, const char *attr)
SMIL helper to point on the value of an attribute in the given tag.
Definition: subtitles.c:369
avio_feof
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Definition: aviobuf.c:393