FFMPEG-批量提取媒体持续时间并写入文本文件 [英] FFMPEG - batch extracting media duration and writing to a text file
本文介绍了FFMPEG-批量提取媒体持续时间并写入文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的文件夹中有十个媒体文件.我想创建一个包含两列的文本文件-文件名及其持续时间(秒):
I have ten media files in a folder. I want to create a text file containing two columns - filename and its duration (seconds):
video1.mp4|300 seconds
video2.mp4|360 seconds
video3.mp4|420 seconds
...
audio10.wav|120 seconds
我没有在网络上找到任何类似的问题,因此我对如何执行此操作没有任何提示...
I did not find any similar question on the Web, so I don't have any hint of how to do this...
推荐答案
枚举媒体文件并解析ffmpeg -i
的输出中的Duration:
行:
Enumerate the media files and parse Duration:
line in the output of ffmpeg -i
:
@echo off
>output.txt (
for %%F in (*.mpg *.mp4 *.mkv *.avi *.m4a *.flac *.mp3 *.wav) do (
for /f "tokens=2-5 delims=:., " %%a in (
'ffmpeg -i "%%F" 2^>^&1 ^| find "Duration:"'
) do (
set /p =%%~nxF^|<nul
setlocal enableDelayedExpansion
set /a "duration=1%%a*3600 + 1%%b*60 + 1%%c - 366100"
echo !duration!.%%d seconds
endlocal
)
)
)
pause
使用ffprobe
(ffmpeg软件包的一部分),持续时间将具有微秒级的精度:
With ffprobe
(a part of ffmpeg package) the durations will have microsecond precision:
@echo off
>output.txt (
for %%F in (*.mpg *.mp4 *.mkv *.avi *.m4a *.flac *.mp3 *.wav) do (
for /f "tokens=2 delims==" %%a in (
'ffprobe "%%F" -show_entries format^=duration -v quiet -of compact'
) do (
echo %%~nxF^|%%a seconds
)
)
)
pause
或者,您可以使用更快的 MediaInfo CLI 输出持续时间(以毫秒为单位):
Alternatively you can use a much faster MediaInfo CLI to output duration in milliseconds:
>output.txt "C:\Program Files (x86)\MediaInfo\MediaInfoCLI.exe" ^
--output=General;%%FileName%%.%%FileExtension%%^|%%Duration%%\r\n ^
*.mpg *.mp4 *.mkv *.avi *.m4a *.flac *.mp3 *.wav
这篇关于FFMPEG-批量提取媒体持续时间并写入文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文