Skip to content

How do I split a rtsp stream in multiple files with remux? #989

@linchiyu

Description

@linchiyu

Overview

I'm trying to split a rtsp stream in multiple files. I was successfull doing it but the files that came out have a time length issue, it increments the last file length on his own. I'm doing 10 seconds cuts for each file, the first file gets 10 seconds but the second file gets 20 seconds time length with 10 seconds of content, the third get 30 seconds file with last 10 seconds of data only.

Here is my code:

import time

from os import path

import av

inputContainer = av.open("rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mp4", "r")

while True:

    dateString = time.time()

    start = time.time()

    videoFilePath = f"output{dateString}.avi"

    in_stream = inputContainer.streams.video[0]

    output_time = 0

    with av.open(f"{videoFilePath}", "w") as output:

        out_stream = output.add_stream(template=in_stream)

        for packet in inputContainer.demux(in_stream):

            if packet.dts is None:

                continue

            packet.stream = out_stream

            packet.pts = packet.pts - output_time

            packet.dts = packet.dts - output_time

            output.mux(packet)

            cur_time = time.time() - start

            if cur_time >= 10:

                output_time = packet.dts

                break

Expected behavior

Each file produced should be 10 seconds on metadata.

Actual behavior

The files gets larger time length, if you open the file it shows no image up until the last 10 seconds of the file.

Investigation

I've tried to change pts and dts timers but it changes nothing.
I also tried to look for changing the metadada in container or the stream, but found nothing

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions