• 大小: 16.36MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-08-05
  • 语言: C#
  • 标签: C#  M3U8  

资源简介

C#调用FFMPEG转视频文件为M3U8,命令行调用

资源截图

代码片段和文件信息

using System;
using System.IO;
using System.Text.Regularexpressions;

namespace ConvertToM3u8
{
    class Program
    {
        static void Main(string[] args)
        {
           /*
            var source = Environment.CurrentDirectory + “\\blank.mp4“;
            var fi=new FileInfo(source);

            StreamReader sr = File.OpenText(Environment.CurrentDirectory+“\\guid.txt“);
            string str = ““;
            string text = ““;
            int num = 0;
            while ((str = sr.ReadLine()) != null)
            {
                str = Regex.Replace(str @“^[ \t]*|[ \t]*$“ “ “);
                fi.CopyTo(Environment.CurrentDirectory + “\\Source\\“ + str.Replace(“ “““) + “.mp4“);
            }
            sr.Close();
            Console.WriteLine(“ok!“);
            Console.ReadKey();
            return;*/

            if (args == null) throw new ArgumentNullException(nameof(args));
            //创建目录
            var targetPath = Environment.CurrentDirectory + “\\Target\\Preview“;
            var tdi=new DirectoryInfo(targetPath);
            if(!tdi.Exists)tdi.Create();

            targetPath = Environment.CurrentDirectory + “\\Target\\M3u8“;
            tdi = new DirectoryInfo(targetPath);
            if (!tdi.Exists) tdi.Create();

            targetPath = Environment.CurrentDirectory + “\\Target\\Thumbs“;
            tdi = new DirectoryInfo(targetPath);
            if (!tdi.Exists) tdi.Create();


            //开始转换
            var sourcePath = Environment.CurrentDirectory + “\\Source“;
            var sdi=new DirectoryInfo(sourcePath);
            for (var i = 0; i < sdi.GetFiles().Length; i++)
            {
                var f = sdi.GetFiles()[i];
                var topTwo = f.Name.Substring(0 2).ToUpper();
               
                
                //生成flv
                var d = new DirectoryInfo(Environment.CurrentDirectory + “\\Target\\Preview\\“ + topTwo);
                if (!d.Exists) d.Create();
                var tflv =new FileInfo( d.FullName + “\\“ + f.Name.Substring(0 36) + “.flv“);
                if (!tflv.Exists)
                {
                    VideoUtil.ConvertFlv(f.FullName tflv.FullName);
                }

                //生成缩略图
                var dThumbs = new DirectoryInfo(Environment.CurrentDirectory + “\\Target\\Thumbs\\“ + topTwo);
                if (!dThumbs.Exists) dThumbs.Create();

                var fThumbs = new FileInfo(dThumbs.FullName + “\\“ + f.Name.Substring(0 36) + “.thumb“);
                if (!fThumbs.Exists)
                {
                    VideoUtil.GetImage(tflv.FullName fThumbs.FullName 160 120);
                }

                //生成m3u8
                d = new DirectoryInfo(Environment.CurrentDirectory + “\\Target\\M3u8\\“ + topTwo);
                if (!d.Exists) d.Create();
                var tm3u8 = new FileInfo(d.FullName + “\\“ + f.Name.Substring(0 36) + “.m3u8“);
    

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

    ..A..H.     48128  2016-03-05 21:28  ConvertToM3u8\.vs\ConvertToM3u8\v14\.suo

     文件        189  2015-12-26 10:48  ConvertToM3u8\App.config

     文件       9216  2016-03-05 20:41  ConvertToM3u8\bin\Debug\ConvertToM3u8.exe

     文件        189  2015-12-26 10:48  ConvertToM3u8\bin\Debug\ConvertToM3u8.exe.config

     文件      19968  2016-03-05 20:41  ConvertToM3u8\bin\Debug\ConvertToM3u8.pdb

     文件      22696  2016-03-05 20:46  ConvertToM3u8\bin\Debug\ConvertToM3u8.vshost.exe

     文件        189  2015-12-26 10:48  ConvertToM3u8\bin\Debug\ConvertToM3u8.vshost.exe.config

     文件        490  2015-10-30 15:19  ConvertToM3u8\bin\Debug\ConvertToM3u8.vshost.exe.manifest

     文件   12246427  2015-12-26 10:48  ConvertToM3u8\bin\Debug\ffmpeg\avcodec-52.dll

     文件   22247936  2015-12-26 10:48  ConvertToM3u8\bin\Debug\ffmpeg\avcodec-56.dll

     文件    1380352  2015-12-26 10:48  ConvertToM3u8\bin\Debug\ffmpeg\avdevice-56.dll

     文件    2386432  2015-12-26 10:48  ConvertToM3u8\bin\Debug\ffmpeg\avfilter-5.dll

     文件    4099457  2015-12-26 10:48  ConvertToM3u8\bin\Debug\ffmpeg\avformat-52.dll

     文件    6021632  2015-12-26 10:48  ConvertToM3u8\bin\Debug\ffmpeg\avformat-56.dll

     文件      73728  2015-12-26 10:48  ConvertToM3u8\bin\Debug\ffmpeg\avutil-50.dll

     文件     495104  2015-12-26 10:48  ConvertToM3u8\bin\Debug\ffmpeg\avutil-54.dll

     文件     330752  2015-12-26 10:48  ConvertToM3u8\bin\Debug\ffmpeg\ffmpeg.exe

     文件     476160  2015-12-26 10:48  ConvertToM3u8\bin\Debug\ffmpeg\ffplay.exe

     文件     155648  2015-12-26 10:48  ConvertToM3u8\bin\Debug\ffmpeg\ffprobe.exe

     文件     131584  2015-12-26 10:48  ConvertToM3u8\bin\Debug\ffmpeg\postproc-53.dll

     文件     281600  2015-12-26 10:48  ConvertToM3u8\bin\Debug\ffmpeg\swresample-1.dll

     文件     487424  2015-12-26 10:48  ConvertToM3u8\bin\Debug\ffmpeg\swscale-3.dll

     文件       6236  2016-01-15 17:53  ConvertToM3u8\bin\Debug\guid.txt

     文件     556575  2015-12-26 10:48  ConvertToM3u8\bin\Debug\pngquant.exe

     文件     682655  2016-01-15 16:52  ConvertToM3u8\bin\Debug\Source\blank.mp4

     文件          0  2016-03-06 06:59  ConvertToM3u8\bin\Debug\新建 文本文档.txt

     文件       2768  2016-01-15 17:48  ConvertToM3u8\ConvertToM3u8.csproj

     文件        992  2015-12-26 12:07  ConvertToM3u8\ConvertToM3u8.sln

     文件       1063  2016-03-05 21:24  ConvertToM3u8\obj\Debug\ConvertToM3u8.csproj.FileListAbsolute.txt

     文件       1922  2015-12-26 10:54  ConvertToM3u8\obj\Debug\ConvertToM3u8.csprojResolveAssemblyReference.cache

............此处省略27个文件信息

评论

共有 条评论