视频m3u8文件转ts视频,vb.net源码(各小段视频下载合并)

Imports System.IO
Imports System.Threading
Imports System.Text.RegularExpressions

Public Class Form1
    Dim mythread As Thread
    Dim strWebFile() As String
    Dim Flag As String

    Private Sub btnChange_Click(sender As Object, e As EventArgs) Handles btnChange.Click
        Dim i As Integer, j As Integer, myfile As String, strAllfile() As String

        lblState.Text = "检测目录..."
        Dim fi As New DirectoryInfo("D:\Open21\") '创建两个目录
        If Not fi.Exists Then
            fi.Create()
        End If
        fi = Nothing
        fi = New DirectoryInfo("D:\Open21\1\")
        If Not fi.Exists Then
            fi.Create()
        End If

        dlgOpen.Multiselect = True                      '输入m3u8原始文件
        dlgOpen.Filter = "m3u8 files (*.m3u8)|*.m3u8"
        If dlgOpen.ShowDialog = Windows.Forms.DialogResult.OK Then
            strAllFile = dlgOpen.FileNames.ToArray
        Else
            Exit Sub
        End If

        lblState.Text = "逐个文件分析...."
        For i = 0 To strAllfile.GetUpperBound(0)

            Dim fso As New StreamReader(strAllfile(i))  '逐个m3u8文件读取
            Dim strTemp As String = fso.ReadToEnd

            lblState.Text = "提取服务器上各小TS地址"
            Dim reg As New Regex("http:[^,]*.ts")       '提取服务器上各小TS地址
            For j = 1 To reg.Matches(strTemp).Count
                ReDim Preserve strWebFile(j - 1)
                strWebFile(j - 1) = reg.Matches(strTemp)(j - 1).Value
            Next

            For j = 0 To strWebFile.GetUpperBound(0)    '下载各小Ts文件
                Flag = "down"
                lblState.Text = "下载第" & i + 1 & "个文件中第" & j + 1 & "号ts视频文件..."
                mythread = New Thread(AddressOf DownFile)
                mythread.Start(j)

                Do While Flag = "down"
                    Application.DoEvents()
                Loop
            Next

            lblState.Text = "第" & i & "个文件全部小ts下载完成!"
            Dim file As New FileInfo(strAllfile(i))
            myfile = "D:\Open21\" & Replace(file.Name, ".m3u8", "") & ".ts"
            '合并
            j = Shell("cmd /c copy /b D:\Open21\1\*.ts  """ & myfile & """", vbNormalFocus) ', vbHide)
            System.Threading.Thread.Sleep(60000) '等待6秒,上面基本合并完成
            Kill("D:\Open21\1\*.ts") '删除
        Next
    End Sub

    Private Sub DownFile(ByVal n As Integer)
        My.Computer.Network.DownloadFile(strWebFile(n), "D:\Open21\1\" & n + 1 & ".ts")

        Flag = "stop"
        mythread.Abort()
    End Sub

End Class

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值