Answers.Body: <p>I think the problem is not the caching, but the fact that ffplay don't get a clean encoded stream.</p>
  <p>With your yellow tunnel clip you can try this:</p>
  <pre class="lang-bash prettyprint-override"><code>while true; do
      ffmpeg -i tunnel.mp4 -c:v mpeg2video -b:v 50M -c:a s302m -strict -2 -ar 48k -f mpegts -;
  done | ffmpeg -re -i - -c:v mpeg2video -b:v 50M -c:a s302m -strict -2 -ar 48k -f mpegts - | ffplay -
  </code></pre>
  <p>And you see, that there is almost no glitches anymore. This is not a really nice solution, but the second ffmpeg instance would recompress the hole stream.</p>
  <p>When is just about playing on desktop I would try more somthing like <a href="https://github.com/jaseg/python-mpv" rel="nofollow noreferrer">python-mpv</a>.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-28T16:27:02.157Z
Answers.LastActivityDate: 2021-03-28T16:27:02.157Z
Answers.UserDisplayName: jb_alvarado
Body: <p>I would like to dynamically generate infinite video stream from video clips, so that choose next one on the fly.
  I was inspired by <a href="https://github.com/ffplayout/ffplayout-engine" rel="nofollow noreferrer">ffplayout project</a> which <a href="https://github.com/ffplayout/ffplayout-engine/blob/b45df954a49204f129489d4c2d7f3dd73b956420/ffplayout.py#L76" rel="nofollow noreferrer">runs <code>ffplay</code></a> and make it read from stdin, 
  and then <a href="https://github.com/ffplayout/ffplayout-engine/blob/b45df954a49204f129489d4c2d7f3dd73b956420/ffplayout.py#L114" rel="nofollow noreferrer">runs <code>ffmpeg</code></a> and stdout is redirected to <code>ffplay</code>. It works nice when streaming to rtmp server (probably because there is some buffering applied on the way), but when using <code>ffplay</code> you can notice some glitches on video transition.</p>
  
  <p>Video is converted to mpegts for transport through pipe.</p>
  
  <p>I was testing on <a href="https://pixabay.com/videos/tunnel-yellow-abstract-background-12904/" rel="nofollow noreferrer">this video</a> which is made for looping.</p>
  
  <p>In order to eliminate ffmpeg startup, file read delay, I did what follows:</p>
  
  <pre><code># saved raw output
  ffmpeg -i tunnel.mp4 -f mpegts tunnel.mpegts
  # made fifo.ts
  mkfifo fifo
  # run ffplay to read from stdin
  ffplay -an -f mpegts -i pipe:0 &lt;fifo.ts
  # write video to fifo
  cat tunnel.mpegts tunnel.mpegts tunnel.mpegts tunnel.mpegts &gt;&gt; fifo.ts
  </code></pre>
  
  <p>still glitches on transition.
  I even tried to read video to memory and write to fifo to eliminate disk io</p>
  
  <pre><code>def main():
      with open('tunnel.mpegts', 'rb') as fd:
          tunnel = fd.read()
  
      with open('fifo.ts', 'wb') as fd:
          for _ in range(5):
              fd.write(tunnel)
  </code></pre>
  
  <p>still glitches.</p>
  
  <p>Any idea how to make it work? Maybe another ffmpeg on the way that would buffer/delay/join/transcode?</p>
  
Tags: <ffmpeg>
Title: Concatenate videos by pipng to ffplay
UserDisplayName: d21d3q
ThreadText: # Concatenate videos by pipng to ffplay
  
  (Asked by: username_0 on 2020-03-18)
  
  I would like to dynamically generate infinite video stream from video clips, so that choose next one on the fly.
  I was inspired by [ffplayout project](https://github.com/ffplayout/ffplayout-engine) which [runs `ffplay`](https://github.com/ffplayout/ffplayout-engine/blob/b45df954a49204f129489d4c2d7f3dd73b956420/ffplayout.py#L76) and make it read from stdin,
  and then [runs `ffmpeg`](https://github.com/ffplayout/ffplayout-engine/blob/b45df954a49204f129489d4c2d7f3dd73b956420/ffplayout.py#L114) and stdout is redirected to `ffplay`. It works nice when streaming to rtmp server (probably because there is some buffering applied on the way), but when using `ffplay` you can notice some glitches on video transition.
  
  Video is converted to mpegts for transport through pipe.
  
  I was testing on [this video](https://pixabay.com/videos/tunnel-yellow-abstract-background-12904/) which is made for looping.
  
  In order to eliminate ffmpeg startup, file read delay, I did what follows:
  
  ```
  # saved raw output
  ffmpeg -i tunnel.mp4 -f mpegts tunnel.mpegts
  # made fifo.ts
  mkfifo fifo
  # run ffplay to read from stdin
  ffplay -an -f mpegts -i pipe:0 <fifo.ts
  # write video to fifo
  cat tunnel.mpegts tunnel.mpegts tunnel.mpegts tunnel.mpegts >> fifo.ts
  
  ```
  
  still glitches on transition.
  I even tried to read video to memory and write to fifo to eliminate disk io
  
  ```
  def main():
      with open('tunnel.mpegts', 'rb') as fd:
          tunnel = fd.read()
  
      with open('fifo.ts', 'wb') as fd:
          for _ in range(5):
              fd.write(tunnel)
  
  ```
  
  still glitches.
  
  Any idea how to make it work? Maybe another ffmpeg on the way that would buffer/delay/join/transcode?
  
  **Tags:** ffmpeg
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-03-28. Score: 0
  
  I think the problem is not the caching, but the fact that ffplay don't get a clean encoded stream.
  
  With your yellow tunnel clip you can try this:
  
  ```bash
  while true; do
      ffmpeg -i tunnel.mp4 -c:v mpeg2video -b:v 50M -c:a s302m -strict -2 -ar 48k -f mpegts -;
  done | ffmpeg -re -i - -c:v mpeg2video -b:v 50M -c:a s302m -strict -2 -ar 48k -f mpegts - | ffplay -
  
  ```
  
  And you see, that there is almost no glitches anymore. This is not a really nice solution, but the second ffmpeg instance would recompress the hole stream.
  
  When is just about playing on desktop I would try more somthing like [python-mpv](https://github.com/jaseg/python-mpv).
  
  
  ---
  
  