You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

解决CMD环境下FFmpeg静默检测结果的多行输出写入文件问题

Solutions to Capture All Silence Durations to File Without Batch

CMD Command (Single Line, Overwrite Mode)

This approach starts with a clean file and writes all matching results in one overwrite operation:

del "C:\TEMP.txt" 2>nul & ffmpeg -i "C:\any-video.avi" -af silencedetect=noise=-50dB:d=0.1 -f null - 2>&1 | findstr "silence_duration:" | (for /f "tokens=8" %f in ('more') do @echo %f) > "C:\TEMP.txt"

Breakdown:

  • del "C:\TEMP.txt" 2>nul: Deletes the existing file (suppresses errors if it doesn’t exist)
  • ffmpeg ... 2>&1: Runs ffmpeg and redirects its stderr output (where silencedetect logs data) to stdout
  • findstr "silence_duration:": Filters output to only lines containing silence duration values
  • Wrapping the for /f loop in parentheses and using > at the end redirects all echoed lines to the file in one go, preserving every result instead of overwriting per line

PowerShell Command (Simpler Native Overwrite)

PowerStream’s stream processing handles multi-line output natively, making it easier to capture all results and overwrite the file by default:

ffmpeg -i "C:\any-video.avi" -af silencedetect=noise=-50dB:d=0.1 -f null - 2>&1 | Select-String "silence_duration:" | ForEach-Object { $_.Line.Split()[7] } | Out-File "C:\TEMP.txt" -Encoding Unicode

Breakdown:

  • ffmpeg ... 2>&1: Redirects ffmpeg’s stderr to stdout, same as CMD
  • Select-String "silence_duration:": Filters for lines with silence duration data
  • ForEach-Object { $_.Line.Split()[7] }: Splits each line into tokens and extracts the 8th value (zero-based index 7)
  • Out-File ...: Writes all results to the file, overwriting existing content by default. -Encoding Unicode matches CMD’s /U output format if needed

内容的提问来源于stack exchange,提问作者DannyhelMont

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.25 14:03:12