Differenze tra le versioni di "Registrare in tempo reale in un file l'audio di una radio WEB con le funzioni esterne del API di VLC"
Da Gambas-it.org - Wikipedia.
(Creata pagina con "Con le riorse di '''VLC''' è possibile registrare in un file audio in tempo reale i dati audio trasmessi da una radio WEB. Si rimanda per il codice, pertanto, all'analoga pa...") |
|||
(10 versioni intermedie di uno stesso utente non sono mostrate) | |||
Riga 1: | Riga 1: | ||
− | Con le riorse di '''VLC''' è possibile registrare in un file audio in tempo reale i dati audio trasmessi da una radio WEB. | + | Con le riorse di '''VLC''' è possibile ascoltare e contemporaneamente registrare in un file audio in tempo reale i dati audio trasmessi da una radio WEB. |
− | + | Mostriamo il seguente esempio partico in ambiente grafico: | |
− | + | Private bo As Boolean | |
+ | |||
+ | |||
+ | Library "libvlc:5.6.1" | ||
+ | |||
+ | <FONT Color=gray>' ''libvlc_instance_t * libvlc_new (int argc, const char *const *argv)'' | ||
+ | ' ''Create And initialize a libvlc instance.''</font> | ||
+ | Private Extern libvlc_new(argc As Integer, argv As String[]) As Pointer | ||
+ | |||
+ | <FONT Color=gray>' ''libvlc_media_t *libvlc_media_new_location(libvlc_instance_t *p_instance, const char * psz_mrl)'' | ||
+ | ' ''Create a media with a certain given media resource location, for instance a valid URL.''</font> | ||
+ | Private Extern libvlc_media_new_location(p_instance As Pointer, path As String) As Pointer | ||
+ | |||
+ | <FONT Color=gray>' ''void libvlc_media_add_option (libvlc_media_t *p_md, const char *psz_options) | ||
+ | ' ''Add an option to the media.''</font> | ||
+ | Private Extern libvlc_media_add_option(p_mi As Pointer, psz_options As String) | ||
+ | |||
+ | <FONT Color=gray>' ''libvlc_media_player_t * libvlc_media_player_new(libvlc_instance_t *p_libvlc_instance) | ||
+ | ' ''Create an empty Media Player object.''</font> | ||
+ | Private Extern libvlc_media_player_new(p_libvlc_instance As Pointer) As Pointer | ||
+ | |||
+ | <FONT Color=gray>' ''void libvlc_media_player_set_media(libvlc_media_player_t *p_mi, libvlc_media_t *p_md) | ||
+ | ' ''Set the media that will be used by the media_player.''</font> | ||
+ | Private Extern libvlc_media_player_set_media(p_md As Pointer, mp As Pointer) | ||
+ | |||
+ | <FONT Color=gray>' ''int libvlc_media_player_play (libvlc_media_player_t * p_mi) | ||
+ | ' ''Play the video file.''</font> | ||
+ | Private Extern libvlc_media_player_play(p_mi As Pointer) As Integer | ||
+ | |||
+ | <FONT Color=gray>' ''void libvlc_media_player_release (libvlc_media_player_t * p_mi) | ||
+ | ' ''Release a media_player after use Decrement the reference count of a media player object.''</font> | ||
+ | Private Extern libvlc_media_player_release(p_mi As Pointer) | ||
+ | |||
+ | <FONT Color=gray>' ''void libvlc_media_release (libvlc_media_t *p_md) | ||
+ | ' ''Decrement the reference count of a media descriptor object.''</font> | ||
+ | Private Extern libvlc_media_release(p_md As Pointer) | ||
+ | |||
+ | <FONT Color=gray>' ''libvlc_release (libvlc_instance_t * p_instance) | ||
+ | ' ''Decrement the reference count of a libvlc instance, and destroy it if it reaches zero.''</font> | ||
+ | Private Extern libvlc_release(p_instance As Pointer) | ||
+ | |||
+ | |||
+ | Public Sub ToggleButton1_Click() | ||
+ | |||
+ | Dim inst, mp, m As Pointer | ||
+ | Dim tm As Date | ||
+ | |||
+ | If ToggleButton1.Value Then | ||
+ | |||
+ | <FONT Color=gray>' ''Inizializza la libreria VLC:''</font> | ||
+ | inst = libvlc_new(0, Null) | ||
+ | |||
+ | <FONT Color=gray>' ''Crea un nuovo oggetto multimedia.'' | ||
+ | ' ''Nel secondo argomento della funzione va specificato l'indirizzo del flusso di dati audio trasmessi dalla radio web:''</font> | ||
+ | m = libvlc_media_new_location(inst, "https://stream.rockantenne.de/70er-rock/stream/mp3?aw_0_1st.playerid=radio.de") | ||
+ | |||
+ | <FONT Color=gray>' ''Imposta i parametri per il formato audio e per creare il file audio:''</font> | ||
+ | libvlc_media_add_option(m, ":sout=#transcode{acodec=mp3,ab=128,samplerate=44100,channels=2}:duplicate{dst=display,dst=std{access=file,mux=mp3,dst=/tmp/audio.mp3}}") <FONT Color=gray>' ''...o anche "mux='''raw'''".''</font> | ||
+ | |||
+ | <FONT Color=gray>' ''Crea il media player:''</font> | ||
+ | mp = libvlc_media_player_new(inst) | ||
+ | |||
+ | libvlc_media_player_set_media(mp, m) | ||
+ | |||
+ | libvlc_media_release(m) | ||
+ | |||
+ | <FONT Color=gray>' ''Avvia la registrazione audio da parte del media player:''</font> | ||
+ | libvlc_media_player_play(mp) | ||
+ | |||
+ | tm = Now | ||
+ | |||
+ | While bo = False | ||
+ | Me.Title = Str(Time(0, 0, 0, DateDiff(tm, Now, gb.Millisecond))) | ||
+ | <FONT Color=gray>' ''Il Wait consente di agire su altri oggetti posti sul Form:''</font> | ||
+ | Wait 0.01 | ||
+ | Wend | ||
+ | |||
+ | <FONT Color=gray>' ''Chiude la libreria VLC ed il programma:''</font> | ||
+ | libvlc_media_player_release(mp) | ||
+ | libvlc_release(inst) | ||
+ | Me.Close | ||
+ | Else | ||
+ | <FONT Color=gray>' ''Causa l'arresto della registrazione, la chiusura della libreria VLC e del programma:''</font> | ||
+ | bo = True | ||
+ | Endif | ||
+ | |||
+ | End | ||
− | + | ||
− | + | ==Registrare in altri formati audio== | |
− | + | ||
+ | ===Formato audio WAV=== | ||
+ | Impostare le opzioni audio come segue: | ||
+ | libvlc_media_add_option(m, ":sout=#transcode{acodec=s16l,ab=128,samplerate=44100,channels=2}:duplicate{dst=display,dst=std{access=file,mux=wav,dst=/tmp/audio.wav}}") | ||
+ | |||
+ | ===Formato audio OGG=== | ||
+ | Impostare le opzioni audio come segue: | ||
+ | libvlc_media_add_option(m, ":sout=#transcode{acodec=vorb,ab=128,samplerate=44100,channels=2}:duplicate{dst=display,dst=std{access=file,mux=ogg,dst=/tmp/audio.ogg}}") |
Versione attuale delle 19:01, 21 ago 2024
Con le riorse di VLC è possibile ascoltare e contemporaneamente registrare in un file audio in tempo reale i dati audio trasmessi da una radio WEB.
Mostriamo il seguente esempio partico in ambiente grafico:
Private bo As Boolean Library "libvlc:5.6.1" ' libvlc_instance_t * libvlc_new (int argc, const char *const *argv) ' Create And initialize a libvlc instance. Private Extern libvlc_new(argc As Integer, argv As String[]) As Pointer ' libvlc_media_t *libvlc_media_new_location(libvlc_instance_t *p_instance, const char * psz_mrl) ' Create a media with a certain given media resource location, for instance a valid URL. Private Extern libvlc_media_new_location(p_instance As Pointer, path As String) As Pointer ' void libvlc_media_add_option (libvlc_media_t *p_md, const char *psz_options) ' Add an option to the media. Private Extern libvlc_media_add_option(p_mi As Pointer, psz_options As String) ' libvlc_media_player_t * libvlc_media_player_new(libvlc_instance_t *p_libvlc_instance) ' Create an empty Media Player object. Private Extern libvlc_media_player_new(p_libvlc_instance As Pointer) As Pointer ' void libvlc_media_player_set_media(libvlc_media_player_t *p_mi, libvlc_media_t *p_md) ' Set the media that will be used by the media_player. Private Extern libvlc_media_player_set_media(p_md As Pointer, mp As Pointer) ' int libvlc_media_player_play (libvlc_media_player_t * p_mi) ' Play the video file. Private Extern libvlc_media_player_play(p_mi As Pointer) As Integer ' void libvlc_media_player_release (libvlc_media_player_t * p_mi) ' Release a media_player after use Decrement the reference count of a media player object. Private Extern libvlc_media_player_release(p_mi As Pointer) ' void libvlc_media_release (libvlc_media_t *p_md) ' Decrement the reference count of a media descriptor object. Private Extern libvlc_media_release(p_md As Pointer) ' libvlc_release (libvlc_instance_t * p_instance) ' Decrement the reference count of a libvlc instance, and destroy it if it reaches zero. Private Extern libvlc_release(p_instance As Pointer) Public Sub ToggleButton1_Click() Dim inst, mp, m As Pointer Dim tm As Date If ToggleButton1.Value Then ' Inizializza la libreria VLC: inst = libvlc_new(0, Null) ' Crea un nuovo oggetto multimedia. ' Nel secondo argomento della funzione va specificato l'indirizzo del flusso di dati audio trasmessi dalla radio web: m = libvlc_media_new_location(inst, "https://stream.rockantenne.de/70er-rock/stream/mp3?aw_0_1st.playerid=radio.de") ' Imposta i parametri per il formato audio e per creare il file audio: libvlc_media_add_option(m, ":sout=#transcode{acodec=mp3,ab=128,samplerate=44100,channels=2}:duplicate{dst=display,dst=std{access=file,mux=mp3,dst=/tmp/audio.mp3}}") ' ...o anche "mux=raw". ' Crea il media player: mp = libvlc_media_player_new(inst) libvlc_media_player_set_media(mp, m) libvlc_media_release(m) ' Avvia la registrazione audio da parte del media player: libvlc_media_player_play(mp) tm = Now While bo = False Me.Title = Str(Time(0, 0, 0, DateDiff(tm, Now, gb.Millisecond))) ' Il Wait consente di agire su altri oggetti posti sul Form: Wait 0.01 Wend ' Chiude la libreria VLC ed il programma: libvlc_media_player_release(mp) libvlc_release(inst) Me.Close Else ' Causa l'arresto della registrazione, la chiusura della libreria VLC e del programma: bo = True Endif End
Registrare in altri formati audio
Formato audio WAV
Impostare le opzioni audio come segue:
libvlc_media_add_option(m, ":sout=#transcode{acodec=s16l,ab=128,samplerate=44100,channels=2}:duplicate{dst=display,dst=std{access=file,mux=wav,dst=/tmp/audio.wav}}")
Formato audio OGG
Impostare le opzioni audio come segue:
libvlc_media_add_option(m, ":sout=#transcode{acodec=vorb,ab=128,samplerate=44100,channels=2}:duplicate{dst=display,dst=std{access=file,mux=ogg,dst=/tmp/audio.ogg}}")