MCPcopy Create free account
hub / github.com/byhook/ffmpeg4android / transcode_subtitles

Function transcode_subtitles

ffmpeg-single-cmd/src/main/cpp/ffmpeg_mod.c:2502–2577  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2500}
2501
2502static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output,
2503 int *decode_failed)
2504{
2505 AVSubtitle subtitle;
2506 int free_sub = 1;
2507 int i, ret = avcodec_decode_subtitle2(ist->dec_ctx,
2508 &subtitle, got_output, pkt);
2509
2510 check_decode_result(NULL, got_output, ret);
2511
2512 if (ret < 0 || !*got_output) {
2513 *decode_failed = 1;
2514 if (!pkt->size)
2515 sub2video_flush(ist);
2516 return ret;
2517 }
2518
2519 if (ist->fix_sub_duration) {
2520 int end = 1;
2521 if (ist->prev_sub.got_output) {
2522 end = av_rescale(subtitle.pts - ist->prev_sub.subtitle.pts,
2523 1000, AV_TIME_BASE);
2524 if (end < ist->prev_sub.subtitle.end_display_time) {
2525 av_log(ist->dec_ctx, AV_LOG_DEBUG,
2526 "Subtitle duration reduced from %"PRId32" to %d%s\n",
2527 ist->prev_sub.subtitle.end_display_time, end,
2528 end <= 0 ? ", dropping it" : "");
2529 ist->prev_sub.subtitle.end_display_time = end;
2530 }
2531 }
2532 FFSWAP(int, *got_output, ist->prev_sub.got_output);
2533 FFSWAP(int, ret, ist->prev_sub.ret);
2534 FFSWAP(AVSubtitle, subtitle, ist->prev_sub.subtitle);
2535 if (end <= 0)
2536 goto out;
2537 }
2538
2539 if (!*got_output)
2540 return ret;
2541
2542 if (ist->sub2video.frame) {
2543 sub2video_update(ist, &subtitle);
2544 } else if (ist->nb_filters) {
2545 if (!ist->sub2video.sub_queue)
2546 ist->sub2video.sub_queue = av_fifo_alloc(8 * sizeof(AVSubtitle));
2547 if (!ist->sub2video.sub_queue)
2548 exit_program(1);
2549 if (!av_fifo_space(ist->sub2video.sub_queue)) {
2550 ret = av_fifo_realloc2(ist->sub2video.sub_queue, 2 * av_fifo_size(ist->sub2video.sub_queue));
2551 if (ret < 0)
2552 exit_program(1);
2553 }
2554 av_fifo_generic_write(ist->sub2video.sub_queue, &subtitle, sizeof(subtitle), NULL);
2555 free_sub = 0;
2556 }
2557
2558 if (!subtitle.num_rects)
2559 goto out;

Callers 1

process_input_packetFunction · 0.85

Calls 6

check_decode_resultFunction · 0.85
sub2video_flushFunction · 0.85
sub2video_updateFunction · 0.85
exit_programFunction · 0.85
check_output_constraintsFunction · 0.85
do_subtitle_outFunction · 0.85

Tested by

no test coverage detected