summaryrefslogtreecommitdiff
path: root/src/internal
diff options
context:
space:
mode:
authorTuomas Virtanen <katajakasa@gmail.com>2018-09-29 15:59:27 +0300
committerTuomas Virtanen <katajakasa@gmail.com>2018-09-29 15:59:27 +0300
commit1f1e88d1da59361ed3aa42549a6ed67c6cd11727 (patch)
tree8c7fe3946ad230abd82f5445350c89cb99f7c3b7 /src/internal
parent66fb5c295f89b6061585436e1411490393c5137a (diff)
Use newer ass_render_chunk() API
Diffstat (limited to 'src/internal')
-rw-r--r--src/internal/kitdecoder.c9
-rw-r--r--src/internal/subtitle/kitsubtitle.c6
-rw-r--r--src/internal/subtitle/renderers/kitsubass.c19
-rw-r--r--src/internal/subtitle/renderers/kitsubimage.c4
-rw-r--r--src/internal/subtitle/renderers/kitsubrenderer.c4
5 files changed, 33 insertions, 9 deletions
diff --git a/src/internal/kitdecoder.c b/src/internal/kitdecoder.c
index 0855eee..f4deaca 100644
--- a/src/internal/kitdecoder.c
+++ b/src/internal/kitdecoder.c
@@ -20,6 +20,7 @@ Kit_Decoder* Kit_CreateDecoder(const Kit_Source *src, int stream_index,
assert(thread_count > 0);
AVCodecContext *codec_ctx = NULL;
+ AVDictionary *codec_opts = NULL;
AVCodec *codec = NULL;
AVFormatContext *format_ctx = src->format_ctx;
int bsizes[2] = {BUFFER_IN_SIZE, out_b_size};
@@ -62,8 +63,13 @@ Kit_Decoder* Kit_CreateDecoder(const Kit_Source *src, int stream_index,
codec_ctx->thread_count = thread_count;
codec_ctx->thread_type = FF_THREAD_SLICE;
+ // This is required for ass_process_chunk() support
+ if(LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 25, 100)) {
+ av_dict_set(&codec_opts, "sub_text_format", "ass", 0);
+ }
+
// Open the stream
- if(avcodec_open2(codec_ctx, codec, NULL) < 0) {
+ if(avcodec_open2(codec_ctx, codec, &codec_opts) < 0) {
Kit_SetError("Unable to open codec for stream %d", stream_index);
goto exit_2;
}
@@ -98,6 +104,7 @@ exit_3:
}
avcodec_close(codec_ctx);
exit_2:
+ av_dict_free(&codec_opts);
avcodec_free_context(&codec_ctx);
exit_1:
free(dec);
diff --git a/src/internal/subtitle/kitsubtitle.c b/src/internal/subtitle/kitsubtitle.c
index d6bed5d..417b338 100644
--- a/src/internal/subtitle/kitsubtitle.c
+++ b/src/internal/subtitle/kitsubtitle.c
@@ -59,12 +59,12 @@ static void dec_decode_subtitle_cb(Kit_Decoder *dec, AVPacket *in_packet) {
subtitle_dec->scratch_frame.end_display_time = 30000;
}
- start = pts + subtitle_dec->scratch_frame.start_display_time / 1000.0F;
- end = pts + subtitle_dec->scratch_frame.end_display_time / 1000.0F;
+ start = subtitle_dec->scratch_frame.start_display_time / 1000.0F;
+ end = subtitle_dec->scratch_frame.end_display_time / 1000.0F;
// Create a packet. This should be filled by renderer.
Kit_RunSubtitleRenderer(
- subtitle_dec->renderer, &subtitle_dec->scratch_frame, start, end);
+ subtitle_dec->renderer, &subtitle_dec->scratch_frame, pts, start, end);
// Free subtitle since it has now been handled
avsubtitle_free(&subtitle_dec->scratch_frame);
diff --git a/src/internal/subtitle/renderers/kitsubass.c b/src/internal/subtitle/renderers/kitsubass.c
index 7db72dd..88159d9 100644
--- a/src/internal/subtitle/renderers/kitsubass.c
+++ b/src/internal/subtitle/renderers/kitsubass.c
@@ -40,7 +40,7 @@ static void Kit_ProcessAssImage(SDL_Surface *surface, const ASS_Image *img) {
}
}
-static void ren_render_ass_cb(Kit_SubtitleRenderer *ren, void *src, double start_pts, double end_pts) {
+static void ren_render_ass_cb(Kit_SubtitleRenderer *ren, void *src, double pts, double start, double end) {
assert(ren != NULL);
assert(src != NULL);
@@ -48,11 +48,26 @@ static void ren_render_ass_cb(Kit_SubtitleRenderer *ren, void *src, double start
AVSubtitle *sub = src;
// Read incoming subtitle packets to libASS
+ long long start_ms = (start + pts) * 1000;
+ long long end_ms = end * 1000;
if(Kit_LockDecoderOutput(ren->dec) == 0) {
for(int r = 0; r < sub->num_rects; r++) {
if(sub->rects[r]->ass == NULL)
continue;
- ass_process_data(ass_ren->track, sub->rects[r]->ass, strlen(sub->rects[r]->ass));
+ if(LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57,25,100)) {
+ ass_process_data(
+ ass_ren->track,
+ sub->rects[r]->ass,
+ strlen(sub->rects[r]->ass));
+ } else {
+ // This requires the sub_text_format codec_opt set for ffmpeg
+ ass_process_chunk(
+ ass_ren->track,
+ sub->rects[r]->ass,
+ strlen(sub->rects[r]->ass),
+ start_ms,
+ end_ms);
+ }
}
Kit_UnlockDecoderOutput(ren->dec);
}
diff --git a/src/internal/subtitle/renderers/kitsubimage.c b/src/internal/subtitle/renderers/kitsubimage.c
index 0cd0cce..b9a8e48 100644
--- a/src/internal/subtitle/renderers/kitsubimage.c
+++ b/src/internal/subtitle/renderers/kitsubimage.c
@@ -17,13 +17,15 @@ typedef struct Kit_ImageSubtitleRenderer {
float scale_y;
} Kit_ImageSubtitleRenderer;
-static void ren_render_image_cb(Kit_SubtitleRenderer *ren, void *sub_src, double start_pts, double end_pts) {
+static void ren_render_image_cb(Kit_SubtitleRenderer *ren, void *sub_src, double pts, double start, double end) {
assert(ren != NULL);
assert(sub_src != NULL);
AVSubtitle *sub = sub_src;
SDL_Surface *dst = NULL;
SDL_Surface *src = NULL;
+ double start_pts = pts + start;
+ double end_pts = pts + end;
// If this subtitle has no rects, we still need to clear screen from old subs
if(sub->num_rects == 0) {
diff --git a/src/internal/subtitle/renderers/kitsubrenderer.c b/src/internal/subtitle/renderers/kitsubrenderer.c
index 77ad201..d41d61d 100644
--- a/src/internal/subtitle/renderers/kitsubrenderer.c
+++ b/src/internal/subtitle/renderers/kitsubrenderer.c
@@ -17,11 +17,11 @@ Kit_SubtitleRenderer* Kit_CreateSubtitleRenderer(Kit_Decoder *dec) {
return ren;
}
-void Kit_RunSubtitleRenderer(Kit_SubtitleRenderer *ren, void *src, double start_pts, double end_pts) {
+void Kit_RunSubtitleRenderer(Kit_SubtitleRenderer *ren, void *src, double pts, double start, double end) {
if(ren == NULL)
return;
if(ren->ren_render != NULL)
- ren->ren_render(ren, src, start_pts, end_pts);
+ ren->ren_render(ren, src, pts, start, end);
}
int Kit_GetSubtitleRendererData(Kit_SubtitleRenderer *ren, Kit_TextureAtlas *atlas, SDL_Texture *texture, double current_pts) {