user1129812
user1129812

Reputation: 2889

How to delay a live stream in stdout?

I have an audio stream coming to stdout which would be piped to a media player (e.g. VLC, ffplay). I want to know that is it possible to delay the audio stream by several seconds in the following manner (assumed to be in Ubuntu bash shell) :

<audio stream> | <stream delay program> | <media player, e.g. ffplay>

I want to delay the audio stream to make it more synchronize with another video stream.

Is there any program/method that could achieve this goal ?

Thanks for any suggestion.

Upvotes: 2

Views: 339

Answers (1)

Jean-Fran&#231;ois Fabre
Jean-Fran&#231;ois Fabre

Reputation: 140196

You could try something like this (python script):

import sys

chunk_size = 100000  # adjust according to sample rate, nb_channels, etc..

buffer2=None

while True:
    buffer1 = sys.stdin.read(chunk_size)
    if buffer2:
        sys.stdout.write(buffer2)
    buffer2 = sys.stdin.read(chunk_size)
    sys.stdout.write(buffer1)

would read 2 times and write only once, so it will be shifted.

Tell me if it works, it's just an attempt. I'll delete the answer if it doesn't.

Upvotes: 1

Related Questions