Answers.Body: <p>Try with the movie filter instead</p>
  
  <pre><code>ffmpeg -loop 1 -i image.jpg -filter_complex \
          "movie=video.mov:loop=999,setpts=N/(FRAME_RATE*TB)[1v]; \
          [0:v][1v]overlay=x=main_w*0.44:y=main_h*0.33[out]" \
         -map [out] -t 00:00:15  out.mp4
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-04-28T20:44:51.773Z
Answers.Text: Works like a charm! Any idea why stream_loop doesn't work ?
Answers.UserDisplayName: user361526
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-04-29T05:30:49.107Z
Answers.Text: I'm speculating here, but stream_loop value will be registered in the same shared variable as the image demuxer's loop argument, and does not actually get successfully registered. The movie filter creates its own local context. But this is just a guess.
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-04-28T20:01:52.710Z
Answers.LastActivityDate: 2016-04-28T20:01:52.710Z
Answers.UserDisplayName: Gyan
Body: <p>I'm trying to overlay a video on top of an image. The problem that I'm facing is that the video duration that I want is longer than my input video's duration.</p>
  
  <p>To solve this issue, I try to generate a streaming loop and hardcode the duration that I want using the parameter "t".</p>
  
  <p>I'm using the setpts filter to make sure that my container format (.mp4) accepts past frames by rewriting their timestamps:</p>
  
  <pre><code>ffmpeg -loop 1 -i image.jpg -stream_loop -1 -i video.mov  -filter_complex "[1:v]setpts=N/(FRAME_RATE*TB)[1v];[0:v][1v]overlay=x=main_w*0.44:y=main_h*0.33[out]" -map [out] -t 00:00:15  out.mp4
  </code></pre>
  
  <p>So the command reads as follows:</p>
  
  <ol>
  <li>take one infinite input where each frame is image.jpg</li>
  <li>take another infinite input (video.mov) by looping (-stream_loop -1)</li>
  </ol>
  
  <p>Each frame will go through the filter:</p>
  
  <ul>
  <li>setpts will re-write the timestamps for source 1 (video.mov)</li>
  <li>overlay will put each setpts-ed frame from video.mov on top of each frame from the initial input (image.jpg - 0:v)</li>
  </ul>
  
  <p>This should continue until a file with 00:00:15 seconds is created.</p>
  
  <p>This command does generate that file but the video.mov isn't looped, once the first loop finishes the last frame is repeated until the output movie ends.</p>
  
  <p>FYI: I made a couple more tests:</p>
  
  <pre><code>ffmpeg -stream_loop -1 -i movie.mov -filter_complex "[0:v]setpts=N/(FRAME_RATE*TB)[out]" -map [out] -t 00:00:30 output.mp4
  </code></pre>
  
  <p>This works fine, it generates a movie with 30 seconds duration with the input movie looped to fill the output movie</p>
  
  <p>on the other hard, if I add one more input file:</p>
  
  <pre><code>ffmpeg -stream_loop -1 -i movie.mov -loop 1 -i image.jpg -filter_complex "[0:v]setpts=N/(FRAME_RATE*TB)[out]" -map [out] -t 00:00:30 output.mp4
  </code></pre>
  
  <p>This will not create a movie with 30 seconds, although one of the inputs is never used, ffmpeg creates a movie file with just one loop of movie.mov and the same length of movie.mov.</p>
  
  <p>Any advices please ?</p>
  
  <p>Thank you very much!</p>
  
  <p>Ze</p>
  
Tags: <ffmpeg><mp4>
Title: Issues looping a stream with FFMpeg
UserDisplayName: user361526
ThreadText: # Issues looping a stream with FFMpeg
  
  (Asked by: username_0 on 2016-04-28)
  
  I'm trying to overlay a video on top of an image. The problem that I'm facing is that the video duration that I want is longer than my input video's duration.
  
  To solve this issue, I try to generate a streaming loop and hardcode the duration that I want using the parameter "t".
  
  I'm using the setpts filter to make sure that my container format (.mp4) accepts past frames by rewriting their timestamps:
  
  ```
  ffmpeg -loop 1 -i image.jpg -stream_loop -1 -i video.mov  -filter_complex "[1:v]setpts=N/(FRAME_RATE*TB)[1v];[0:v][1v]overlay=x=main_w*0.44:y=main_h*0.33[out]" -map [out] -t 00:00:15  out.mp4
  
  ```
  
  So the command reads as follows:
  
  1. take one infinite input where each frame is image.jpg
  2. take another infinite input (video.mov) by looping (-stream\_loop -1)
  
  Each frame will go through the filter:
  
  * setpts will re-write the timestamps for source 1 (video.mov)
  * overlay will put each setpts-ed frame from video.mov on top of each frame from the initial input (image.jpg - 0:v)
  
  This should continue until a file with 00:00:15 seconds is created.
  
  This command does generate that file but the video.mov isn't looped, once the first loop finishes the last frame is repeated until the output movie ends.
  
  FYI: I made a couple more tests:
  
  ```
  ffmpeg -stream_loop -1 -i movie.mov -filter_complex "[0:v]setpts=N/(FRAME_RATE*TB)[out]" -map [out] -t 00:00:30 output.mp4
  
  ```
  
  This works fine, it generates a movie with 30 seconds duration with the input movie looped to fill the output movie
  
  on the other hard, if I add one more input file:
  
  ```
  ffmpeg -stream_loop -1 -i movie.mov -loop 1 -i image.jpg -filter_complex "[0:v]setpts=N/(FRAME_RATE*TB)[out]" -map [out] -t 00:00:30 output.mp4
  
  ```
  
  This will not create a movie with 30 seconds, although one of the inputs is never used, ffmpeg creates a movie file with just one loop of movie.mov and the same length of movie.mov.
  
  Any advices please ?
  
  Thank you very much!
  
  Ze
  
  **Tags:** ffmpeg, mp4
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-04-28. Score: 4 | Accepted answer
  
  Try with the movie filter instead
  
  ```
  ffmpeg -loop 1 -i image.jpg -filter_complex \
          "movie=video.mov:loop=999,setpts=N/(FRAME_RATE*TB)[1v]; \
          [0:v][1v]overlay=x=main_w*0.44:y=main_h*0.33[out]" \
         -map [out] -t 00:00:15  out.mp4
  
  ```
  
  > **Comments:**
  > **username_0**: Works like a charm! Any idea why stream_loop doesn't work ?  
  > **username_1**: I'm speculating here, but stream_loop value will be registered in the same shared variable as the image demuxer's loop argument, and does not actually get successfully registered. The movie filter creates its own local context. But this is just a guess.  
  
  ---
  
  