Convertire i formati audio mediante il Componente gb.media
Utilizzando i plugin di GStreamer con le Classi MediaControl e MediaPipeline del Componente gb.media, è possibile effettuare diverse conversioni di file audio da un formato ad un altro.
Mostriamo di seguito qualche esempio pratico.
Indice
- 1 Conversione audio dal formato WAV al formato MP3
- 2 Conversione audio dal formato WAV al formato OGG
- 3 Conversione audio dal formato MP3 al formato OGG
- 4 Conversione audio dal formato MP3 al formato WAV
- 5 Conversione audio dal formato MP3 al formato RAW
- 6 Conversione audio dal formato OGG-Vorbis al formato MP3
- 7 Conversione audio dal formato RAW al formato WAV
- 8 Conversione audio dal formato RAW al formato MP3
- 9 Conversione audio dal formato RAW al formato OGG-Vorbis
- 10 Conversione audio dal formato FLAC al formato WAV
- 11 Conversione audio dal formato FLAC al formato MP3
- 12 Conversione audio dal formato FLAC al formato OGG-Vorbis
- 13 Conversione audio dal formato AAC al formato WAV
- 14 Conversione audio dal formato AAC al formato MP3
- 15 Conversione audio dal formato AAC al formato OGG-Vorbis
- 16 Conversione audio dal formato AIFF al formato WAV
- 17 Conversione audio dal formato AIFF al formato MP3
- 18 Conversione audio dal formato AIFF al formato OGG-Vorbis
- 19 Conversione audio con il plugin "decodebin"
Conversione audio dal formato WAV al formato MP3
Private Const QUALITY As String = "quality" Private Const BITRATE As String = "bitrate" Private bo As Boolean Public Sub Main() Dim fileaudio, appoggio As String Dim pl As MediaPipeline Dim src, wprs, cnv, lam, snk As MediaControl fileaudio = "/percorso/del/file.wav" appoggio = Temp pl = New MediaPipeline As "PLine" src = New MediaControl(pl, "filesrc") src["location"] = fileaudio wprs = New MediaControl(pl, "wavparse") cnv = New MediaControl(pl, "audioconvert") lam = New MediaControl(pl, "lamemp3enc") lam["target"] = BITRATE ' Imposta il Bitrate. lam["cbr"] = True ' Imposta il Bitrate "Costante". lam["bitrate"] = 192 ' Imposta il valore del Bitrate "Costante". snk = New MediaControl(pl, "filesink") snk["location"] = appoggio ' Collega fra loro all'interno della pipeline gli oggetti MediaControl impostati: src.LinkTo(wprs) wprs.LinkTo(cnv) cnv.LinkTo(lam) lam.LinkTo(snk) pl.Play() Print "Durata del file wav: "; Time(0, 0, 0, pl.Duration * 1000) Repeat Write "\r\e[0mTempo trascorso: \e[31m" & Time(0, 0, 0, pl.Position * 1000) Wait 0.01 Until bo Copy appoggio To "/tmp" &/ File.BaseName(fileaudio) & ".mp3" pl.Stop pl.Close Print "\n\e[0mConversione terminata !" End Public Sub PLine_End() ' Questo Evento viene sollevato, quando la conversione è terminata bo = True End
Conversione audio dal formato WAV al formato OGG
Private bo As Boolean Public Sub Main() Dim fileaudio, appoggio As String Dim pl As MediaPipeline Dim src, wprs, cnv, vor, mux, snk As MediaControl fileaudio = "/percorso/del/file.wav" appoggio = Temp pl = New MediaPipeline As "PLine" src = New MediaControl(pl, "filesrc") src["location"] = fileaudio wprs = New MediaControl(pl, "wavparse") cnv = New MediaControl(pl, "audioconvert") vor = New MediaControl(pl, "vorbisenc") mux = New MediaControl(pl, "oggmux") snk = New MediaControl(pl, "filesink") snk["location"] = appoggio src.LinkTo(wprs) wprs.LinkTo(cnv) cnv.LinkTo(vor) vor.LinkTo(mux) mux.LinkTo(snk) pl.Play() Print "Durata del file wav: "; Time(0, 0, 0, pl.Duration * 1000) Repeat Write "\r\e[0mTempo trascorso: \e[31m" & Time(0, 0, 0, pl.Position * 1000) Wait 0.01 Until bo Copy appoggio To "/tmp" &/ File.BaseName(fileaudio) & ".ogg" pl.Stop pl.Close Print "\n\e[0mConversione terminata !" End Public Sub PLine_End() bo = True End
Conversione audio dal formato MP3 al formato OGG
Private bo As Boolean Public Sub Main() Dim fileaudio, appoggio As String Dim pl As MediaPipeline Dim src, map, mad, vor, mux, snk As MediaControl fileaudio = "/percorso/del/file.mp3" appoggio = Temp pl = New MediaPipeline As "PLine" src = New MediaControl(pl, "filesrc") src["location"] = fileaudio map = New MediaControl(pl, "mpegaudioparse") mad = New MediaControl(pl, "mpg123audiodec") vor = New MediaControl(pl, "vorbisenc") mux = New MediaControl(pl, "oggmux") snk = New MediaControl(pl, "filesink") snk["location"] = appoggio src.LinkTo(map) map.LinkTo(mad) mad.LinkTo(vor) vor.LinkTo(mux) mux.LinkTo(snk) pl.Play() While pl.Duration < 1 Wait 0.01 Wend Print "Durata del file mp3: "; Time(0, 0, 0, pl.Duration * 1000) Repeat Write "\r\e[0mTempo trascorso: \e[31m" & Time(0, 0, 0, pl.Position * 1000) Wait 0.01 Until bo Copy appoggio To "/tmp" &/ File.BaseName(fileaudio) & ".ogg" pl.Stop pl.Close Print "\n\e[0mConversione terminata !" End Public Sub PLine_End() bo = True End
Conversione audio dal formato MP3 al formato WAV
Private bo As Boolean Public Sub Main() Dim fileaudio, appoggio As String Dim pl As MediaPipeline Dim src, map, mad, wav, snk As MediaControl fileaudio = "/percorso/del/file.mp3" appoggio = Temp pl = New MediaPipeline As "PLine" src = New MediaControl(pl, "filesrc") src["location"] = fileaudio map = New MediaControl(pl, "mpegaudioparse") mad = New MediaControl(pl, "mpg123audiodec") wav = New MediaControl(pl, "wavenc") snk = New MediaControl(pl, "filesink") snk["location"] = appoggio src.LinkTo(map) map.LinkTo(mad) mad.LinkTo(wav) wav.LinkTo(snk) pl.Play() While pl.Duration < 1 Wait 0.01 Wend Print "Durata del file mp3: "; Time(0, 0, 0, pl.Duration * 1000) Repeat Write "\r\e[0mTempo trascorso: \e[31m" & Time(0, 0, 0, pl.Position * 1000) Wait 0.01 Until bo Copy appoggio To "/tmp" &/ File.BaseName(fileaudio) & ".wav" pl.Stop pl.Close Print "\n\e[0mConversione terminata !" End Public Sub PLine_End() bo = True End
Conversione audio dal formato MP3 al formato RAW
Con il seguente codice si otterranno da un file MP3 i dati audio grezzi nel formato: frequenza di campionamento = 44100, risoluzione = 16 bit, canali = 2.
Private bo As Boolean Public Sub Main() Dim fileaudio, appoggio As String Dim pl As MediaPipeline Dim src, par, dcd, snk As MediaControl Dim fil As MediaFilter fileaudio = "/percorso/del/file.mp3" appoggio = Temp pl = New MediaPipeline As "PLine" src = New MediaControl(pl, "filesrc") src["location"] = fileaudio par = New MediaControl(pl, "mpegaudioparse") dcd = New MediaControl(pl, "mpg123audiodec") fil = New MediaFilter(pl, "audio/x-raw, format=S16LE, rate=44100, channels=2, endianness=1234, width=16, depth=16") snk = New MediaControl(pl, "filesink") snk["location"] = appoggio src.LinkTo(par) par.LinkTo(dcd) dcd.LinkTo(fil) fil.LinkTo(snk) pl.Play() While pl.Duration < 1 Wait 0.01 Wend Print "Durata del file mp3: "; Time(0, 0, 0, pl.Duration * 1000) Repeat Write "\r\e[0mTempo trascorso: \e[31m" & Time(0, 0, 0, pl.Position * 1000) Wait 0.01 Until bo Copy appoggio To "/tmp" &/ File.BaseName(fileaudio) & ".raw" pl.Stop pl.Close Print "\n\e[0mConversione terminata !" End Public Sub PLine_End() bo = True End
Conversione audio dal formato OGG-Vorbis al formato MP3
Private Const QUALITY As String = "quality" Private Const BITRATE As String = "bitrate" Private bo As Boolean Public Sub Main() Dim fileaudio, appoggio As String Dim pl As MediaPipeline Dim src, ogg, vor, cnv, lam, snk As MediaControl fileaudio = "/percorso/del/file.ogg" appoggio = Temp pl = New MediaPipeline As "PLine" src = New MediaControl(pl, "filesrc") src["location"] = fileaudio ogg = New MediaControl(pl, "oggdemux") vor = New MediaControl(pl, "vorbisdec") cnv = New MediaControl(pl, "audioconvert") lam = New MediaControl(pl, "lamemp3enc") lam["target"] = BITRATE ' Imposta il Bitrate. lam["cbr"] = True ' Imposta il Bitrate "Costante". lam["bitrate"] = 192 ' Imposta il valore del Bitrate "Costante". snk = New MediaControl(pl, "filesink") snk["location"] = appoggio src.LinkTo(ogg) ogg.LinkLaterTo(vor) vor.LinkTo(cnv) cnv.LinkTo(lam) lam.LinkTo(snk) pl.Play() Print "Durata del file ogg: "; Time(0, 0, 0, pl.Duration * 1000) Repeat Write "\r\e[0mTempo trascorso: \e[31m" & Time(0, 0, 0, pl.Position * 1000) Wait 0.01 Until bo Copy appoggio To "/tmp" &/ File.BaseName(fileaudio) & ".mp3" pl.Stop pl.Close Print "\n\e[0mConversione terminata !" End Public Sub PLine_End() ' Questo Evento viene sollevato, quando la conversione è terminata bo = True End
Conversione audio dal formato RAW al formato WAV
Il seguente codice prevede che i dati del file audio RAW abbiano le seguenti caratteristiche: frequenza di campionamento = 44100; numero di canali = 2; modalità interleaved e formato-pcm = S16LE.
Private Const GST_AUDIO_FORMAT_S16LE As Integer = 4 Private bo As Boolean Public Sub Main() Dim fileaudio, appoggio As String Dim pl As MediaPipeline Dim src, raw, wav, snk As MediaControl fileaudio = "/percorso/del/file/raw" appoggio = Temp pl = New MediaPipeline As "PLine" src = New MediaControl(pl, "filesrc") src["location"] = fileaudio raw = New MediaControl(pl, "rawaudioparse") raw["interleaved"] = True raw["num-channels"] = 2 raw["pcm-format"] = GST_AUDIO_FORMAT_S16LE raw["sample-rate"] = 44100 wav = New MediaControl(pl, "wavenc") snk = New MediaControl(pl, "filesink") snk["location"] = appoggio src.LinkTo(raw) raw.LinkTo(wav) wav.LinkTo(snk) pl.Play() Print "Durata del file wav finale: "; Time(0, 0, 0, pl.Duration * 1000) Repeat Write "\r\e[0mTempo trascorso: \e[31m" & Time(0, 0, 0, pl.Position * 1000) Wait 0.01 Until bo Copy appoggio To "/tmp" &/ File.BaseName(fileaudio) & ".wav" pl.Stop pl.Close Print "\n\e[0mConversione terminata !" End Public Sub PLine_End() bo = True End
Conversione audio dal formato RAW al formato MP3
Private Const QUALITY As String = "quality" Private Const BITRATE As String = "bitrate" Private bo As Boolean Public Sub Main() Dim fileaudio, appoggio As String Dim pl As MediaPipeline Dim src, raw, lam, snk As MediaControl fileaudio = "/percorso/del/file/raw" appoggio = Temp pl = New MediaPipeline As "PLine" src = New MediaControl(pl, "filesrc") src["location"] = fileaudio raw = New MediaControl(pl, "rawaudioparse") raw["interleaved"] = True raw["num-channels"] = 2 raw["pcm-format"] = GST_AUDIO_FORMAT_S16LE raw["sample-rate"] = 44100 lam = New MediaControl(pl, "lamemp3enc") lam["target"] = BITRATE ' Imposta il Bitrate lam["cbr"] = True ' Imposta il Bitrate "Costante" lam["bitrate"] = 192 ' Imposta il valore del Bitrate "Costante" snk = New MediaControl(pl, "filesink") snk["location"] = appoggio src.LinkTo(raw) raw.LinkTo(lam) lam.LinkTo(snk) pl.Play() While pl.Duration < 1 Wait 0.01 Wend Print "Durata del file mp3 finale: "; Time(0, 0, 0, pl.Duration * 1000) Repeat Write "\r\e[0mTempo trascorso: \e[31m" & Time(0, 0, 0, pl.Position * 1000) Wait 0.01 Until bo Copy appoggio To "/tmp" &/ File.BaseName(fileaudio) & ".mp3" pl.Stop pl.Close Print "\n\e[0mConversione terminata !" End Public Sub PLine_End() bo = True End
Conversione audio dal formato RAW al formato OGG-Vorbis
Private bo As Boolean Public Sub Main() Dim fileaudio, appoggio As String Dim pl As MediaPipeline Dim src, raw, cnv, vor, mux, snk As MediaControl fileaudio = "/percorso/del/file/raw" appoggio = Temp pl = New MediaPipeline As "PLine" src = New MediaControl(pl, "filesrc") src["location"] = fileaudio raw = New MediaControl(pl, "rawaudioparse") raw["interleaved"] = True raw["num-channels"] = 2 raw["pcm-format"] = GST_AUDIO_FORMAT_S16LE raw["sample-rate"] = 44100 cnv = New MediaControl(pl, "audioconvert") vor = New MediaControl(pl, "vorbisenc") mux = New MediaControl(pl, "oggmux") snk = New MediaControl(pl, "filesink") snk["location"] = appoggio src.LinkTo(raw) raw.LinkTo(cnv) cnv.LinkTo(vor) vor.LinkTo(mux) mux.LinkTo(snk) pl.Play() While pl.Duration < 1 Wait 0.01 Wend Print "Durata del file ogg finale: "; Time(0, 0, 0, pl.Duration * 1000) Repeat Write "\r\e[0mTempo trascorso: \e[31m" & Time(0, 0, 0, pl.Position * 1000) Wait 0.01 Until bo Copy appoggio To "/tmp" &/ File.BaseName(fileaudio) & ".ogg" pl.Stop pl.Close Print "\n\e[0mConversione terminata !" End Public Sub PLine_End() bo = True End
Conversione audio dal formato FLAC al formato WAV
Private bo As Boolean Public Sub Main() Dim fileaudio, appoggio As String Dim pl As MediaPipeline Dim src, flp, fld, wav, snk As MediaControl fileaudio = "/percorso/del/file/flac" appoggio = Temp pl = New MediaPipeline As "PLine" src = New MediaControl(pl, "filesrc") src["location"] = fileaudio flp = New MediaControl(pl, "flacparse") fld = New MediaControl(pl, "flacdec") wav = New MediaControl(pl, "wavenc") snk = New MediaControl(pl, "filesink") snk["location"] = appoggio src.LinkTo(flp) flp.LinkTo(fld) fld.LinkTo(wav) wav.LinkTo(snk) pl.Play() While pl.Duration < 1 Wait 0.01 Wend Print "Durata del file Flac: "; Time(0, 0, 0, pl.Duration * 1000) Repeat Write "\r\e[0mTempo trascorso: \e[31m" & Time(0, 0, 0, pl.Position * 1000) Wait 0.01 Until bo Copy appoggio To "/tmp" &/ File.BaseName(fileaudio) & ".wav" pl.Stop pl.Close Print "\n\e[0mConversione terminata !" End Public Sub PLine_End() bo = True End
Conversione audio dal formato FLAC al formato MP3
Private Const QUALITY As String = "quality" Private Const BITRATE As String = "bitrate" Private bo As Boolean Public Sub Main() Dim fileaudio, appoggio As String Dim pl As MediaPipeline Dim src, flp, fld, lam, snk As MediaControl fileaudio = "/percorso/del/file/flac" appoggio = Temp pl = New MediaPipeline As "PLine" src = New MediaControl(pl, "filesrc") src["location"] = fileaudio flp = New MediaControl(pl, "flacparse") fld = New MediaControl(pl, "flacdec") lam = New MediaControl(pl, "lamemp3enc") lam["target"] = BITRATE lam["cbr"] = True lam["bitrate"] = 192 snk = New MediaControl(pl, "filesink") snk["location"] = appoggio src.LinkTo(flp) flp.LinkTo(fld) fld.LinkTo(lam) lam.LinkTo(snk) pl.Play() While pl.Duration < 1 Wait 0.01 Wend Print "Durata del file Flac: "; Time(0, 0, 0, pl.Duration * 1000) Repeat Write "\r\e[0mTempo trascorso: \e[31m" & Time(0, 0, 0, pl.Position * 1000) Wait 0.01 Until bo Copy appoggio To "/tmp" &/ File.BaseName(fileaudio) & ".mp3" pl.Stop pl.Close Print "\n\e[0mConversione terminata !" End Public Sub PLine_End() bo = True End
Conversione audio dal formato FLAC al formato OGG-Vorbis
Private bo As Boolean Public Sub Main() Dim fileaudio, appoggio As String Dim pl As MediaPipeline Dim src, flp, fld, cnv, vor, mux, snk As MediaControl fileaudio = "/percorso/del/file/flac" appoggio = Temp pl = New MediaPipeline As "PLine" src = New MediaControl(pl, "filesrc") src["location"] = fileaudio flp = New MediaControl(pl, "flacparse") fld = New MediaControl(pl, "flacdec") cnv = New MediaControl(pl, "audioconvert") vor = New MediaControl(pl, "vorbisenc") mux = New MediaControl(pl, "oggmux") snk = New MediaControl(pl, "filesink") snk["location"] = appoggio src.LinkTo(flp) flp.LinkTo(fld) fld.LinkTo(cnv) cnv.LinkTo(vor) vor.LinkTo(mux) mux.LinkTo(snk) pl.Play() While pl.Duration < 1 Wait 0.01 Wend Print "Durata del file flac: "; Time(0, 0, 0, pl.Duration * 1000) Repeat Write "\r\e[0mTempo trascorso: \e[31m" & Time(0, 0, 0, pl.Position * 1000) Wait 0.01 Until bo Copy appoggio To "/tmp" &/ File.BaseName(fileaudio) & ".ogg" pl.Stop pl.Close Print "\n\e[0mConversione terminata !" End Public Sub PLine_End() bo = True End
Conversione audio dal formato AAC al formato WAV
Private bo As Boolean Public Sub Main() Dim fileaudio, temporaneo As String Dim pl As MediaPipeline Dim src, aac, wav, snk As MediaControl fileaudio = "/percorso/del/file/aac" temporaneo = Temp pl = New MediaPipeline As "PLine" src = New MediaControl(pl, "filesrc") src["location"] = fileaudio aac = New MediaControl(pl, "faad") wav = New MediaControl(pl, "wavenc") snk = New MediaControl(pl, "filesink") snk["location"] = temporaneo src.LinkTo(flp) flp.LinkTo(fld) fld.LinkTo(wav) wav.LinkTo(snk) pl.Play() While pl.Duration < 1 Wait 0.01 Wend Print "Durata del file aac: "; Time(0, 0, 0, pl.Duration * 1000) Repeat Write "\r\e[0mTempo trascorso: \e[31m" & Time(0, 0, 0, pl.Position * 1000) Wait 0.01 Until bo Copy temporaneo To "/tmp" &/ File.BaseName(fileaudio) & ".wav" pl.Stop pl.Close Print "\n\e[0mConversione terminata !" End Public Sub PLine_End() bo = True End
Conversione audio dal formato AAC al formato MP3
Private Const QUALITY As String = "quality" Private Const BITRATE As String = "bitrate" Private bo As Boolean Public Sub Main() Dim fileaudio, temporaneo As String Dim pl As MediaPipeline Dim src, aac, lam, snk As MediaControl fileaudio = "/percorso/del/file/aac" temporaneo = Temp pl = New MediaPipeline As "PLine" src = New MediaControl(pl, "filesrc") src["location"] = fileaudio aac = New MediaControl(pl, "faad") lam = New MediaControl(pl, "lamemp3enc") lam["target"] = BITRATE lam["cbr"] = True lam["bitrate"] = 192 snk = New MediaControl(pl, "filesink") snk["location"] = temporaneo src.LinkTo(aac) aac.LinkTo(lam) lam.LinkTo(snk) pl.Play() While pl.Duration < 1 Wait 0.01 Wend Print "Durata del file Acc: "; Time(0, 0, 0, pl.Duration * 1000) Repeat Write "\r\e[0mTempo trascorso: \e[31m" & Time(0, 0, 0, pl.Position * 1000) Wait 0.01 Until bo Copy temporaneo To "/tmp" &/ File.BaseName(fileaudio) & ".mp3" pl.Stop pl.Close Print "\n\e[0mConversione terminata !" End Public Sub PLine_End() bo = True End
Conversione audio dal formato AAC al formato OGG-Vorbis
Private bo As Boolean Public Sub Main() Dim fileaudio, temporaneo As String Dim pl As MediaPipeline Dim src, aac, cnv, vor, mux, snk As MediaControl fileaudio = "/percorso/del/file/aac" temporaneo = Temp pl = New MediaPipeline As "PLine" src = New MediaControl(pl, "filesrc") src["location"] = fileaudio aac = New MediaControl(pl, "faad") cnv = New MediaControl(pl, "audioconvert") vor = New MediaControl(pl, "vorbisenc") mux = New MediaControl(pl, "oggmux") snk = New MediaControl(pl, "filesink") snk["location"] = temporaneo src.LinkTo(aac) aac.LinkTo(cnv) cnv.LinkTo(vor) vor.LinkTo(mux) mux.LinkTo(snk) pl.Play() While pl.Duration < 1 Wait 0.01 Wend Print "Durata del file aac: "; Time(0, 0, 0, pl.Duration * 1000) Repeat Write "\r\e[0mTempo trascorso: \e[31m" & Time(0, 0, 0, pl.Position * 1000) Wait 0.01 Until bo Copy temporaneo To "/tmp" &/ File.BaseName(fileaudio) & ".ogg" pl.Stop pl.Close Print "\n\e[0mConversione terminata !" End Public Sub PLine_End() bo = True End
Conversione audio dal formato AIFF al formato WAV
Private bo As Boolean Public Sub Main() Dim fileaudio, temporaneo As String Dim pl As MediaPipeline Dim src, aif, cnv, wav, snk As MediaControl fileaudio = "/percorso/del/file/aiff" temporaneo = Temp pl = New MediaPipeline As "PLine" src = New MediaControl(pl, "filesrc") src["location"] = fileaudio aif = New MediaControl(pl, "aiffparse") cnv = New MediaControl(pl, "audioconvert") wav = New MediaControl(pl, "wavenc") snk = New MediaControl(pl, "filesink") snk["location"] = temporaneo src.LinkTo(aif) aif.LinkTo(cnv) cnv.LinkTo(wav) wav.LinkTo(snk) pl.Play() While pl.Duration < 1 Wait 0.01 Wend Print "Durata del file aiff: "; Time(0, 0, 0, pl.Duration * 1000) Repeat Write "\r\e[0mTempo trascorso: \e[31m" & Time(0, 0, 0, pl.Position * 1000) Wait 0.01 Until bo Copy temporaneo To "/tmp" &/ File.BaseName(fileaudio) & ".wav" pl.Stop pl.Close Print "\n\e[0mConversione terminata !" End Public Sub PLine_End() bo = True End
Conversione audio dal formato AIFF al formato MP3
Private Const QUALITY As String = "quality" Private Const BITRATE As String = "bitrate" Private bo As Boolean Public Sub Main() Dim fileaudio, temporaneo As String Dim pl As MediaPipeline Dim src, aif, cnv, lam, snk As MediaControl fileaudio = "/percorso/del/file/aiff" temporaneo = Temp pl = New MediaPipeline As "PLine" src = New MediaControl(pl, "filesrc") src["location"] = fileaudio aac = New MediaControl(pl, "aiffparse") cnv = New MediaControl(pl, "audioconvert") lam = New MediaControl(pl, "lamemp3enc") lam["target"] = BITRATE lam["cbr"] = True lam["bitrate"] = 192 snk = New MediaControl(pl, "filesink") snk["location"] = temporaneo src.LinkTo(aif) aif.LinkTo(cnv) cnv.LinkTo(lam) lam.LinkTo(snk) pl.Play() While pl.Duration < 1 Wait 0.01 Wend Print "Durata del file aiff: "; Time(0, 0, 0, pl.Duration * 1000) Repeat Write "\r\e[0mTempo trascorso: \e[31m" & Time(0, 0, 0, pl.Position * 1000) Wait 0.01 Until bo Copy temporaneo To "/tmp" &/ File.BaseName(fileaudio) & ".mp3" pl.Stop pl.Close Print "\n\e[0mConversione terminata !" End Public Sub PLine_End() bo = True End
Conversione audio dal formato AIFF al formato OGG-Vorbis
Private bo As Boolean Public Sub Main() Dim fileaudio, temporaneo As String Dim pl As MediaPipeline Dim src, aif, cnv, vor, mux, snk As MediaControl fileaudio = "/percorso/del/file/aiff" temporaneo = Temp pl = New MediaPipeline As "PLine" src = New MediaControl(pl, "filesrc") src["location"] = fileaudio aac = New MediaControl(pl, "aiffparse") cnv = New MediaControl(pl, "audioconvert") vor = New MediaControl(pl, "vorbisenc") mux = New MediaControl(pl, "oggmux") snk = New MediaControl(pl, "filesink") snk["location"] = temporaneo src.LinkTo(aif) aif.LinkTo(cnv) cnv.LinkTo(vor) vor.LinkTo(mux) mux.LinkTo(snk) pl.Play() While pl.Duration < 1 Wait 0.01 Wend Print "Durata del file aiff: "; Time(0, 0, 0, pl.Duration * 1000) Repeat Write "\r\e[0mTempo trascorso: \e[31m" & Time(0, 0, 0, pl.Position * 1000) Wait 0.01 Until bo Copy temporaneo To "/tmp" &/ File.BaseName(fileaudio) & ".ogg" pl.Stop pl.Close Print "\n\e[0mConversione terminata !" End Public Sub PLine_End() bo = True End
Conversione audio con il plugin "decodebin"
Usando il plugin "decodebin" è possibile convertire qualsiasi formato audio in un altro desiderato.
Mostriamo un esempio, nel quale sarà convertito un file audio "OGG" in un file audio "WAV", avente il seguente formato: frequenza di campionamento = 44100, risoluzione = 16 bit, canali = 2.
Private bo As Boolean Public Sub Main() Dim fileaudio, appoggio As String Dim pl As MediaPipeline Dim src, dcb, con, flt, wav, snk As MediaControl fileaudio = "/percorso/del/file.ogg" appoggio = Temp pl = New MediaPipeline As "PLine" src = New MediaControl(pl, "filesrc") src["location"] = fileaudio dcb = New MediaControl(pl, "decodebin") con = New MediaControl(pl, "audioconvert") flt = New MediaFilter(pl, "audio/x-raw, format=S16LE, rate=44100, channels=2, depth=16") wav = New MediaControl(pl, "wavenc") snk = New MediaControl(pl, "filesink") snk["location"] = appoggio src.LinkTo(dcb) dcb.LinkLaterTo(con) con.LinkTo(fil) fil.LinkTo(wav) wav.LinkTo(snk) pl.Play() Print "Durata del file ogg: "; Time(0, 0, 0, pl.Duration * 1000) Repeat Write "\r\e[0mTempo trascorso: \e[31m" & Time(0, 0, 0, pl.Position * 1000) Wait 0.01 Until bo Copy appoggio To "/tmp" &/ File.BaseName(fileaudio) & ".wav" pl.Stop pl.Close Print "\n\e[0mConversione terminata !" End Public Sub PLine_End() bo = True End