FFMPEG - 批量提取媒体持续时间并写入文本文件 [英] FFMPEG - batch extracting media duration and writing to a text file

查看:34
本文介绍了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)MediaInfoMediaInfoCLI.exe" ^
    --output=General;%%FileName%%.%%FileExtension%%^|%%Duration%%
 ^
    *.mpg *.mp4 *.mkv *.avi *.m4a *.flac *.mp3 *.wav

这篇关于FFMPEG - 批量提取媒体持续时间并写入文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆