Guest User

Untitled

a guest
Jan 22nd, 2015
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.72 KB | None | 0 0
  1. commit e5e0d243546e29a24326e7aa15bd9a34a82fae37
  2. Author: Eejya Singh <[email protected]>
  3. Date: Wed Jan 21 21:49:27 2015 +0530
  4.  
  5. Adding enhanced features to WebVTT encoder
  6.  
  7. diff --git a/libavcodec/webvttenc.c b/libavcodec/webvttenc.c
  8. index 9f67a2e..b05f363 100644
  9. --- a/libavcodec/webvttenc.c
  10. +++ b/libavcodec/webvttenc.c
  11. @@ -119,6 +119,35 @@ static void webvtt_new_line_cb(void *priv, int forced)
  12. {
  13. webvtt_print(priv, "\n");
  14. }
  15. +static void webvtt_color_cb(void *priv, unsigned int color, unsigned int color_id)
  16. +{
  17. + WebVTTContext *s = priv;
  18. + if (color_id > 1)
  19. + return;
  20. +
  21. + else
  22. + {
  23. + // webvtt_stack_push_pop(priv, 'f', (color&0xffffff) == 0xFFFFFF);
  24. + if ((color&0xffffff) != 0xFFFFFF)
  25. + {
  26. + /* map all levels to one level */
  27. + if(!(color&0xffff00) && (color&0xff))
  28. + webvtt_print(priv, "<c.red>");
  29. + else if(!(color&0xff00) && (color&0xff) && (color&0xff0000))
  30. + webvtt_print(priv, "<c.magenta>");
  31. + else if(!(color&0xff00ff) && (color&0xff00))
  32. + webvtt_print(priv, "<c.green>");
  33. + else if(!(color&0xff) && (color&0xff00) && (color&0xff0000))
  34. + webvtt_print(priv, "<c.cyan>");
  35. + else if(!(color&0xffff) && (color&0xff0000))
  36. + webvtt_print(priv, "<c.blue>");
  37. + else
  38. + webvtt_print(priv, "<c.yellow>"); // all other colors to yellow
  39. + webvtt_stack_push(s,'c');
  40. +
  41. + }
  42. + }
  43. +}
  44.  
  45. static void webvtt_style_cb(void *priv, char style, int close)
  46. {
  47. @@ -141,16 +170,96 @@ static void webvtt_end_cb(void *priv)
  48. webvtt_stack_push_pop(priv, 0, 1);
  49. }
  50.  
  51. +static void webvtt_alignment_cb(void *priv, int alignment)
  52. +{
  53. + int x=35,y=70;
  54. + char buffer[32];
  55. + int len;
  56. +
  57. + if(alignment > 3) y=5;
  58. + if(alignment == 1 || alignment == 4 || alignment == 7) x= 5;
  59. + else if(!(alignment%3)) x=65;
  60. +
  61. + if(x == 35 && y==5) len = snprintf(buffer, sizeof(buffer),
  62. + " line:1");
  63. + else if(y == 70)
  64. + {
  65. + if(x == 5)
  66. + len = snprintf(buffer, sizeof(buffer),
  67. + " align:start");
  68. + else if (x == 65)
  69. + len = snprintf(buffer, sizeof(buffer),
  70. + " align:end");
  71. + }
  72. + else
  73. + {
  74. + if(x == 5)
  75. + len = snprintf(buffer, sizeof(buffer),
  76. + " line:1 align:start");
  77. + else len = snprintf(buffer, sizeof(buffer),
  78. + " line:1 align:end");
  79. + }
  80. +
  81. +}
  82. +static void webvtt_move_cb(void *priv, int x1, int y1, int x2, int y2,
  83. + int t1, int t2)
  84. +{
  85. + WebVTTContext *s = priv;
  86. + char buffer[32];
  87. + int len;
  88. + if (x1 > 320 || x1 < 100 || y1 < 280)
  89. + {
  90. + int x,y,w=0,h;
  91. + if(x2 > x1)
  92. + {
  93. + w = x2 - x1;
  94. + h = y2 - y1;
  95. + }
  96. + x=35,y=70;
  97. + if(w < 1)
  98. + {
  99. + w=160;
  100. + h=96;
  101. + }
  102. + w *= 100;
  103. + w /= 704;
  104. + h *= 100;
  105. + h /= 480;
  106. +
  107. + if(x1 < 100) x=5;
  108. + else if (x1 > 320) x=65;
  109. + if(y1 < 280) y=5;
  110. +
  111. + if(w > 0) len = snprintf(buffer, sizeof(buffer),
  112. + " position:%u%% line:%u%% size:%u%%", x, y, w);
  113. + else len = snprintf(buffer, sizeof(buffer),
  114. + " position:%u%% line:%u%%", x, y);
  115. +
  116. + unsigned char *dummy;
  117. + unsigned room;
  118. +
  119. + av_bprint_get_buffer(&s->buffer, len, &dummy, &room);
  120. + if (room >= len) {
  121. + memmove(s->buffer.str + s->timestamp_end + len,
  122. + s->buffer.str + s->timestamp_end,
  123. + s->buffer.len - s->timestamp_end + 1);
  124. + memcpy(s->buffer.str + s->timestamp_end, buffer, len);
  125. + }
  126. + /* Increment even if av_bprint_get_buffer() did not return enough room:
  127. + the bprint structure will be treated as truncated. */
  128. + s->buffer.len += len;
  129. + }
  130. +}
  131. static const ASSCodesCallbacks webvtt_callbacks = {
  132. .text = webvtt_text_cb,
  133. .new_line = webvtt_new_line_cb,
  134. .style = webvtt_style_cb,
  135. - .color = NULL,
  136. + .color = webvtt_color_cb,
  137. .font_name = NULL,
  138. .font_size = NULL,
  139. - .alignment = NULL,
  140. + .alignment = webvtt_alignment_cb,
  141. .cancel_overrides = webvtt_cancel_overrides_cb,
  142. - .move = NULL,
  143. + .move = webvtt_move_cb,
  144. .end = webvtt_end_cb,
  145. };
Advertisement
Add Comment
Please, Sign In to add comment