C#/.Net은 ts 파일을 처리하고 ts 파일을 mp4 형식으로 병합합니다.

먼저 렌더링을 첨부합니다.

처리 논리: 먼저 mp4 스트림 파일을 생성한 다음 탐색하여 폴더의 모든 ts 파일을 얻은 다음 ts 파일 스트림을 mp4 파일 스트림에 추가합니다.

private void btnRun_Click(object sender, EventArgs e)
        {
            string filePath = this.txtFilePath.Text.ToString();
            string outName = this.txtOutName.Text.ToString();
            string outPath = Path.Combine(this.txtOutPath.Text.ToString(),outName);
            using (FileStream reader = new FileStream(outPath, FileMode.OpenOrCreate, FileAccess.ReadWrite))
            {

                var files = Directory.GetFiles(filePath, "*.ts");
                List<string> fileList=new List<string>(files);
                fileList.Sort(
                    (x,y)=>{
                        int indexX =Convert.ToInt32(x.Remove(x.IndexOf(".ts")).Substring(x.LastIndexOf(@"\")+1));
                        int indexY = Convert.ToInt32(y.Remove(y.IndexOf(".ts")).Substring(y.LastIndexOf(@"\") + 1));
                        if (indexX > indexY)
                            return 1;
                        else if (indexX < indexY)
                            return -1;
                        else
                            return 0;
                });
                foreach (var item in fileList)
                {
                    using (FileStream readStream=new FileStream(item,FileMode.Open,FileAccess.Read))
                    {
                        readStream.CopyTo(reader);
                    }
                }
               
            }
        }

 

Supongo que te gusta

Origin blog.csdn.net/weixin_45091053/article/details/128745703
Recomendado
Clasificación