diff options
author | wm4 <wm4@nowhere> | 2013-06-01 19:44:55 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2013-06-03 02:09:07 +0200 |
commit | 3000df35d31f09f13a7c662e2f96bcd7d0f6ac13 (patch) | |
tree | 64ce19abc28e21cc9a17ed66045433de0342221b /sub/sd_movtext.c | |
parent | 02ce316ade9ba932ad405383278d6b01c54e5fc4 (diff) | |
download | mpv-3000df35d31f09f13a7c662e2f96bcd7d0f6ac13.tar.bz2 mpv-3000df35d31f09f13a7c662e2f96bcd7d0f6ac13.tar.xz |
sub: basic subtitle converters
Add a basic infrastructure for subtitle converters. These converters
work sort-of like decoders, except that they produce packets instead
of subtitle bitmaps. They are put in front of actual decoders.
Start with sd_movtext. 4 lines of code are blown up to a 55 lines file,
but fortunately this is not going to be that bad for the following
converters.
Diffstat (limited to 'sub/sd_movtext.c')
-rw-r--r-- | sub/sd_movtext.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/sub/sd_movtext.c b/sub/sd_movtext.c new file mode 100644 index 0000000000..30d2da8254 --- /dev/null +++ b/sub/sd_movtext.c @@ -0,0 +1,54 @@ +/* + * This file is part of mpv. + * + * mpv is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * mpv is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with mpv. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stdlib.h> +#include <assert.h> + +#include <libavutil/intreadwrite.h> +#include <libavutil/common.h> + +#include "sd.h" + +static bool supports_format(const char *format) +{ + return format && strcmp(format, "mov_text") == 0; +} + +static int init(struct sd *sd) +{ + sd->output_codec = "text"; + return 0; +} + +static void decode(struct sd *sd, struct demux_packet *packet) +{ + unsigned char *data = packet->buffer; + int len = packet->len; + if (len < 2) + return; + len = FFMIN(len - 2, AV_RB16(data)); + data += 2; + sd_conv_add_packet(sd, data, len, packet->pts, packet->duration); +} + +const struct sd_functions sd_movtext = { + .supports_format = supports_format, + .init = init, + .decode = decode, + .get_converted = sd_conv_def_get_converted, + .reset = sd_conv_def_reset, +}; |