jaseg / python-mpv

Python interface to the awesome mpv media player
https://git.jaseg.de/python-mpv.git
Other
532 stars 67 forks source link

Streaming record support #191

Closed silvioprog closed 2 years ago

silvioprog commented 2 years ago

Hi.

First, thanks for this awesome project!

So, is there any option to start a streaming record?

For example, using the mpv command line tool, we can record a streaming into a output file:

mpv http://s1.myradiostream.com:12508/listen.mp3 --stream-record=record.mp3

It would be really a useful feature!

cheers

silvioprog commented 2 years ago

Ping https://github.com/mpv-player/mpv/issues/9625

dfaker commented 2 years ago

As mentioned on the mpv issue, reproduced here for future visitors:

Your two options for this are passing the keyword argument to the constructor:

import mpv

player = mpv.MPV(stream_record='out.mp3')
player.play('http://s1.myradiostream.com:12508/listen.mp3')
player.wait_for_playback()

or setting the property on MPV before playback:

import mpv

player = mpv.MPV()
player.stream_record='out.mp3'
player.play('http://s1.myradiostream.com:12508/listen.mp3')
player.wait_for_playback()

setting the player.stream_record property to a new value mid playback also seems to correctly switch to a new stream and close the old one correctly.

import mpv
import time

player = mpv.MPV()

player.play('http://s1.myradiostream.com:12508/listen.mp3')

time.sleep(10)
player.stream_record='outdelayed.mp3'
time.sleep(5)
player.stream_record='outdelayed2.mp3'
time.sleep(5)
player.stream_record='outdelayed3.mp3'

player.wait_for_playback()
silvioprog commented 2 years ago

@dfaker, firstly, thanks a lot for this information, it worked and will help me a lot!

So, I have another question. To stop the only the recording without stop the radio, I'll use this (ugly) code (that works fine):

player.stream_record = ''

Is this a proper way to stop a recording and keep the streaming playing?

dfaker commented 2 years ago

That doesn't strike me as a distasteful solution at all.

silvioprog commented 2 years ago

Thanks again for the additional info, @dfaker. I'm going to use it. :+1: