Convertire un file video in un altro formato mediante il Componente gb.media
Da Gambas-it.org - Wikipedia.
Indice
Convertire un file video nel formato OGG
Ottenere una conversione in formato OGG con audio
Si otterrà un file video del formato OGG, ma con audio, se il file originario è un file audio/video:
Private bo As Boolean Public Sub Main() Dim pl As MediaPipeline Dim src, vdcb, tee, vcon, the, adcb, acon, vor, ogg, snk As MediaControl Dim que1, que2, que3 As MediaControl pl = New MediaPipeline As "PLine" src = New MediaControl(pl, "filesrc") src["location"] = "/percorso/del/file/video" tee = New MediaControl(pl, "tee") vdcb = New MediaControl(pl, "decodebin") que1 = New MediaControl(pl, "queue") vcon = New MediaControl(pl, "videoconvert") the = New MediaControl(pl, "theoraenc") adcb = New MediaControl(pl, "decodebin") que2 = New MediaControl(pl, "queue") acon = New MediaControl(pl, "audioconvert") vor = New MediaControl(pl, "vorbisenc") que3 = New MediaControl(pl, "queue") ogg = New MediaControl(pl, "oggmux") snk = New MediaControl(pl, "filesink") snk["location"] = "/tmp/video.ogg" ' Parte video: src.LinkTo(tee) tee.LinkTo(vdcb) vdcb.LinkLaterTo(que1) que1.LinkTo(vcon) vcon.LinkTo(the) the.LinkTo(ogg) ' Parte audio: tee.LinkTo(adcb) adcb.LinkLaterTo(que2) que2.LinkTo(acon) acon.LinkTo(vor) vor.LinkTo(que3) ' Combinazione dei dati audio e video: que3.LinkTo(ogg) ' Creazione del file ogg finale: ogg.LinkTo(snk) ' Avvia la conversione audio-video: pl.Play() While pl.Duration < 1 Wait 0.01 Wend Print "Durata del file video: "; Time(0, 0, 0, pl.Duration * 1000) While Not bo Write "\r\e[0mTempo trascorso: \e[31m" & Time(0, 0, 0, pl.Position * 1000) Wait 0.01 Wend pl.Stop() pl.Close() Print "\n\e[0mConversione terminata !" Quit End Public Sub PLine_End() bo = True End
Ottenere una conversione in formato OGG senza audio
Si otterrà un file video del formato OGG, ma privo di audio:
Private pl As MediaPipeline Private bo As Boolean Public Sub Main() Dim src, dcb, vdc, enc, mux, snk As MediaControl pl = New MediaPipeline As "PLine" src = New MediaControl(pl, "filesrc") src["location"] = "/percorso/del/file/video" dcb = New MediaControl(pl, "decodebin") vdc = New MediaControl(pl, "videoconvert") enc = New MediaControl(pl, "theoraenc") mux = New MediaControl(pl, "oggmux") snk = New MediaControl(pl, "filesink") snk["location"] = "/tmp/video.ogg" src.LinkTo(dcb) dcb.LinkLaterTo(vdc) vdc.LinkTo(enc) enc.LinkTo(mux) mux.LinkTo(snk) pl.Play() While pl.Duration < 1 Wait 0.01 Wend Print "Durata del file video: "; Time(0, 0, 0, pl.Duration * 1000) While Not bo Write "\r\e[0mTempo trascorso: \e[31m" & Time(0, 0, 0, pl.Position * 1000) Wait 0.01 Wend pl.Close Print "\n\e[0mConversione terminata !" Quit End Public Sub PLine_End() bo = True End
Convertire un file video senza audio nel formato Matroska
Si otterrà un file video del formato Matroska, ma privo di audio:
Private pl As MediaPipeline Private bo As Boolean Public Sub Main() Dim src, dcb, vdc, enc, mux, snk As MediaControl pl = New MediaPipeline As "PLine" src = New MediaControl(pl, "filesrc") src["location"] = "/percorso/del/file/video" dcb = New MediaControl(pl, "decodebin") vdc = New MediaControl(pl, "videoconvert") enc = New MediaControl(pl, "x264enc") mux = New MediaControl(pl, "matroskamux") snk = New MediaControl(pl, "filesink") snk["location"] = "/tmp/video.mkv" src.LinkTo(dcb) dcb.LinkLaterTo(vdc) vdc.LinkTo(enc) enc.LinkTo(mux) mux.LinkTo(snk) pl.Play() While pl.Duration < 1 Wait 0.01 Wend Print "Durata del file video: "; Time(0, 0, 0, pl.Duration * 1000) While Not bo Write "\r\e[0mTempo trascorso: \e[31m" & Time(0, 0, 0, pl.Position * 1000) Wait 0.01 Wend pl.Close Print "\n\e[0mConversione terminata !" Quit End Public Sub PLine_End() bo = True End
Convertire un file video senza audio nel formato MP4
Si otterrà un file video del formato MP4, ma privo di audio:
Private pl As MediaPipeline Private bo As Boolean Public Sub Main() Dim src, dcb, vdc, enc, mux, snk As MediaControl pl = New MediaPipeline As "PLine" src = New MediaControl(pl, "filesrc") src["location"] = "/percorso/del/file/video" dcb = New MediaControl(pl, "decodebin") vdc = New MediaControl(pl, "videoconvert") enc = New MediaControl(pl, "x264enc") mux = New MediaControl(pl, "mp4mux") snk = New MediaControl(pl, "filesink") snk["location"] = "/tmp/video.mp4" src.LinkTo(dcb) dcb.LinkLaterTo(vdc) vdc.LinkTo(enc) enc.LinkTo(mux) mux.LinkTo(snk) pl.Play() While pl.Duration < 1 Wait 0.01 Wend Print "Durata del file video: "; Time(0, 0, 0, pl.Duration * 1000) While Not bo Write "\r\e[0mTempo trascorso: \e[31m" & Time(0, 0, 0, pl.Position * 1000) Wait 0.01 Wend pl.Close Print "\n\e[0mConversione terminata !" Quit End Public Sub PLine_End() bo = True End
Convertire un file video senza audio nel formato RAW
Si otterrà un file video del formato RAW, ma privo di audio:
Private pl As MediaPipeline Private bo As Boolean Public Sub Main() Dim src, dcb, vdc, enc, mux, snk As MediaControl pl = New MediaPipeline As "PLine" src = New MediaControl(pl, "filesrc") src["location"] = "/percorso/del/file/video" dcb = New MediaControl(pl, "decodebin") vdc = New MediaControl(pl, "videoconvert") enc = New MediaControl(pl, "x264enc") enc["speed-preset"] = 6 enc["bitrate"] = 1024 mux = New MediaControl(pl, "mpegtsmux") snk = New MediaControl(pl, "filesink") snk["location"] = "/tmp/video.raw" src.LinkTo(dcb) dcb.LinkLaterTo(vdc) vdc.LinkTo(enc) enc.LinkTo(mux) mux.LinkTo(snk) pl.Play() While pl.Duration < 1 Wait 0.01 Wend Print "Durata del file video: "; Time(0, 0, 0, pl.Duration * 1000) While Not bo Write "\r\e[0mTempo trascorso: \e[31m" & Time(0, 0, 0, pl.Position * 1000) Wait 0.01 Wend pl.Close Print "\n\e[0mConversione terminata !" Quit End Public Sub PLine_End() bo = True End