1

感谢 David Ruhmann,昨天我让我的批处理文件用于重命名视频:

@echo off
setlocal EnableExtensions EnableDelayedExpansion

:: Create Empty Folder
rd /Q "%Temp%\Temp" 2>nul & mkdir "%Temp%\Temp"

:: Loop through Folders
pushd "xPath=c:\processing"
for /d %%D in (*) do call :Process "%%~fD"
popd
goto End


::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:Process <Parent>
:: Folder Name
set "xFolder=%~nx1"

:: Set Sub Folder
if not exist "%~1\VIDEO\" goto :eof
pushd "%~1\VIDEO"

:: Loop through Videos
for /f "delims=" %%A in ('dir *.avi /b') do if exist "%%~fA" (
    set "xDateWritten=%%~tA"
    set "xDateGMT=0000/00/00 00:00:00"
    for /f "tokens=1,2" %%X in ('robocopy . "%Temp%\Temp" "%%~nxA" /TS /FP /NS /NC /NP /NJH /NJS /NDL /L') do set "xDateGMT=%%X %%Y"
    rem Format = FF-FF-YYYYMMDD-HHh-MMm-SSs-FF-FF.ext
    echo %xFolder:~0,2%-%xFolder:~2,2%-!xDateWritten:~6,4!!xDateWritten:~0,2!!xDateWritten:~3,2!-!xDateWritten:~11,2!h-!xDateWritten:~14,2!m-!xDateGMT:~17,2!s-%xFolder:~4,2%-%xFolder:~6,2%%%~xA
    ren "%%~fA" "%xFolder:~0,2%-%xFolder:~2,2%-!xDateWritten:~6,4!!xDateWritten:~0,2!!xDateWritten:~3,2!-!xDateWritten:~11,2!h-!xDateWritten:~14,2!m-!xDateGMT:~17,2!s-%xFolder:~4,2%-%xFolder:~6,2%%%~xA"
)
popd
goto :eof


:End
endlocal
pause

但现在我需要添加一个附加功能。重命名后,我希望脚本导出新文件名,后跟文件大小(以字节为单位),以及视频长度为csv 或其他与 excel 兼容的文件类型。由于这些是视频文件,如果我也可以导出帧速率总帧数,那就太好了。不确定这是否甚至在批处理文件的范围内。

4

2 回答 2

2

这是将名称和大小导出到 csv 文件的修改。

改变这个

echo %xFolder:~0,2%-%xFolder:~2,2%-!xDateWritten:~6,4!!xDateWritten:~0,2!!xDateWritten:~3,2!-!xDateWritten:~11,2!h-!xDateWritten:~14,2!m-!xDateGMT:~17,2!s-%xFolder:~4,2%-%xFolder:~6,2%%%~xA
ren "%%~fA" "%xFolder:~0,2%-%xFolder:~2,2%-!xDateWritten:~6,4!!xDateWritten:~0,2!!xDateWritten:~3,2!-!xDateWritten:~11,2!h-!xDateWritten:~14,2!m-!xDateGMT:~17,2!s-%xFolder:~4,2%-%xFolder:~6,2%%%~xA"

进入这个

set "xFrame=00,00000"
for /f %%X in ('exiftool -p "$Framerate,$Framecount" "%%~fA"') do set "xFrame=%%~X"
set "xSize=%%~zA"
set "xName=%xFolder:~0,2%-%xFolder:~2,2%-!xDateWritten:~6,4!!xDateWritten:~0,2!!xDateWritten:~3,2!-!xDateWritten:~11,2!h-!xDateWritten:~14,2!m-!xDateGMT:~17,2!s-%xFolder:~4,2%-%xFolder:~6,2%%%~xA"
echo !xName!
ren "%%~fA" "!xName!"
echo !xName!,!xSize!,!xFrame!>>C:\RenameOutput.csv

更新:

要获取媒体文件信息,我们必须使用第 3 方工具。如

  1. ExifTool
  2. 媒体信息
  3. FFmpeg

基于对 ExifTool 和 MediaInfo 的快速浏览,我更喜欢 MediaInfo,因为它更一致的媒体文件 Duration 输出格式。如何解析信息的示例。

for /f "tokens=2,*" %X in ('mediainfo file.avi ^| find "Duration "') do @echo %Y

更新 2:

在答案中添加了 exiftool 示例。

于 2012-12-28T16:44:05.860 回答
0

这是对我们长评论流的回应。

改变这个

set "xName=%xFolder:~0,2%-%xFolder:~2,2%-!xDateWritten:~6,4!!xDateWritten:~0,2!!xDateWritten:~3,2!-!xDateWritten:~11,2!h-!xDateWritten:~14,2!m-!xDateGMT:~17,2!s-%xFolder:~4,2%-%xFolder:~6,2%%%~xA"

进入这个

set "xHour=!xDateWritten:~11,2!"
if "!xDateWritten:~17,2!"=="PM" set /a "xHour+=12"
set "xName=%xFolder:~0,2%-%xFolder:~2,2%-!xDateWritten:~6,4!!xDateWritten:~0,2!!xDateWritten:~3,2!-!xHour!h-!xDateWritten:~14,2!m-!xDateGMT:~17,2!s-%xFolder:~4,2%-%xFolder:~6,2%%%~xA"

完整脚本(添加评论)

@echo off
setlocal EnableExtensions EnableDelayedExpansion

:: Create Empty Folder
rd /Q "%Temp%\Temp" 2>nul & mkdir "%Temp%\Temp"

:: Loop through Folders
pushd "xPath=c:\processing"
for /d %%D in (*) do call :Process "%%~fD"
popd
goto End


::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:Process <Parent>
:: Folder Name
set "xFolder=%~nx1"

:: Set Sub Folder
if not exist "%~1\VIDEO\" goto :eof
pushd "%~1\VIDEO"

:: Loop through Videos
for /f "delims=" %%A in ('dir *.avi /b') do if exist "%%~fA" (
    rem Retrieve the file time stamp
    set "xDateWritten=%%~tA"
    rem Retrieve the Seconds using RoboCopy
    set "xDateGMT=0000/00/00 00:00:00"
    for /f "tokens=1,2" %%X in ('robocopy . "%Temp%\Temp" "%%~nxA" /TS /FP /NS /NC /NP /NJH /NJS /NDL /L') do set "xDateGMT=%%X %%Y"
    rem Retrieve the Video frame information
    set "xFrame=00,00000"
    for /f %%X in ('exiftool -p "$Framerate,$Framecount" "%%~fA"') do set "xFrame=%%~X"
    rem Retrieve the file size
    set "xSize=%%~zA"
    rem Adjust to 24 hours
    set "xHour=!xDateWritten:~11,2!"
    if "!xDateWritten:~17,2!"=="PM" set /a "xHour+=12"
    rem Format = FF-FF-YYYYMMDD-HHh-MMm-SSs-FF-FF.ext
    set "xName=%xFolder:~0,2%-%xFolder:~2,2%-!xDateWritten:~6,4!!xDateWritten:~0,2!!xDateWritten:~3,2!-!xHour!h-!xDateWritten:~14,2!m-!xDateGMT:~17,2!s-%xFolder:~4,2%-%xFolder:~6,2%%%~xA"
    rem Display, Rename, and Save
    echo !xName!
    ren "%%~fA" "!xName!"
    echo !xName!,!xSize!,!xFrame!>>C:\RenameOutput.csv
)
popd
goto :eof


:End
endlocal
pause
于 2013-01-10T21:52:47.680 回答