Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- commit e5e0d243546e29a24326e7aa15bd9a34a82fae37
- Author: Eejya Singh <[email protected]>
- Date: Wed Jan 21 21:49:27 2015 +0530
- Adding enhanced features to WebVTT encoder
- diff --git a/libavcodec/webvttenc.c b/libavcodec/webvttenc.c
- index 9f67a2e..b05f363 100644
- --- a/libavcodec/webvttenc.c
- +++ b/libavcodec/webvttenc.c
- @@ -119,6 +119,35 @@ static void webvtt_new_line_cb(void *priv, int forced)
- {
- webvtt_print(priv, "\n");
- }
- +static void webvtt_color_cb(void *priv, unsigned int color, unsigned int color_id)
- +{
- + WebVTTContext *s = priv;
- + if (color_id > 1)
- + return;
- +
- + else
- + {
- + // webvtt_stack_push_pop(priv, 'f', (color&0xffffff) == 0xFFFFFF);
- + if ((color&0xffffff) != 0xFFFFFF)
- + {
- + /* map all levels to one level */
- + if(!(color&0xffff00) && (color&0xff))
- + webvtt_print(priv, "<c.red>");
- + else if(!(color&0xff00) && (color&0xff) && (color&0xff0000))
- + webvtt_print(priv, "<c.magenta>");
- + else if(!(color&0xff00ff) && (color&0xff00))
- + webvtt_print(priv, "<c.green>");
- + else if(!(color&0xff) && (color&0xff00) && (color&0xff0000))
- + webvtt_print(priv, "<c.cyan>");
- + else if(!(color&0xffff) && (color&0xff0000))
- + webvtt_print(priv, "<c.blue>");
- + else
- + webvtt_print(priv, "<c.yellow>"); // all other colors to yellow
- + webvtt_stack_push(s,'c');
- +
- + }
- + }
- +}
- static void webvtt_style_cb(void *priv, char style, int close)
- {
- @@ -141,16 +170,96 @@ static void webvtt_end_cb(void *priv)
- webvtt_stack_push_pop(priv, 0, 1);
- }
- +static void webvtt_alignment_cb(void *priv, int alignment)
- +{
- + int x=35,y=70;
- + char buffer[32];
- + int len;
- +
- + if(alignment > 3) y=5;
- + if(alignment == 1 || alignment == 4 || alignment == 7) x= 5;
- + else if(!(alignment%3)) x=65;
- +
- + if(x == 35 && y==5) len = snprintf(buffer, sizeof(buffer),
- + " line:1");
- + else if(y == 70)
- + {
- + if(x == 5)
- + len = snprintf(buffer, sizeof(buffer),
- + " align:start");
- + else if (x == 65)
- + len = snprintf(buffer, sizeof(buffer),
- + " align:end");
- + }
- + else
- + {
- + if(x == 5)
- + len = snprintf(buffer, sizeof(buffer),
- + " line:1 align:start");
- + else len = snprintf(buffer, sizeof(buffer),
- + " line:1 align:end");
- + }
- +
- +}
- +static void webvtt_move_cb(void *priv, int x1, int y1, int x2, int y2,
- + int t1, int t2)
- +{
- + WebVTTContext *s = priv;
- + char buffer[32];
- + int len;
- + if (x1 > 320 || x1 < 100 || y1 < 280)
- + {
- + int x,y,w=0,h;
- + if(x2 > x1)
- + {
- + w = x2 - x1;
- + h = y2 - y1;
- + }
- + x=35,y=70;
- + if(w < 1)
- + {
- + w=160;
- + h=96;
- + }
- + w *= 100;
- + w /= 704;
- + h *= 100;
- + h /= 480;
- +
- + if(x1 < 100) x=5;
- + else if (x1 > 320) x=65;
- + if(y1 < 280) y=5;
- +
- + if(w > 0) len = snprintf(buffer, sizeof(buffer),
- + " position:%u%% line:%u%% size:%u%%", x, y, w);
- + else len = snprintf(buffer, sizeof(buffer),
- + " position:%u%% line:%u%%", x, y);
- +
- + unsigned char *dummy;
- + unsigned room;
- +
- + av_bprint_get_buffer(&s->buffer, len, &dummy, &room);
- + if (room >= len) {
- + memmove(s->buffer.str + s->timestamp_end + len,
- + s->buffer.str + s->timestamp_end,
- + s->buffer.len - s->timestamp_end + 1);
- + memcpy(s->buffer.str + s->timestamp_end, buffer, len);
- + }
- + /* Increment even if av_bprint_get_buffer() did not return enough room:
- + the bprint structure will be treated as truncated. */
- + s->buffer.len += len;
- + }
- +}
- static const ASSCodesCallbacks webvtt_callbacks = {
- .text = webvtt_text_cb,
- .new_line = webvtt_new_line_cb,
- .style = webvtt_style_cb,
- - .color = NULL,
- + .color = webvtt_color_cb,
- .font_name = NULL,
- .font_size = NULL,
- - .alignment = NULL,
- + .alignment = webvtt_alignment_cb,
- .cancel_overrides = webvtt_cancel_overrides_cb,
- - .move = NULL,
- + .move = webvtt_move_cb,
- .end = webvtt_end_cb,
- };
Advertisement
Add Comment
Please, Sign In to add comment