summaryrefslogtreecommitdiff
path: root/avconv.c
diff options
context:
space:
mode:
Diffstat (limited to 'avconv.c')
-rw-r--r--avconv.c49
1 files changed, 35 insertions, 14 deletions
diff --git a/avconv.c b/avconv.c
index 9fae43a5c2..5f0422cc5d 100644
--- a/avconv.c
+++ b/avconv.c
@@ -638,7 +638,6 @@ static int configure_video_filters(InputStream *ist, OutputStream *ost)
if ((ret = avfilter_graph_parse(ost->graph, ost->avfilter, &inputs, &outputs, NULL)) < 0)
return ret;
- av_freep(&ost->avfilter);
} else {
if ((ret = avfilter_link(last_filter, 0, ost->output_video_filter, 0)) < 0)
return ret;
@@ -767,6 +766,10 @@ void exit_program(int ret)
bsfc = next;
}
output_streams[i].bitstream_filters = NULL;
+
+#if CONFIG_AVFILTER
+ av_freep(&output_streams[i].avfilter);
+#endif
}
for (i = 0; i < nb_input_files; i++) {
avformat_close_input(&input_files[i].ctx);
@@ -1302,6 +1305,7 @@ static void do_subtitle_out(AVFormatContext *s,
static int bit_buffer_size = 1024 * 256;
static uint8_t *bit_buffer = NULL;
+#if !CONFIG_AVFILTER
static void do_video_resample(OutputStream *ost,
InputStream *ist,
AVFrame *in_picture,
@@ -1316,7 +1320,6 @@ static void do_video_resample(OutputStream *ost,
ost->resample_height != dec->height ||
ost->resample_pix_fmt != dec->pix_fmt;
-#if !CONFIG_AVFILTER
if (resample_changed) {
av_log(NULL, AV_LOG_INFO,
"Input stream #%d:%d frame changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s\n",
@@ -1332,6 +1335,7 @@ static void do_video_resample(OutputStream *ost,
dec->height != enc->height ||
dec->pix_fmt != enc->pix_fmt;
+
if (ost->video_resample) {
*out_picture = &ost->resample_frame;
if (!ost->img_resample_ctx || resample_changed) {
@@ -1357,21 +1361,13 @@ static void do_video_resample(OutputStream *ost,
sws_scale(ost->img_resample_ctx, in_picture->data, in_picture->linesize,
0, ost->resample_height, (*out_picture)->data, (*out_picture)->linesize);
}
-#else
- if (resample_changed) {
- avfilter_graph_free(&ost->graph);
- if (configure_video_filters(ist, ost)) {
- av_log(NULL, AV_LOG_FATAL, "Error reinitializing filters!\n");
- exit_program(1);
- }
- }
-#endif
if (resample_changed) {
ost->resample_width = dec->width;
ost->resample_height = dec->height;
ost->resample_pix_fmt = dec->pix_fmt;
}
}
+#endif
static void do_video_out(AVFormatContext *s,
@@ -1426,7 +1422,11 @@ static void do_video_out(AVFormatContext *s,
if (nb_frames <= 0)
return;
+#if !CONFIG_AVFILTER
do_video_resample(ost, ist, in_picture, &final_picture);
+#else
+ final_picture = in_picture;
+#endif
/* duplicates frame if needed */
for (i = 0; i < nb_frames; i++) {
@@ -2012,12 +2012,33 @@ static int transcode_video(InputStream *ist, AVPacket *pkt, int *got_output, int
for (i = 0; i < nb_output_streams; i++) {
OutputStream *ost = &output_streams[i];
- int frame_size;
+ int frame_size, resample_changed;
if (!check_output_constraints(ist, ost) || !ost->encoding_needed)
continue;
#if CONFIG_AVFILTER
+ resample_changed = ost->resample_width != decoded_frame->width ||
+ ost->resample_height != decoded_frame->height ||
+ ost->resample_pix_fmt != decoded_frame->format;
+ if (resample_changed) {
+ av_log(NULL, AV_LOG_INFO,
+ "Input stream #%d:%d frame changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s\n",
+ ist->file_index, ist->st->index,
+ ost->resample_width, ost->resample_height, av_get_pix_fmt_name(ost->resample_pix_fmt),
+ decoded_frame->width, decoded_frame->height, av_get_pix_fmt_name(decoded_frame->format));
+
+ avfilter_graph_free(&ost->graph);
+ if (configure_video_filters(ist, ost)) {
+ av_log(NULL, AV_LOG_FATAL, "Error reinitializing filters!\n");
+ exit_program(1);
+ }
+
+ ost->resample_width = decoded_frame->width;
+ ost->resample_height = decoded_frame->height;
+ ost->resample_pix_fmt = decoded_frame->format;
+ }
+
if (!decoded_frame->sample_aspect_ratio.num)
decoded_frame->sample_aspect_ratio = ist->st->sample_aspect_ratio;
decoded_frame->pts = ist->pts;
@@ -3736,13 +3757,13 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc)
ost->top_field_first = -1;
MATCH_PER_STREAM_OPT(top_field_first, i, ost->top_field_first, oc, st);
- MATCH_PER_STREAM_OPT(copy_initial_nonkeyframes, i, ost->copy_initial_nonkeyframes, oc ,st);
-
#if CONFIG_AVFILTER
MATCH_PER_STREAM_OPT(filters, str, filters, oc, st);
if (filters)
ost->avfilter = av_strdup(filters);
#endif
+ } else {
+ MATCH_PER_STREAM_OPT(copy_initial_nonkeyframes, i, ost->copy_initial_nonkeyframes, oc ,st);
}
return ost;