I'm trying to record an RTP stream via python-vlc for exactly 30 seconds but the output file is sometimes less than or greater than my desired video length.
Note: I tried using ffmpeg, but it can't properly decode the stream hence the decision to use python-vlc.
This is my code:
import vlc
import time
vlcInstance = vlc.Instance("--demux=ts")
player1 = vlcInstance.media_player_new()
media1 = vlcInstance.media_new("rtp://239.194.115.71:5000")
media1.add_option("sout=file/ts:sample.mpg")
limiter = 0
player1.set_media(media1)
player1.play()
time.sleep(1)
while player1.is_playing():
if limiter > 30:
player1.stop()
media1.release()
break
limiter = limiter + 1
time.sleep(1)
What possible method can I use to always record the stream for exactly 30 seconds?