- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在努力使用 FFMPEG 获取视频的长度/持续时间。下面是我从谷歌获得的代码,但是当我运行该方法时它返回空字符串。做了我能做的任何调整,但没有成功。谁能指导我这里出了什么问题?
private static void GetVideoDuration()
{
string basePath = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar;
string filePath = basePath + @"1.mp4";
string cmd = string.Format("-v error -select_streams v:0 -show_entries stream=duration -of default=noprint_wrappers=1:nokey=1 {0}", filePath);
Process proc = new Process();
proc.StartInfo.FileName = Path.Combine(basePath, @"ffprobe.exe");
proc.StartInfo.Arguments = cmd;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.UseShellExecute = false;
if (!proc.Start())
{
Console.WriteLine("Error starting");
return;
}
StreamReader reader = proc.StandardError;
string line;
while ((line = reader.ReadToEnd()) != null)
{
Console.WriteLine(line);
}
proc.Close();
}
最佳答案
谢谢大家,我得到了答案。
似乎 ffprobe 没有使用
返回输出proc.StandardError;
但使用
proc.StandardOutput;
上面的语句适用于 ffmpeg,但不适用于 ffprobe,下面的语句适用于 ffprobe。这是工作示例,以备不时之需。
private static void GetVideoDuration()
{
string basePath = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar;
string filePath = basePath + @"1.mp4";
string cmd = string.Format("-v error -select_streams v:0 -show_entries stream=duration -sexagesimal -of default=noprint_wrappers=1:nokey=1 {0}", filePath);
Process proc = new Process();
proc.StartInfo.FileName = Path.Combine(basePath, @"ffprobe.exe");
proc.StartInfo.Arguments = cmd;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.UseShellExecute = false;
if (!proc.Start())
{
Console.WriteLine("Error starting");
return;
}
string duration = proc.StandardOutput.ReadToEnd().Replace("\r\n", "");
// Remove the milliseconds
duration = duration.Substring(0, duration.LastIndexOf("."));
proc.WaitForExit();
proc.Close();
}
以上方法将以 hh:mm:ss.fff tt 格式返回您的持续时间,意味着包括毫秒,但如果您想要以秒为单位的持续时间,请从命令中删除 -sexagesimal.
关于c# - 使用 ffmpeg/ffprobe 获取视频的长度不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38474590/
我必须开发一个使用 Pydub 来编辑 mp3 文件的 Alexa Skill。 Pydub 需要 ffmpeg,所以我已将其添加到 requirements.txt 但现在,当我尝试运行我的技能时,
运行代码片段时,出现标题中的错误。 我已经重新安装了软件包pydub,以及pip3 install ffprobe。 from pydub.playback import play f
我有这个命令 ffprobe -show_frames -select_streams v -print_format json -i c:\test.mpg 但是,它会打印出所有帧信息。无论如何我
我正在尝试使用 FFProbe 提取视频 (.MP4) 的持续时间,并要求将结果输出到文件中。当我使用命令提示符输入文件时,FFProbe 工作完美并创建包含持续时间信息的文件,但是,当我在我的 VB
当我使用 ffmpeg 时,我会这样使用它: ./ffmpeg -ss 00:30:00 -i inputvideo.mp4 -t 00:00:20 -c:v copy -c:a copy outpu
我正在尝试从 ffprobe 返回特定值: ffprobe -v error -select_streams V:0 -show_entries stream=index,width,height,s
我正在使用 mkvmerge将 mp4 CFR 视频与包含 VFR 时间戳的文本文件相结合。使用的命令是 mkvmerge --timestamps 0:timestamps.txt input_vi
我一直在使用 ffprobe 从视频流中读取数据包进行分析。然而,它的速度非常缓慢。阅读 30 分钟 720p 视频大约需要 8 分钟。 我目前正在使用以下命令: ffprobe.exe -i vid
我有一个 oog 文件(它是由 pbx Asterisk 记录的两个音频流中的 sox 混合的),我正在尝试使用 ffprobe 获取文件信息。 当我使用类似的东西时 cat %filename%.o
我使用此代码通过 ffprobe 提取视频信息: ffprobe -show_streams -of json -v quiet -i input.mp4 所有流的信息都出现在输出中,而我只需要 v:
我试图了解 ffprobe 的行为关于对格式标签使用大写或小写约定。 以下是重现的步骤。从现有 MP4 电影创建 MP4、AVI 和 MKV 容器: $ ffmpeg -y -i input.mp4
我尝试了许多使用 FFProbe 获取视频编解码器的不同示例,including this one除了偶尔的 [/STREAM] 之外,无法获得任何输出。 这是我目前正在尝试的 $codec = ex
对于我的一个脚本,我需要读出一个 wav 文件的位深度。 ffprobe -v error -show_entries format=bits_per_sample -of default=nopri
我在使用 ffprobe 语法时遇到问题,获取打印格式以输出默认值而不使用任何键。有一个 nokey 选项,所以我传入这样的东西 ffprobe -print_format 默认无 key 但我什么也
我正在尝试使用 FFprobe 来测试流媒体链接是否处于事件状态。 例如,这是一个有效的流媒体链接: ffprobe -loglevel quiet -show_streams rtmp://Lrmh
使用此 ffprobe 将 MP4 转换为类似于视频的输出格式的命令是什么? : ffprobe version N-82151-g1e660fe Copyright (c) 2007-2016 th
我目前正在运行以下命令,它主要提供了我需要的东西,但我也想让它包含文件名。 for %%A IN (%VAR0%\*.wav) DO "C:\program files (x86)\ffmpeg\bi
我正在使用 ffprobe 在具有可用硬件加速解码器的 AWS VT1 上使用以下命令从视频文件中提取信息 ffprobe -of json -show_streams -show_frames -s
我想安排一个作业脚本来检查直播流是否还活着,使用“ffprobe”命令。这样我就可以更改那些已经死掉的 Steam 的数据库状态。 我尝试了命令: ffprobe -v quiet -print_fo
我在 马克并且正在开发一个项目,我的程序应该将 .mp3 文件转换为 .wav 文件,然后从该文件中获取文本(基本语音识别)。为了将 .mp3 文件转换为 .wav 文件,我使用的是 ffmpeg 库
我是一名优秀的程序员,十分优秀!