Saving audio clips from livestream

About encoding, codec settings, muxers and filter usage
srafay
New Cone
New Cone
Posts: 4
Joined: 17 Feb 2018 12:59
VLC version: 2.2.2
Operating System: Ubuntu 16.04
Contact:

Saving audio clips from livestream

Postby srafay » 17 Feb 2018 13:11

I am just trying to save audio clips (15 seconds per clip) from live stream using VLC library. I am unable to find any option that could allow me to record only 15 seconds from the live stream. Thus I ended up using timer in my code, but the recording clips sometimes contain 10 seconds, sometimes 20 seconds (rarely 15 seconds). Also, sometimes the audio content is repeated in the clips. Here is the code (I am a newbie so please guide me)

  • Code.py
    import os
    import sys
    import vlc
    import time

    clipNumber = sys.argv[1]

    filepath = 'http://app.pakistanvision.tv:1935/live/ ... layer.m3u8'
    movie = os.path.expanduser(filepath)
    if 'http://' not in filepath:
    if not os.access(movie, os.R_OK):
    print ( 'Error: %s file is not readable' % movie )
    sys.exit(1)
    filename_and_command = "--sout=#transcode{vcodec=none,acodec=mp3,ab=320,channels=2,samplerate=44100}:file{dst=clip" + str(clipNumber) + ".mp3}"
    instance = vlc.Instance(filename_and_command)
    try:
    media = instance.media_new(movie)
    except NameError:
    print ('NameError: % (%s vs Libvlc %s)' % (sys.exc_info()[1],
    vlc.__version__, vlc.libvlc_get_version()))
    sys.exit(1)
    player = instance.media_player_new()
    player.set_media(media)
    player.play()
    time.sleep(15)
    exit()
Now that I want to record 1 minute of the live-stream, I invoke this python code from the bash script 4 times and it creates 4 audio clips (clip1.mp3, clip2.mp3, clip3.mp3 and clip4.mp3)

  • Script.sh
    for ((i=1; i<=4; i++))
    do
    printf "Recording stream #%d\n", "$i"
    python code.py "$i"
    printf "Finished stream #%d\n", "$i"
    done
Is there anyway to just loop the code with Python instead of invoking again and again with bash script (I tried to put the code in the loop in python, but the first clip - clip1 - keeps recording and never finishes recording). And a way to specify that I could only record 15 seconds from the live-stream instead of using time.sleep(15).
I am sure they is an easy and more efficient way to do it all, maybe i am following a wrong approach. Please guide me.

srafay
New Cone
New Cone
Posts: 4
Joined: 17 Feb 2018 12:59
VLC version: 2.2.2
Operating System: Ubuntu 16.04
Contact:

Re: Saving audio clips from livestream

Postby srafay » 25 Feb 2018 14:20

anyone?


Return to “VLC stream-output (sout)”

Who is online

Users browsing this forum: No registered users and 31 guests