summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2011-11-21 14:39:22 +0100
committerAnton Khirnov <anton@khirnov.net>2011-11-21 18:12:38 +0100
commit9595234c941cb81ffc2858e3f5859f0b9fa58a39 (patch)
tree1b59d9f0c95e8d910065eb1dc9cb16b9a0d0da46
parent45d4b66f6fa7115124ae0051dc24cda1017f95a0 (diff)
avconv: split subtitle transcoding out of output_packet().
-rw-r--r--avconv.c59
1 files changed, 34 insertions, 25 deletions
diff --git a/avconv.c b/avconv.c
index 409f2bad3d..4a5fb9c0bb 100644
--- a/avconv.c
+++ b/avconv.c
@@ -1811,16 +1811,41 @@ fail:
return ret;
}
+static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output)
+{
+ AVSubtitle subtitle;
+ int i, ret = avcodec_decode_subtitle2(ist->st->codec,
+ &subtitle, got_output, pkt);
+ if (ret < 0)
+ return ret;
+ if (!*got_output)
+ return 0;
+
+ pkt->size = 0;
+
+ rate_emu_sleep(ist);
+
+ for (i = 0; i < nb_output_streams; i++) {
+ OutputStream *ost = &output_streams[i];
+
+ if (!check_output_constraints(ist, ost) || !ost->encoding_needed)
+ continue;
+
+ do_subtitle_out(output_files[ost->file_index].ctx, ost, ist, &subtitle, pkt->pts);
+ }
+
+ avsubtitle_free(&subtitle);
+ return 0;
+}
+
/* pkt = NULL means EOF (needed to flush decoder buffers) */
static int output_packet(InputStream *ist, int ist_index,
OutputStream *ost_table, int nb_ostreams,
const AVPacket *pkt)
{
- AVFormatContext *os;
OutputStream *ost;
int ret = 0, i;
int got_output;
- AVSubtitle subtitle, *subtitle_to_free;
int64_t pkt_pts = AV_NOPTS_VALUE;
AVPacket avpkt;
@@ -1867,22 +1892,17 @@ static int output_packet(InputStream *ist, int ist_index,
if (!got_output)
goto discard_packet;
continue;
+ } else if (ist->st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) {
+ ret = transcode_subtitles(ist, &avpkt, &got_output);
+ if (ret < 0)
+ return ret;
+ if (!got_output)
+ goto discard_packet;
+ continue;
}
/* decode the packet if needed */
- subtitle_to_free = NULL;
switch(ist->st->codec->codec_type) {
- case AVMEDIA_TYPE_SUBTITLE:
- ret = avcodec_decode_subtitle2(ist->st->codec,
- &subtitle, &got_output, &avpkt);
- if (ret < 0)
- return ret;
- if (!got_output) {
- goto discard_packet;
- }
- subtitle_to_free = &subtitle;
- avpkt.size = 0;
- break;
default:
return -1;
}
@@ -1898,27 +1918,16 @@ static int output_packet(InputStream *ist, int ist_index,
if (!check_output_constraints(ist, ost) || !ost->encoding_needed)
continue;
- os = output_files[ost->file_index].ctx;
-
/* set the input output pts pairs */
//ost->sync_ipts = (double)(ist->pts + input_files[ist->file_index].ts_offset - start_time)/ AV_TIME_BASE;
av_assert0(ist->decoding_needed);
switch(ost->st->codec->codec_type) {
- case AVMEDIA_TYPE_SUBTITLE:
- do_subtitle_out(os, ost, ist, &subtitle,
- pkt->pts);
- break;
default:
abort();
}
}
- /* XXX: allocate the subtitles in the codec ? */
- if (subtitle_to_free) {
- avsubtitle_free(subtitle_to_free);
- subtitle_to_free = NULL;
- }
if (ret < 0)
return ret;
}