如何把夸克浏览器下载的m3u8视频流小电影转换为MP4格式
查看了存放目录,视频流缓存片段数据的存放格式:0、1、2、3、4....10、11、12....序列是视频缓存片段,0.key是AES解密密钥,32位长的文件名存了原始下载的链接信息,可以不考虑。
参见下面代码,可以将片段文件合成MP4视频文件
string fName=""; string fFullName = ""; string fPathName = ""; string fExtName = ""; string fFileNameWithoutExtension = ""; string newName = ""; OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.InitialDirectory= sInitialDirectory ; ;//注意这里写路径时要用c:\\而不是c:\ openFileDialog.Filter = "视频片段文件|*|视频片段ts文件|*.ts|所有文件|*.*"; openFileDialog.RestoreDirectory = true; openFileDialog.FilterIndex = 1; if (openFileDialog.ShowDialog() == DialogResult.OK) { fFullName = openFileDialog.FileName; fPathName = Path.GetDirectoryName(fFullName); fFileNameWithoutExtension = Path.GetFileNameWithoutExtension(fFullName); //-->test fName = Path.GetFileName(fFullName); fExtName= Path.GetExtension(fFullName); textBox1.Text = ""; DirectoryInfo root = new DirectoryInfo(fPathName); FileInfo[] files = root.GetFiles(); foreach (FileInfo f in files) { if (f.Extension == ".key") continue; fFullName = f.FullName; fPathName = Path.GetDirectoryName(fFullName); fFileNameWithoutExtension = Path.GetFileNameWithoutExtension(fFullName); //-->test fName = Path.GetFileName(fFullName); fExtName = Path.GetExtension(fFullName); sInitialDirectory= Path.GetDirectoryName(fFullName); try { newName = (10000 + int.Parse(fFileNameWithoutExtension)).ToString(); if (fExtName == "") { fExtName = ".ts"; File.Move(fFullName, fPathName + "\\" + newName + fExtName); fFullName = fPathName + "\\" + newName + fExtName; } AesDecyptFile(fFullName, fPathName+ "\\0.key"); } catch( Exception ex ) { textBox1.Text +="发生错误:" +ex.Message; }; } string put = Cmd.RunCmd("copy /Y /b "+ fPathName + "\\*.ts.mp4 "+ fPathName + "\\_new_.mp4"); //执行命令 // Console.WriteLine(put); //控制台输出返回结果 textBox1.Text += put; if (File.Exists(fPathName + "\\_new_.mp4")) { put = Cmd.RunCmd("del " + fPathName + "\\*.ts.mp4"); //执行命令 // Console.WriteLine(put); //控制台输出返回结果 textBox1.Text += put; put = Cmd.RunCmd("del " + fPathName + "\\*.ts"); //执行命令 // Console.WriteLine(put); //控制台输出返回结果 textBox1.Text += put; } }
点击下面链接下载可执行文件
https://files.cnblogs.com/files/blogs/826051/m3u8文件转MP4.rar?t=1726790517&download=true