广州高端网站定制开发价格,管理咨询师考试,滕州网站建设助企网络,嘉兴城乡建设局网站获取上传视频的尺寸#xff1a;
获取视频尺寸通常需要借助第三方库FFmpeg。
首先#xff0c;确保你的系统中已安装了FFmpeg#xff0c;并且FFmpeg的可执行文件路径已经添加到你的系统环境变量中。
1.官网下载ffmpeg
进入 链接: ffmpeg官网 网址#xff0c;点击下载wind…获取上传视频的尺寸
获取视频尺寸通常需要借助第三方库FFmpeg。
首先确保你的系统中已安装了FFmpeg并且FFmpeg的可执行文件路径已经添加到你的系统环境变量中。
1.官网下载ffmpeg
进入 链接: ffmpeg官网 网址点击下载windows版ffmpeg点击左下第一个绿色的行 选择标注红框的其中一个进行下载
2.配置
下载完成后赋值路径进行环境变量配置
找到环境变量 配置在Path中
3、实例
然后你可以使用如下代码来获取视频的详细信息包括尺寸 public static (int width, int height) GetVideoSize(string videoPath){var startInfo new ProcessStartInfo{FileName ffmpeg,Arguments $-i {videoPath} -hide_banner,RedirectStandardOutput true,RedirectStandardError true,UseShellExecute false,CreateNoWindow true};// 创建process 对象并关联ProcessStartInfo// 启动进程using (var process Process.Start(startInfo)){// 等待进程执行完毕process.WaitForExit();// 读取命令的输出结果string output process.StandardError.ReadToEnd();// 正则表达式匹配视频尺寸var match Regex.Match(output, Video: . (\d{2,})x(\d{2,}));if (match.Success){int width int.Parse(match.Groups[1].Value);int height int.Parse(match.Groups[2].Value);return (width, height);}}return (0, 0);}}其中 videoPath 指的是视频文件地址
4、 其他
当你环境配置好其实也可以自己可以测试一下自己的命令是否正确 winR ——》 cmd可以看看这个命令符返出来什么 videoPath指的是视频文件的地址
ffmpeg -i {videoPath} -hide_banner