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

Function do_subtitle_out

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

Source from the content-addressed store, hash-verified

951}
952
953static void do_subtitle_out(OutputFile *of,
954 OutputStream *ost,
955 AVSubtitle *sub)
956{
957 int subtitle_out_max_size = 1024 * 1024;
958 int subtitle_out_size, nb, i;
959 AVCodecContext *enc;
960 AVPacket pkt;
961 int64_t pts;
962
963 if (sub->pts == AV_NOPTS_VALUE) {
964 av_log(NULL, AV_LOG_ERROR, "Subtitle packets must have a pts\n");
965 if (exit_on_error)
966 exit_program(1);
967 return;
968 }
969
970 enc = ost->enc_ctx;
971
972 if (!subtitle_out) {
973 subtitle_out = av_malloc(subtitle_out_max_size);
974 if (!subtitle_out) {
975 av_log(NULL, AV_LOG_FATAL, "Failed to allocate subtitle_out\n");
976 exit_program(1);
977 }
978 }
979
980 /* Note: DVB subtitle need one packet to draw them and one other
981 packet to clear them */
982 /* XXX: signal it in the codec context ? */
983 if (enc->codec_id == AV_CODEC_ID_DVB_SUBTITLE)
984 nb = 2;
985 else
986 nb = 1;
987
988 /* shift timestamp to honor -ss and make check_recording_time() work with -t */
989 pts = sub->pts;
990 if (output_files[ost->file_index]->start_time != AV_NOPTS_VALUE)
991 pts -= output_files[ost->file_index]->start_time;
992 for (i = 0; i < nb; i++) {
993 unsigned save_num_rects = sub->num_rects;
994
995 ost->sync_opts = av_rescale_q(pts, AV_TIME_BASE_Q, enc->time_base);
996 if (!check_recording_time(ost))
997 return;
998
999 sub->pts = pts;
1000 // start_display_time is required to be 0
1001 sub->pts += av_rescale_q(sub->start_display_time, (AVRational){ 1, 1000 }, AV_TIME_BASE_Q);
1002 sub->end_display_time -= sub->start_display_time;
1003 sub->start_display_time = 0;
1004 if (i == 1)
1005 sub->num_rects = 0;
1006
1007 ost->frames_encoded++;
1008
1009 subtitle_out_size = avcodec_encode_subtitle(enc, subtitle_out,
1010 subtitle_out_max_size, sub);

Callers 1

transcode_subtitlesFunction · 0.85

Calls 3

exit_programFunction · 0.85
check_recording_timeFunction · 0.85
output_packetFunction · 0.85

Tested by

no test coverage detected