0

I have 2 RTSP streams, I would like to change between them each minute and I would like to write the result into the same file (streaming.m3u8) and I would like embed HTML video tag. But the video change is not working.

import ffmpeg
import schedule
import time

def stream_1():
    packet_size = 4096

    process = (
        ffmpeg
        .input('rtsp://....')
        .output('streaming.m3u8', hls_time=3, hls_wrap=10)
        .run_async(pipe_stdout=True)
    )

    while process.poll() is None:
        packet = process.stdout.read(packet_size)
        try:
            tcp_socket.send(packet)
        except socket.error:
            process.stdout.close()
            process.wait()
            break

def stream_2():
    packet_size = 4096

    process = (
        ffmpeg
        .input('rtsp://....')
        .output('streaming.m3u8', hls_time=3, hls_wrap=10)
        .run_async(pipe_stdout=True)
    )

    while process.poll() is None:
        packet = process.stdout.read(packet_size)
        try:
            tcp_socket.send(packet)
        except socket.error:
            process.stdout.close()
            process.wait()
            break

schedule.every(1).minutes.do(stream_1)
schedule.every(2).minutes.do(stream_2)
user3740961
  • 329
  • 1
  • 5
  • 17
  • I don't see how are you stopping the execution of `stream_1` or `stream_2` after one minute. And the schedule looks strange, because I believe you are scheduling `stream_1` to run on the minutes: 1, 2, 3, ... and `stream_2` on the minutes: 2, 4, 6, ... – Hernán Alarcón Aug 27 '20 at 01:16
  • Yes. I don't know how kill/stop the process or stream. – user3740961 Aug 27 '20 at 05:03
  • [This question](https://stackoverflow.com/questions/13293269/how-would-i-stop-a-while-loop-after-n-amount-of-time) could help to to stop your while after some time. – Hernán Alarcón Aug 27 '20 at 17:13

0 Answers0