m3u8及TS文件下载解稀:用FFmpeg解稀兼并m3u8中ts文件 1-3选集 Error when loading first segment ‘x.ts’m3u8及TS文件下载解稀:用FFmpeg解稀兼并m3u8中ts文件 1-3选集 Error when loading first segment ‘x.ts’ FFMPEG的根本号令
用FFMPEG去解稀兼并转化TS文件,网上有很多多少种写法,好比: ffmpeg -protocol_whitelist “file,http,crypto,tcp” -i index.m3u8 -c copy out.ts ffmpeg -allowed_extensions ALL -i index.m3u8 -c copy new.mp4 ffmpeg -allowed_extensions ALL -i index1.m3u8 -c copy -bsf:a aac_adtstoasc index.mp4 等。我间接用的中心那个就能够了。 String m3u8file = textBox5.Text;
var tool = @“ffmepg.exe”;
var command = ” -allowed_extensions ALL -i ” + m3u8file + ” -c copy ” + textBox8.Text + “\out.mp4 -y”;
using (var p = new Process())
{
RedirectExcuteProcess(p, tool, command, (s, e) => ShowDecodeInfo(m3u8file, e.Data));
} 碰到过的奇异成绩
正在号令止挪用FFMPEG时,呈现毛病
Unrecognized option ‘copy’.
Error splitting the argument list: Option not found
m3u8及TS文件下载解稀
不断找没有到缘故原由。厥后才发明是从网上间接拷的号令,此中的 -号是齐角的,也便是正在汉字输进形态下输进的,没有是英文输进法下的 -。网上各人皆是拷去拷来的,有成绩,从头自止输进-标记,号令就能够一般施行。 M3U8文件格局
下载下去的m3u8翻开后最典范的以下图:
m3u8及TS文件下载解稀
具体的格局比力庞大,只便上述字段停止形貌: The basic commands of FFMPEG use FFMPEG to decrypt, merge and transform TS files. There are many ways to write on the Internet, such as: ffmpeg -protocol_whitelist “file,http,crypto,tcp” -i index.m3u8 -c copy out.tsffmpeg -allowed_extensions ALL -i index .m3u8 -c copy new.mp4ffmpeg -allowed_extensions ALL -i index1.m3u8 -c copy -bsf:a aac_adtstoasc index.mp4 etc. I just use the middle one directly.
String m3u8file = textBox5.Text;var tool = @”ffmepg.exe”;var command = “-allowed_extensions ALL -i” + m3u8file + “-c copy” + textBox8.Text + “\out.mp4 -y”;using (var p = new Process())
{RedirectExcuteProcess(p, tool, command, (s, e) => ShowDecodeInfo(m3u8file, e.Data));} Strange problems encountered when calling FFMPEG from the command line, an error Unrecognized option ‘copy’ appears.
Error splitting the argument list: Option not found The reason has not been found. Later, I discovered that the command was copied directly from the Internet, and the-sign was full-width, that is, it was entered in the state of Chinese character input, not the English input method -. Everyone on the Internet is copying it back and forth. If there is a problem, enter the-symbol again, and the command can be executed normally.
The most typical m3u8 downloaded in the M3U8 file format is as shown in the figure below: The detailed format is more complicated, and only the above fields are described: EXTM3U start identification. The first line of each M3U file must be this.
EXT-X-VERSION: The 3EXT-X-VERSION tag indicates the adaptability of the playlist version. Playlist files, their associated media and servers must comply with all regulations of the latest version.
The use of IV in the EXT-X-KEY tag must specify that the version number of the protocol is 2 (what is the IV, see the EXT-X-KEY part below)
The value of the floating-point number used in EXTINF must specify the protocol version number is 3 Use EXT-X-BYTERANGE and EXT-X-IFRAME-ONLY flags must specify the version number of the protocol is 4 Use SAMPLE-AES in the EXT-X-KEY tag The version of the protocol must be specified as 5EXT-X-TARGETDURATION: S is an integer in seconds.
The tag specifies the maximum duration of the media file, and the duration defined in the EXTINF tag of the media file in the play file list must be less than or equal to the duration specified by the tag. The tag must appear once in the playlist file.
EXT-X-MEDIA-SEQUENCE defines the sequence number of the first file in the current m3u8 file. It seems useless.
EXT-X-KEY defines the encryption method and the url of the key file, which is used to obtain the 16bytes key file to decode the ts file.
Attribute: METHOD, encryption method, generally AES-128URL, the address of the key file IV, AES decryption algorithm, there can be two parameters Key and IV, IV is the initialization variable of the AES algorithm CBC encryption mode, the default is 16 0 , You can set other values.
EXTINF specifies the duration of each media segment (ts), this is only valid for the following URI, which is the specific video file.
EXT-X-ENDLIST indicates the end of the m3u8 file. The live m3u8 does not have this tag.
Tool download TSMatser is a download decryption tool for m3u8 and TS files, CKplayer video files.
The tool can automatically parse key files and ts files.
Other tools to download ts can use other tools to download ts files, such as the resource sniffer of the travel browser, after sniffing, filtering and downloading ts files.
You can also use VLC Player to input the m3u8 address directly, then you can play and download.
Multi-threaded download TS file aria2c download TS file aria2c is a utility for downloading files. Support HTTP(S), FTP, SFTP, BitTorrent, and Metalink protocols. We can call aria2c to download specific TS files.
Specific c# code: var url = this.cururlpath + curdownfile;var tool = @”aria2c.exe”;var fi = new FileInfo(textBox6.Text + “\” + textBox9.Text + “\” + curdownfile);var command = “-c -s 10 -x 10 –file-allocation=none –check-certificate=false -d” + fi.DirectoryName + “-o” + fi.Name + “” + url;//Console. WriteLine(command);using (var p = new Process())
{undefinedRedirectExcuteProcess(p, tool, command, (s, e) => ShowDownInfo(i,url, e.Data));} Based on the returned output in the ShowDownInfo callback function, make a corresponding judgment: if (a == null ) return;const string re1 = “.*?”; // Non-greedy match on fillerconst string re2 = “(\\(.*\\))”; // Round Braces 1var r = new Regex(re1 + re2 , RegexOptions.IgnoreCase | RegexOptions.Singleline);var m = r.Match(a);if (m.Success)
{var rbraces1 = m.Groups[1].ToString().WordStr(“(“, “”).WordStr(“)”, “”).WordStr(“%”, “”).WordStr(“s” , “0”);if (rbraces1 == “OK”)
{listView1.BeginUpdate();listView1.Items[itemidx].SubItems[1].Text = “Downloaded”;listView1.EndUpdate();this.Invoke(new Action(() => {label20.Text = “Already Download “+ (downfilescnt + 2) + “/” + listView1.Items.Count; }));}//label20.Text = DateTime.Now.ToString().WordStr(“/”, “-“) +” “+ url +” Download progress: “+ rbraces1 + “%”; Multi-threaded downloading In order to improve the download speed, a thread pool is used to call the downloader.
For (int i = 0; i <thStepCount; i++)
{undefinedthStep = new Thread(threaddownloadfiles);thStep.Name = i.ToString();thStep.Start();} Thread synchronization problem. Multiple threads simultaneously call aria2c to the m3u8 file All TS files are downloaded. In order to ensure that the work of each thread is not repeated or omitted, a synchronization mechanism is required. At first, I wanted to use lock to achieve it. I found it more troublesome. Later, I changed to a more clumsy way to count the total number of TS files and follow the threads. Numbers are allocated, and each completes the download tasks within their own allocation range: if (Thread.CurrentThread.Name.Equals(“0”)) //Files processed by thread 1 {undefinedstartpos = 0; endpos = listView1.Items.Count / 3 ;}else if (Thread.CurrentThread.Name.Equals(“1”)) //File processed by thread 2 {startpos = listView1.Items.Count / 3; endpos = listView1.Items.Count * 2 / 3;}else if (Thread.CurrentThread.Name.Equals(“2″)) //Files processed by thread 3 {startpos = listView1.Items.Count * 2 / 3; endpos = listView1.Items.Count;}for (int i = startpos ; i <endpos; i++)
{Undefined//Call the downloaded function;} Tool Download TSMatser is a m3u8 and TS file, CKplayer video file download decryption tool. When downloading key files and ts files, multi-threading technology is used, and aria2c is called for downloading.
EXTM3U
开端标识。每一个M3U文件第一止必需是那个。 EXT-X-VERSION:3
EXT-X-VERSION标签指出了播放列表版本的顺应性。播放列表文件、其联系关系的媒体战效劳器必需服从最新版本的一切划定。
正在EXT-X-KEY标识表记标帜中利用IV必需指定和谈的版本号是2(IV是啥,看前面的EXT-X-KEY部门)
正在EXTINF中利用浮面数的值必需指定和谈版本号是3
利用 EXT-X-BYTERANGE 战 EXT-X-IFRAME-ONLY标识表记标帜必需指定和谈的版本号是4
正在EXT-X-KEY标识表记标帜中利用SAMPLE-AES必需指定和谈的版本是5 EXT-X-TARGETDURATION:
S是一个以秒为单元的整数。
该标签指定了媒体文件连续工夫的最年夜值,播放文件列表中的媒体文件正在EXTINF标签中界说的连续工夫必需小于大概即是该标签指定的连续工夫。该标签正在播放列表文件中必需呈现一次。 EXT-X-MEDIA-SEQUENCE
界说当前m3u8文件中第一个文件的序列号。仿佛出啥用。 EXT-X-KEY
界说减稀方法战key文件的url,用于获得16bytes的key文件解码ts文件。
属性:
METHOD,减稀方法,通常为AES-128
URL, 稀钥文件的地点
IV,AES解稀算法中,能够有 Key 战 IV 两个参数,IV是AES算法CBC减稀形式的初初化变量,默许是16个0,能够设置其他值。 EXTINF
指定每一个媒体段(ts)的连续工夫,那个仅对厥后里的URI有用,前面的URI便是详细的视频文件。 EXT-X-ENDLIST
表白m3u8文件的完毕。曲播的m3u8出有该tag。 东西下载
TSMatser是一个m3u8及TS文件、CKplayer视频文件下载解稀东西。
东西可主动剖析key文件战ts文件。
其他东西下载ts
能够用其他东西下载ts文件,好比翱翔阅读器的资本嗅探器,嗅探后挑选下载ts文件。 也能够用VLC Player间接输进m3u8地点,就能够播放下载了。
多线程下载TS文件
aria2c下载TS文件
aria2c 是一个用去下载文件的适用法式。撑持HTTP(S), FTP, SFTP, BitTorrent,战Metalink和谈。我们能够挪用aria2c去下载详细的TS文件。 详细c#代码:
var url = this.cururlpath + curdownfile;
var tool = @“aria2c.exe”;
var fi = new FileInfo(textBox6.Text + “\” + textBox9.Text + “\” + curdownfile);
var command = ” -c -s 10 -x 10 –file-allocation=none –check-certificate=false -d ” + fi.DirectoryName + ” -o ” + fi.Name + ” ” + url;
//Console.WriteLine(command);
using (var p = new Process())
{undefined
RedirectExcuteProcess(p, tool, command, (s, e) => ShowDownInfo(i,url, e.Data));
} 正在ShowDownInfo回调函数中基于返回的输出,停止响应的判定:
if (a == null) return; const string re1 = “.*?”; // Non-greedy match on filler
const string re2 = “(\\(.*\\))”; // Round Braces 1 var r = new Regex(re1 + re2, RegexOptions.IgnoreCase | RegexOptions.Singleline);
var m = r.Match(a);
if (m.Success)
{
var rbraces1 = m.Groups[1].ToString().WordStr(“(“, “”).WordStr(“)”, “”).WordStr(“%”, “”).WordStr(“s”, “0”);
if (rbraces1 == “OK”)
{
listView1.BeginUpdate();
listView1.Items[itemidx].SubItems[1].Text = “已下载”;
listView1.EndUpdate();
this.Invoke(new Action(() => { label20.Text = “已下载” + (downfilescnt + 2) + “/” + listView1.Items.Count; })); }
//label20.Text = DateTime.Now.ToString().WordStr(“/”, “-“) + ” ” + url + ” 下载进度:” + rbraces1 + “%”; 多线程下载
为了进步下载速率,利用了线程池,去挪用下载法式。 for (int i = 0; i < thStepCount; i++)
{undefined
thStep = new Thread(threaddownloadfiles);
thStep.Name = i.ToString();
thStep.Start();
} 线程的同步成绩
多个线程同时挪用aria2c对m3u8文件中的一切TS文件停止下载,为了包管各线程的事情没有反复,没有漏掉,需求有同步机造,最开端念用lock去完成,发明比力费事,厥后改用比力笨的方法,统计TS文件总数,根据线程数停止分派,各自完成本人分派范畴内乱的下载使命: if (Thread.CurrentThread.Name.Equals(“0”)) //线程1处置的文件
{undefined
startpos = 0; endpos = listView1.Items.Count / 3; }
else if (Thread.CurrentThread.Name.Equals(“1”)) //线程2处置的文件
{
startpos = listView1.Items.Count / 3; endpos = listView1.Items.Count * 2 / 3;
}
else if (Thread.CurrentThread.Name.Equals(“2”)) //线程3处置的文件
{
startpos = listView1.Items.Count * 2 / 3; endpos = listView1.Items.Count;
} for (int i = startpos; i < endpos; i++)
{undefined
//挪用下载的函数;
} 东西下载
TSMatser是一个m3u8及TS文件、CKplayer视频文件下载解稀东西。下载key文件战ts文件时接纳了多线程手艺,挪用aria2c停止下载。 以上不克不及处理成绩 Error when loading first segment ‘x.ts’ 但仍旧珍藏
参考 https://cdnjson.com/v2ex/thread-1574-1-1.html
|