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

前端之家收集整理的这篇文章主要介绍了视频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
原文链接:https://www.f2er.com/vb/257236.html

猜你在找的VB相关文章