From 1922c0a7732f8a21510f59fdd8ccff6b33280827 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Robert=20Kr=C3=BCger?= <krueger@signal7.de>
Date: Tue, 23 Mar 2010 17:39:51 +0000
Subject: [PATCH] Add a loop option to ffplay.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Patch by Robert Krüger, krueger signal7 de

Originally committed as revision 22646 to svn://svn.ffmpeg.org/ffmpeg/trunk
---
 doc/ffplay-doc.texi |  2 ++
 ffplay.c            | 12 +++++++++---
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/doc/ffplay-doc.texi b/doc/ffplay-doc.texi
index e3d4bf68783..11794b2cd49 100644
--- a/doc/ffplay-doc.texi
+++ b/doc/ffplay-doc.texi
@@ -53,6 +53,8 @@ Disable graphical display.
 Force format.
 @item -window_title @var{title}
 Set window title (default is the input filename).
+@item -loop @var{number}
+Loops movie playback <number> times. 0 means forever.
 @end table
 
 @section Advanced options
diff --git a/ffplay.c b/ffplay.c
index 315a1268943..03da8965821 100644
--- a/ffplay.c
+++ b/ffplay.c
@@ -260,6 +260,7 @@ static int error_recognition = FF_ER_CAREFUL;
 static int error_concealment = 3;
 static int decoder_reorder_pts= -1;
 static int autoexit;
+static int loop=1;
 static int framedrop=1;
 
 static int rdftspeed=20;
@@ -2481,9 +2482,13 @@ static int decode_thread(void *arg)
                 packet_queue_put(&is->videoq, pkt);
             }
             SDL_Delay(10);
-            if(autoexit && is->audioq.size + is->videoq.size + is->subtitleq.size ==0){
-                ret=AVERROR_EOF;
-                goto fail;
+            if(is->audioq.size + is->videoq.size + is->subtitleq.size ==0){
+                if(loop!=1 && (!loop || --loop)){
+                    stream_seek(cur_stream, start_time != AV_NOPTS_VALUE ? start_time : 0, 0, 0);
+                }else if(autoexit){
+                    ret=AVERROR_EOF;
+                    goto fail;
+                }
             }
             continue;
         }
@@ -2963,6 +2968,7 @@ static const OptionDef options[] = {
     { "sync", HAS_ARG | OPT_FUNC2 | OPT_EXPERT, {(void*)opt_sync}, "set audio-video sync. type (type=audio/video/ext)", "type" },
     { "threads", HAS_ARG | OPT_FUNC2 | OPT_EXPERT, {(void*)opt_thread_count}, "thread count", "count" },
     { "autoexit", OPT_BOOL | OPT_EXPERT, {(void*)&autoexit}, "exit at the end", "" },
+    { "loop", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&loop}, "set number of times the playback shall be looped", "loop count" },
     { "framedrop", OPT_BOOL | OPT_EXPERT, {(void*)&framedrop}, "drop frames when cpu is too slow", "" },
     { "window_title", OPT_STRING | HAS_ARG, {(void*)&window_title}, "set window title", "window title" },
 #if CONFIG_AVFILTER
-- 
GitLab