如何把夸克瀏覽器下載的m3u8影片流小電影轉換為MP4格式

老马识途远發表於2024-09-20

檢視了存放目錄,影片流快取片段資料的存放格式: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

相關文章