summaryrefslogtreecommitdiff
path: root/fftools
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2022-04-04 12:26:18 +0200
committerAnton Khirnov <anton@khirnov.net>2022-07-23 11:53:19 +0200
commit481b27e8503def47e10d8692d3adf3ef69a34dce (patch)
treedf5c41f890f78a548baee2c039a5e2fe9614ad6d /fftools
parentdceccd4aebe92179f748ab71e048a927968c5b5a (diff)
fftools/ffmpeg: use refcounted packets for encoded subtitles
Diffstat (limited to 'fftools')
-rw-r--r--fftools/ffmpeg.c25
1 files changed, 8 insertions, 17 deletions
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 92a83c4253..2118d5c857 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -140,8 +140,6 @@ unsigned nb_output_dumped = 0;
static BenchmarkTimeStamps current_time;
AVIOContext *progress_avio = NULL;
-static uint8_t *subtitle_out;
-
InputStream **input_streams = NULL;
int nb_input_streams = 0;
InputFile **input_files = NULL;
@@ -558,8 +556,6 @@ static void ffmpeg_cleanup(int ret)
}
av_freep(&filtergraphs);
- av_freep(&subtitle_out);
-
/* close files */
for (i = 0; i < nb_output_files; i++)
of_close(&output_files[i]);
@@ -997,7 +993,7 @@ static void do_subtitle_out(OutputFile *of,
AVSubtitle *sub)
{
int subtitle_out_max_size = 1024 * 1024;
- int subtitle_out_size, nb, i;
+ int subtitle_out_size, nb, i, ret;
AVCodecContext *enc;
AVPacket *pkt = ost->pkt;
int64_t pts;
@@ -1011,14 +1007,6 @@ static void do_subtitle_out(OutputFile *of,
enc = ost->enc_ctx;
- if (!subtitle_out) {
- subtitle_out = av_malloc(subtitle_out_max_size);
- if (!subtitle_out) {
- av_log(NULL, AV_LOG_FATAL, "Failed to allocate subtitle_out\n");
- exit_program(1);
- }
- }
-
/* Note: DVB subtitle need one packet to draw them and one other
packet to clear them */
/* XXX: signal it in the codec context ? */
@@ -1038,6 +1026,12 @@ static void do_subtitle_out(OutputFile *of,
if (!check_recording_time(ost))
return;
+ ret = av_new_packet(pkt, subtitle_out_max_size);
+ if (ret < 0) {
+ av_log(NULL, AV_LOG_FATAL, "Failed to allocate subtitle encode buffer\n");
+ exit_program(1);
+ }
+
sub->pts = pts;
// start_display_time is required to be 0
sub->pts += av_rescale_q(sub->start_display_time, (AVRational){ 1, 1000 }, AV_TIME_BASE_Q);
@@ -1048,8 +1042,7 @@ static void do_subtitle_out(OutputFile *of,
ost->frames_encoded++;
- subtitle_out_size = avcodec_encode_subtitle(enc, subtitle_out,
- subtitle_out_max_size, sub);
+ subtitle_out_size = avcodec_encode_subtitle(enc, pkt->data, pkt->size, sub);
if (i == 1)
sub->num_rects = save_num_rects;
if (subtitle_out_size < 0) {
@@ -1057,8 +1050,6 @@ static void do_subtitle_out(OutputFile *of,
exit_program(1);
}
- av_packet_unref(pkt);
- pkt->data = subtitle_out;
pkt->size = subtitle_out_size;
pkt->pts = av_rescale_q(sub->pts, AV_TIME_BASE_Q, ost->mux_timebase);
pkt->duration = av_rescale_q(sub->end_display_time, (AVRational){ 1, 1000 }, ost->mux_timebase);