From 1372c826de242fccec8e3d42282ac458a84bb43e Mon Sep 17 00:00:00 2001 From: Marton Balint Date: Sun, 3 Jun 2012 19:36:06 +0200 Subject: [PATCH 1/7] ffplay: use dummy video driver if display is disabled Fixes ticket 1402. Signed-off-by: Marton Balint --- ffplay.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ffplay.c b/ffplay.c index 86444a822b..7b9c42ea83 100644 --- a/ffplay.c +++ b/ffplay.c @@ -3060,6 +3060,7 @@ int main(int argc, char **argv) { int flags; VideoState *is; + char dummy_videodriver[] = "SDL_VIDEODRIVER=dummy"; av_log_set_flags(AV_LOG_SKIP_REPEATED); parse_loglevel(argc, argv, options); @@ -3097,6 +3098,8 @@ int main(int argc, char **argv) flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER; if (audio_disable) flags &= ~SDL_INIT_AUDIO; + if (display_disable) + SDL_putenv(dummy_videodriver); /* For the event queue, we always need a video driver. */ #if !defined(__MINGW32__) && !defined(__APPLE__) flags |= SDL_INIT_EVENTTHREAD; /* Not supported on Windows or Mac OS X */ #endif From c9651d4bee36c8d28729622bcf57df8a9e1aa70c Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Wed, 6 Jun 2012 23:17:29 +0200 Subject: [PATCH 2/7] ffplay: fix use after free reproduceable with: ffmpeg -i tests/lena.pnm -pix_fmt pal8 -vcodec rawvideo -s 512x512 out.avi valgrind ffplay_g out.avi Signed-off-by: Michael Niedermayer Signed-off-by: Marton Balint --- ffplay.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ffplay.c b/ffplay.c index 7b9c42ea83..cbbbe7dc00 100644 --- a/ffplay.c +++ b/ffplay.c @@ -1672,10 +1672,11 @@ static int video_thread(void *arg) ret = get_video_frame(is, frame, &pts_int, &pkt); if (ret < 0) goto the_end; - av_free_packet(&pkt); - if (!ret) + if (!ret) { + av_free_packet(&pkt); continue; + } is->frame_last_filter_delay = av_gettime() / 1000000.0 - is->frame_last_returned_time; if (fabs(is->frame_last_filter_delay) > AV_NOSYNC_THRESHOLD / 10.0) @@ -1688,8 +1689,10 @@ static int video_thread(void *arg) last_w, last_h, is->video_st->codec->width, is->video_st->codec->height); avfilter_graph_free(&graph); graph = avfilter_graph_alloc(); - if ((ret = configure_video_filters(graph, is, vfilters)) < 0) + if ((ret = configure_video_filters(graph, is, vfilters)) < 0) { + av_free_packet(&pkt); goto the_end; + } filt_out = is->out_video_filter; last_w = is->video_st->codec->width; last_h = is->video_st->codec->height; @@ -1714,6 +1717,8 @@ static int video_thread(void *arg) } else av_buffersrc_write_frame(filt_in, frame); + av_free_packet(&pkt); + while (ret >= 0) { ret = av_buffersink_get_buffer_ref(filt_out, &picref, 0); if (ret < 0) { From 0a501c756f39d3b3c3242bd0b011b37cfd0eb11f Mon Sep 17 00:00:00 2001 From: Marton Balint Date: Wed, 6 Jun 2012 22:09:41 +0200 Subject: [PATCH 3/7] ffplay: fix frame aspect ratio after qatar merge Signed-off-by: Marton Balint --- ffplay.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ffplay.c b/ffplay.c index cbbbe7dc00..e10988333d 100644 --- a/ffplay.c +++ b/ffplay.c @@ -1699,6 +1699,7 @@ static int video_thread(void *arg) } frame->pts = pts_int; + frame->sample_aspect_ratio = av_guess_sample_aspect_ratio(is->ic, is->video_st, frame); if (is->use_dr1) { FrameBuffer *buf = frame->opaque; AVFilterBufferRef *fb = avfilter_get_video_buffer_ref_from_arrays( From cd947e9a2bc37f5af7a1dda90a7bc62b7f9019e7 Mon Sep 17 00:00:00 2001 From: Marton Balint Date: Wed, 6 Jun 2012 22:20:23 +0200 Subject: [PATCH 4/7] ffplay: add missing filt_in assignment after video filter reconfigure Fixes segfaults on changing resolution. Signed-off-by: Marton Balint --- ffplay.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ffplay.c b/ffplay.c index e10988333d..f22a848079 100644 --- a/ffplay.c +++ b/ffplay.c @@ -1693,6 +1693,7 @@ static int video_thread(void *arg) av_free_packet(&pkt); goto the_end; } + filt_in = is->in_video_filter; filt_out = is->out_video_filter; last_w = is->video_st->codec->width; last_h = is->video_st->codec->height; From e85df18d7495ac2816c090a9421f60055e4e59c9 Mon Sep 17 00:00:00 2001 From: Marton Balint Date: Wed, 6 Jun 2012 22:32:25 +0200 Subject: [PATCH 5/7] ffplay: add support for changing pixel format With the filtering code refactored, it was much easier to finally fix this. Fixes ticket 123 and 238. Signed-off-by: Marton Balint --- ffplay.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ffplay.c b/ffplay.c index f22a848079..86e347f131 100644 --- a/ffplay.c +++ b/ffplay.c @@ -1648,6 +1648,7 @@ static int video_thread(void *arg) AVFilterContext *filt_out = NULL, *filt_in = NULL; int last_w = is->video_st->codec->width; int last_h = is->video_st->codec->height; + enum PixelFormat last_format = is->video_st->codec->pix_fmt; if ((ret = configure_video_filters(graph, is, vfilters)) < 0) { SDL_Event event; @@ -1684,7 +1685,8 @@ static int video_thread(void *arg) #if CONFIG_AVFILTER if ( last_w != is->video_st->codec->width - || last_h != is->video_st->codec->height) { + || last_h != is->video_st->codec->height + || last_format != is->video_st->codec->pix_fmt) { av_log(NULL, AV_LOG_INFO, "Frame changed from size:%dx%d to size:%dx%d\n", last_w, last_h, is->video_st->codec->width, is->video_st->codec->height); avfilter_graph_free(&graph); @@ -1697,6 +1699,7 @@ static int video_thread(void *arg) filt_out = is->out_video_filter; last_w = is->video_st->codec->width; last_h = is->video_st->codec->height; + last_format = is->video_st->codec->pix_fmt; } frame->pts = pts_int; From a78bc6f78c922158cc6afc6eaf5cfea7dab80cfd Mon Sep 17 00:00:00 2001 From: Marton Balint Date: Wed, 6 Jun 2012 23:06:23 +0200 Subject: [PATCH 6/7] ffplay: fix frame_delay calculation in new avfilter code Signed-off-by: Marton Balint --- ffplay.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/ffplay.c b/ffplay.c index 86e347f131..070db4bec7 100644 --- a/ffplay.c +++ b/ffplay.c @@ -1540,9 +1540,6 @@ static int get_video_frame(VideoState *is, AVFrame *frame, int64_t *pts, AVPacke SDL_UnlockMutex(is->pictq_mutex); } - if (ret) - is->frame_last_returned_time = av_gettime() / 1000000.0; - return ret; } return 0; @@ -1679,10 +1676,6 @@ static int video_thread(void *arg) continue; } - is->frame_last_filter_delay = av_gettime() / 1000000.0 - is->frame_last_returned_time; - if (fabs(is->frame_last_filter_delay) > AV_NOSYNC_THRESHOLD / 10.0) - is->frame_last_filter_delay = 0; - #if CONFIG_AVFILTER if ( last_w != is->video_st->codec->width || last_h != is->video_st->codec->height @@ -1725,12 +1718,18 @@ static int video_thread(void *arg) av_free_packet(&pkt); while (ret >= 0) { + is->frame_last_returned_time = av_gettime() / 1000000.0; + ret = av_buffersink_get_buffer_ref(filt_out, &picref, 0); if (ret < 0) { ret = 0; break; } + is->frame_last_filter_delay = av_gettime() / 1000000.0 - is->frame_last_returned_time; + if (fabs(is->frame_last_filter_delay) > AV_NOSYNC_THRESHOLD / 10.0) + is->frame_last_filter_delay = 0; + avfilter_fill_frame_from_video_buffer_ref(frame, picref); pts_int = picref->pts; From 5fdcfdf2370d4c1552601a0633beea0bc84aa437 Mon Sep 17 00:00:00 2001 From: Marton Balint Date: Wed, 6 Jun 2012 23:16:29 +0200 Subject: [PATCH 7/7] ffplay: fix build if avfilter is disabled Signed-off-by: Marton Balint --- ffplay.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ffplay.c b/ffplay.c index 070db4bec7..cb62614f36 100644 --- a/ffplay.c +++ b/ffplay.c @@ -2309,7 +2309,9 @@ static void stream_component_close(VideoState *is, int stream_index) ic->streams[stream_index]->discard = AVDISCARD_ALL; avcodec_close(avctx); +#if CONFIG_AVFILTER free_buffer_pool(&is->buffer_pool); +#endif switch (avctx->codec_type) { case AVMEDIA_TYPE_AUDIO: is->audio_st = NULL;