Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2014
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.50 KB | None | 0 0
  1. 0a1,21
  2. > /*
  3. > * SubRip subtitle demuxer
  4. > * Copyright (c) 2010 Aurelien Jacobs <aurel@gnuage.org>
  5. > *
  6. > * This file is part of FFmpeg.
  7. > *
  8. > * FFmpeg is free software; you can redistribute it and/or
  9. > * modify it under the terms of the GNU Lesser General Public
  10. > * License as published by the Free Software Foundation; either
  11. > * version 2.1 of the License, or (at your option) any later version.
  12. > *
  13. > * FFmpeg is distributed in the hope that it will be useful,
  14. > * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. > * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. > * Lesser General Public License for more details.
  17. > *
  18. > * You should have received a copy of the GNU Lesser General Public
  19. > * License along with FFmpeg; if not, write to the Free Software
  20. > * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. > */
  22. >
  23. 9c30
  24. < } STLContext;
  25. ---
  26. > } SRTContext;
  27. 11c32
  28. < static int stl_probe(AVProbeData *p)
  29. ---
  30. > static int srt_probe(AVProbeData *p)
  31. 13,15c34,53
  32. < char c;
  33. < const unsigned char *ptr = p->buf;
  34. < if (sscanf(ptr, "%*d:%*d:%*d:%*d , %*d:%*d:%*d:%*d ,", &c) == 1)
  35. ---
  36. > int v;
  37. > char buf[64], *pbuf;
  38. > FFTextReader tr;
  39. >
  40. > ff_text_init_buf(&tr, p->buf, p->buf_size);
  41. >
  42. > while (ff_text_peek_r8(&tr) == '\r' || ff_text_peek_r8(&tr) == '\n')
  43. > ff_text_r8(&tr);
  44. >
  45. > /* Check if the first non-empty line is a number. We do not check what the
  46. > * number is because in practice it can be anything. */
  47. > if (ff_subtitles_read_line(&tr, buf, sizeof(buf)) < 0 ||
  48. > strtol(buf, &pbuf, 10) < 0 || *pbuf)
  49. > return 0;
  50. >
  51. > /* Check if the next line matches a SRT timestamp */
  52. > if (ff_subtitles_read_line(&tr, buf, sizeof(buf)) < 0)
  53. > return 0;
  54. > if (buf[0] >= '0' && buf[1] <= '9' && strstr(buf, " --> ")
  55. > && sscanf(buf, "%*d:%*2d:%*2d%*1[,.]%*3d --> %*d:%*2d:%*2d%*1[,.]%3d", &v) == 1)
  56. 16a55
  57. >
  58. 18a58
  59. >
  60. 21a62,64
  61. > int i;
  62. >
  63. > for (i=0; i<2; i++) {
  64. 24c67,68
  65. < if (sscanf(*buf, "%2d:%2d:%2d:%2d , %2d:%2d:%2d:%2d , ",
  66. ---
  67. > if (sscanf(*buf, "%d:%2d:%2d%*1[,.]%3d --> %d:%2d:%2d%*1[,.]%3d"
  68. > "%*[ ]X1:%u X2:%u Y1:%u Y2:%u",
  69. 26,28c70,73
  70. < &hh2, &mm2, &ss2, &ms2) >= 6) {
  71. < int64_t start = (hh1*3600LL + mm1*60LL + ss1) * 100LL + ms1;
  72. < int64_t end = (hh2*3600LL + mm2*60LL + ss2) * 100LL + ms2;
  73. ---
  74. > &hh2, &mm2, &ss2, &ms2,
  75. > x1, x2, y1, y2) >= 8) {
  76. > int64_t start = (hh1*3600LL + mm1*60LL + ss1) * 1000LL + ms1;
  77. > int64_t end = (hh2*3600LL + mm2*60LL + ss2) * 1000LL + ms2;
  78. 34c79
  79. <
  80. ---
  81. > }
  82. 38c83
  83. < static int stl_read_header(AVFormatContext *s)
  84. ---
  85. > static int srt_read_header(AVFormatContext *s)
  86. 40c85
  87. < STLContext *stl = s->priv_data;
  88. ---
  89. > SRTContext *srt = s->priv_data;
  90. 49c94
  91. < avpriv_set_pts_info(st, 64, 1, 100);
  92. ---
  93. > avpriv_set_pts_info(st, 64, 1, 1000);
  94. 51c96
  95. < st->codec->codec_id = AV_CODEC_ID_TEXT;
  96. ---
  97. > st->codec->codec_id = AV_CODEC_ID_SUBRIP;
  98. 71c116
  99. < sub = ff_subtitles_queue_insert(&stl->q, ptr, len, 0);
  100. ---
  101. > sub = ff_subtitles_queue_insert(&srt->q, ptr, len, 0);
  102. 92c137
  103. < ff_subtitles_queue_finalize(&stl->q);
  104. ---
  105. > ff_subtitles_queue_finalize(&srt->q);
  106. 99,140c144
  107. < /*static int stl_read_header(AVFormatContext *s)
  108. < {
  109. < STLContext *stl = s->priv_data;
  110. < AVStream *st = avformat_new_stream(s, NULL);
  111. <
  112. < if (!st)
  113. < return AVERROR(ENOMEM);
  114. < avpriv_set_pts_info(st, 64, 1, 100);
  115. < st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;
  116. < st->codec->codec_id = AV_CODEC_ID_TEXT;
  117. <
  118. < while (!avio_feof(s->pb)) {
  119. < char line[4096];
  120. < char *p = line;
  121. <
  122. < const int64_t pos = avio_tell(s->pb);
  123. < int len = ff_get_line(s->pb, line, sizeof(line));
  124. < int64_t pts_start;
  125. <
  126. < if (!len)
  127. < break;
  128. <
  129. < line[strcspn(line, "\r\n")] = 0;
  130. <
  131. < pts_start = read_ts(&p);
  132. < if (pts_start != AV_NOPTS_VALUE) {
  133. < AVPacket *sub;
  134. <
  135. < sub = ff_subtitles_queue_insert(&stl->q, p, strlen(p), 0);
  136. < if (!sub)
  137. < return AVERROR(ENOMEM);
  138. < sub->pos = pos;
  139. < sub->pts = pts_start;
  140. < sub->duration = -1;
  141. < }
  142. < }
  143. <
  144. < ff_subtitles_queue_finalize(&stl->q);
  145. < return 0;
  146. < }
  147. < */
  148. < static int stl_read_packet(AVFormatContext *s, AVPacket *pkt)
  149. ---
  150. > static int srt_read_packet(AVFormatContext *s, AVPacket *pkt)
  151. 142,143c146,147
  152. < STLContext *stl = s->priv_data;
  153. < return ff_subtitles_queue_read_packet(&stl->q, pkt);
  154. ---
  155. > SRTContext *srt = s->priv_data;
  156. > return ff_subtitles_queue_read_packet(&srt->q, pkt);
  157. 146,147c150,151
  158. < static int stl_read_seek(AVFormatContext *s, int stream_index,
  159. < int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
  160. ---
  161. > static int srt_read_seek(AVFormatContext *s, int stream_index,
  162. > int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
  163. 149,150c153,154
  164. < STLContext *stl = s->priv_data;
  165. < return ff_subtitles_queue_seek(&stl->q, s, stream_index,
  166. ---
  167. > SRTContext *srt = s->priv_data;
  168. > return ff_subtitles_queue_seek(&srt->q, s, stream_index,
  169. 154c158
  170. < static int stl_read_close(AVFormatContext *s)
  171. ---
  172. > static int srt_read_close(AVFormatContext *s)
  173. 156,157c160,161
  174. < STLContext *stl = s->priv_data;
  175. < ff_subtitles_queue_clean(&stl->q);
  176. ---
  177. > SRTContext *srt = s->priv_data;
  178. > ff_subtitles_queue_clean(&srt->q);
  179. 161,170c165,173
  180. < AVInputFormat ff_stl_demuxer = {
  181. < .name = "stl",
  182. < .long_name = NULL_IF_CONFIG_SMALL("STL subtitles"),
  183. < .priv_data_size = sizeof(STLContext),
  184. < .read_probe = stl_probe,
  185. < .read_header = stl_read_header,
  186. < .read_packet = stl_read_packet,
  187. < .read_seek2 = stl_read_seek,
  188. < .read_close = stl_read_close,
  189. < .extensions = "stl",
  190. ---
  191. > AVInputFormat ff_srt_demuxer = {
  192. > .name = "srt",
  193. > .long_name = NULL_IF_CONFIG_SMALL("SubRip subtitle"),
  194. > .priv_data_size = sizeof(SRTContext),
  195. > .read_probe = srt_probe,
  196. > .read_header = srt_read_header,
  197. > .read_packet = srt_read_packet,
  198. > .read_seek2 = srt_read_seek,
  199. > .read_close = srt_read_close,
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement