Answers.Body: <p>It sounds like you want to live transition from one video playback to another and mix these videos as you go (like a video DJ) and stream them to some kind of website like Twitch. Just use OBS for this and then load all the video files into two different players and then use OBS filters to transition as you go. You will need at least a quad-core (8 threads) machine to handle all the processor overhead, but if you have a decent video card it can assist with the x264 compression for the outbound stream. It would be the shortest distance to what it sounds like you want to do. Because of the command line system of FFMPEG it is hard to have a fluid and smooth interface in a live stream like what you are looking for.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-25T12:20:12.423Z
Answers.Text: Thanks for the Help, i wasnt aware of OBS. Seems like a good product but iam looking to do this with ffmpeg. The playlists can be created and from that i want to make a ffmpeg command. This does not need to be live editable. Also i want it to be able to  run on a rasberri pi where i can check the status of the output (ffplay etc..) The goal is to create an easy video player which mixes on the box because of bandwith reasons. i edited the original to include a github repo for the tests.
Answers.UserDisplayName: machtl
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-08-04T23:07:42.750Z
Answers.Text: How have you solved your problem with ffmpeg? I am still interested in make a realtime mix of videos and stream.
Answers.UserDisplayName: iLevi
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-24T08:40:43.830Z
Answers.LastActivityDate: 2019-07-24T08:40:43.830Z
Answers.UserDisplayName: user1544752
Body: <p>I am using FFmpeg to combine a radio stream with a video but my target is to read from a playlist file (own format) and combine multiple videos with the audio in the background. The most important thing is that I want to grab the output and pipe it to VLC or FFplay (I would prefer VLC because somehow sometimes FFplay displays vertical scanlines with some videos where VLC doesn't).</p>
  
  <p>The playlist reading part and so on is already done, so I just need the FFmpeg part combining everything in a FFmpeg command.</p>
  
  <p>Also, a goal is to get it to work locally on a Raspberry Pi so no transcoding should happen because rpi is busy decoding video.</p>
  
  <p>I have the following <strong>playlist:</strong></p>
  
  <ol>
  <li>video <code>test1.mkv</code> with audio stream (mpeg2)</li>
  <li>video <code>test2.mpeg</code> with audio stream (same as above)</li>
  <li>video with audio from video</li>
  <li>video with audio from mp3</li>
  <li>... and so on</li>
  <li>if needed loop to playlist item 1</li>
  </ol>
  
  <p>So you can see those videos can have a different formats and sizes and the audio can be from the video or from a stream/mp3.</p>
  
  <p>First of all I am wondering if I should actually start to use the library and not do it with the command line, is this even possible with the command line?</p>
  
  <p>the main <strong>problems</strong> are:</p>
  
  <ol>
  <li>Video transitions do not work because stream is playing (doesnt stop)</li>
  <li>I cannot get the video to pipe to VLC</li>
  <li>I cannot get the transitions to work properly</li>
  <li>Should not transcode to work on a RPI</li>
  <li>Loop 1 item for x or the whole playlist for x or infinite doesn't work </li>
  </ol>
  
  <p>simple map of <strong>video and audio</strong> stream:
      ffmpeg -i "SampleVideo_1280x720_1mb.mp4" -i "<a href="https://www.mpeg2stream.com/" rel="nofollow noreferrer">https://www.mpeg2stream.com/</a>" -map 0:v:0 -map 1:a:0 -f mpegts udp://127.0.0.1:23000</p>
  
  <p>in this i combine the video with a video, this works nice and i grab the output from the stream (meh, i dont want to transcode)</p>
  
  <p><strong>piping:</strong>
  i tried different pipe methods to get this to work but i cannot get it to work well, especially on the windows testbox.</p>
  
  <pre><code>ffmpeg -i "test.mkv" -f mpegts -codec copy - | vlc -
  </code></pre>
  
  <p>here i still transcode to transportstreams, but also vlc doesnt display it and somehow only a bar is running back and forth.</p>
  
  <p>I gave up on piping and now only put it on an mpegts stream:</p>
  
  <pre><code>-c:v libx264 -preset superfast -tune zerolatency -c:a aac -ar 44100 -f mpegts udp://127.0.0.1:23000
  </code></pre>
  
  <p><strong>Transitioning:</strong>
  making the transition i do with the following:</p>
  
  <pre><code>ffmpeg -i "SampleVideo_1280x720_1mb.mp4" -i "test1.mkv" -filter_complex "[0]fade=t=out:st=0:d=1:alpha=1,setpts=PTS-STARTPTS[va0]; [1]fade=t=in:st=0:d=1:alpha=1,setpts=PTS-STARTPTS[va1]; [va0][va1]overlay[outv]; [0][1]amix[outa]" -map [outv] -map "[outa]" -crf 10 out.mp4
  </code></pre>
  
  <p>here i write in an outfile, this should also be piped, i would understand that this does not work without transcoding. isnt there an easier method? also it does not work without scaling to something. so i probably could just use concat without transitioning. Also here i gave up and use just normal concatinating</p>
  
  <p><strong>Concat and scaling:</strong></p>
  
  <pre><code>ffmpeg -i big_buck_bunny.mp4 -i SampleVideo_1280x720_1mb.mp4 -i "file_example_MP4_1920_18MG.mp4" -i "https://teststream.de/stream/"`
  -filter_complex `
  "[0:v]scale=1280x720:force_original_aspect_ratio=increase[v0]; `
  [1:v]scale=1280x720:force_original_aspect_ratio=increase[v1]; `
  [2:v]scale=1280x720:force_original_aspect_ratio=increase[v2]; `
  [v0][0:a][v1][1:a][v2][3:a]concat=n=3:v=1:a=1[v][a]" `
  -map [v] -map [a] `
  -c:v libx264 -preset superfast -tune zerolatency -c:a aac -ar 44100 -f mpegts udp://127.0.0.1:23000
  </code></pre>
  
  <p>the problem with concatinating shows that the first audio plays correctly (from the video) but it does not concat to video 3 because the stream is obviously not finished, how can i concat the stream for video 3 dynamic length? Also i cannot get it to scale automatically to the best resolution without hardcoding it.</p>
  
  <p><strong>Loop:</strong>
  the next thing is i cannot get loop to work. stream-loop doesnt work or is it possible to do this via complex filtering?</p>
  
  <p>any ideas how to get all of this to work or is this not possible with ffmpeg and i should think of another solution? </p>
  
  <p>Cheers and thanks a lot!</p>
  
  <p><strong>Edit 1:</strong>
  Most of the questions now are obvious (some of them are just because i dont know much about video stuff)</p>
  
  <p>So far i have come to create some of it, but i still have some problems, but 2 of them currently stop me the most:
  <a href="https://github.com/martinlierschof/ffmpeg_test/" rel="nofollow noreferrer">https://github.com/martinlierschof/ffmpeg_test/</a></p>
  
  <p>Problem 1: audio stream starts from beginning every time i amix it. It should always play from the "live" position.</p>
  
  <p>Problem 2: the [videoout] and [audioout] should be able to be looped (after concating) for x amounts or -1 (infinite)</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-02-24T21:54:22.103Z
Comments.Text: In your `ffmpeg -i "SampleVideo_1280x720_1mb.mp4" -i "https://www.mpeg2stream.com/" -map 0:v:0 -map 1:a:0 -f mpegts udp://127.0.0.1:23000`, when you don't want to transcode, why don't you add `-c copy`? Regards.
Comments.UserDisplayName: Golar Ramblar
Tags: <ffmpeg><playlist>
Title: combine stream and multiple videos to live output, with transitions
UserDisplayName: machtl
ThreadText: # combine stream and multiple videos to live output, with transitions
  
  (Asked by: username_0 on 2019-07-18)
  
  I am using FFmpeg to combine a radio stream with a video but my target is to read from a playlist file (own format) and combine multiple videos with the audio in the background. The most important thing is that I want to grab the output and pipe it to VLC or FFplay (I would prefer VLC because somehow sometimes FFplay displays vertical scanlines with some videos where VLC doesn't).
  
  The playlist reading part and so on is already done, so I just need the FFmpeg part combining everything in a FFmpeg command.
  
  Also, a goal is to get it to work locally on a Raspberry Pi so no transcoding should happen because rpi is busy decoding video.
  
  I have the following **playlist:**
  
  1. video `test1.mkv` with audio stream (mpeg2)
  2. video `test2.mpeg` with audio stream (same as above)
  3. video with audio from video
  4. video with audio from mp3
  5. ... and so on
  6. if needed loop to playlist item 1
  
  So you can see those videos can have a different formats and sizes and the audio can be from the video or from a stream/mp3.
  
  First of all I am wondering if I should actually start to use the library and not do it with the command line, is this even possible with the command line?
  
  the main **problems** are:
  
  1. Video transitions do not work because stream is playing (doesnt stop)
  2. I cannot get the video to pipe to VLC
  3. I cannot get the transitions to work properly
  4. Should not transcode to work on a RPI
  5. Loop 1 item for x or the whole playlist for x or infinite doesn't work
  
  simple map of **video and audio** stream:
  ffmpeg -i "SampleVideo\_1280x720\_1mb.mp4" -i "<https://www.mpeg2stream.com/>" -map 0:v:0 -map 1:a:0 -f mpegts udp://127.0.0.1:23000
  
  in this i combine the video with a video, this works nice and i grab the output from the stream (meh, i dont want to transcode)
  
  **piping:**
  i tried different pipe methods to get this to work but i cannot get it to work well, especially on the windows testbox.
  
  ```
  ffmpeg -i "test.mkv" -f mpegts -codec copy - | vlc -
  
  ```
  
  here i still transcode to transportstreams, but also vlc doesnt display it and somehow only a bar is running back and forth.
  
  I gave up on piping and now only put it on an mpegts stream:
  
  ```
  -c:v libx264 -preset superfast -tune zerolatency -c:a aac -ar 44100 -f mpegts udp://127.0.0.1:23000
  
  ```
  
  **Transitioning:**
  making the transition i do with the following:
  
  ```
  ffmpeg -i "SampleVideo_1280x720_1mb.mp4" -i "test1.mkv" -filter_complex "[0]fade=t=out:st=0:d=1:alpha=1,setpts=PTS-STARTPTS[va0]; [1]fade=t=in:st=0:d=1:alpha=1,setpts=PTS-STARTPTS[va1]; [va0][va1]overlay[outv]; [0][1]amix[outa]" -map [outv] -map "[outa]" -crf 10 out.mp4
  
  ```
  
  here i write in an outfile, this should also be piped, i would understand that this does not work without transcoding. isnt there an easier method? also it does not work without scaling to something. so i probably could just use concat without transitioning. Also here i gave up and use just normal concatinating
  
  **Concat and scaling:**
  
  ```
  ffmpeg -i big_buck_bunny.mp4 -i SampleVideo_1280x720_1mb.mp4 -i "file_example_MP4_1920_18MG.mp4" -i "https://teststream.de/stream/"`
  -filter_complex `
  "[0:v]scale=1280x720:force_original_aspect_ratio=increase[v0]; `
  [1:v]scale=1280x720:force_original_aspect_ratio=increase[v1]; `
  [2:v]scale=1280x720:force_original_aspect_ratio=increase[v2]; `
  [v0][0:a][v1][1:a][v2][3:a]concat=n=3:v=1:a=1[v][a]" `
  -map [v] -map [a] `
  -c:v libx264 -preset superfast -tune zerolatency -c:a aac -ar 44100 -f mpegts udp://127.0.0.1:23000
  
  ```
  
  the problem with concatinating shows that the first audio plays correctly (from the video) but it does not concat to video 3 because the stream is obviously not finished, how can i concat the stream for video 3 dynamic length? Also i cannot get it to scale automatically to the best resolution without hardcoding it.
  
  **Loop:**
  the next thing is i cannot get loop to work. stream-loop doesnt work or is it possible to do this via complex filtering?
  
  any ideas how to get all of this to work or is this not possible with ffmpeg and i should think of another solution?
  
  Cheers and thanks a lot!
  
  **Edit 1:**
  Most of the questions now are obvious (some of them are just because i dont know much about video stuff)
  
  So far i have come to create some of it, but i still have some problems, but 2 of them currently stop me the most:
  <https://github.com/martinlierschof/ffmpeg_test/>
  
  Problem 1: audio stream starts from beginning every time i amix it. It should always play from the "live" position.
  
  Problem 2: the [videoout] and [audioout] should be able to be looped (after concating) for x amounts or -1 (infinite)
  
  **Tags:** ffmpeg, playlist
  
  > **Comments:**
  > **username_1**: In your `ffmpeg -i "SampleVideo_1280x720_1mb.mp4" -i "https://www.mpeg2stream.com/" -map 0:v:0 -map 1:a:0 -f mpegts udp://127.0.0.1:23000`, when you don't want to transcode, why don't you add `-c copy`? Regards.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2019-07-24. Score: 1
  
  It sounds like you want to live transition from one video playback to another and mix these videos as you go (like a video DJ) and stream them to some kind of website like Twitch. Just use OBS for this and then load all the video files into two different players and then use OBS filters to transition as you go. You will need at least a quad-core (8 threads) machine to handle all the processor overhead, but if you have a decent video card it can assist with the x264 compression for the outbound stream. It would be the shortest distance to what it sounds like you want to do. Because of the command line system of FFMPEG it is hard to have a fluid and smooth interface in a live stream like what you are looking for.
  
  > **Comments:**
  > **username_0**: Thanks for the Help, i wasnt aware of OBS. Seems like a good product but iam looking to do this with ffmpeg. The playlists can be created and from that i want to make a ffmpeg command. This does not need to be live editable. Also i want it to be able to  run on a rasberri pi where i can check the status of the output (ffplay etc..) The goal is to create an easy video player which mixes on the box because of bandwith reasons. i edited the original to include a github repo for the tests.  
  > **username_3**: How have you solved your problem with ffmpeg? I am still interested in make a realtime mix of videos and stream.  
  
  ---
  
  