batch-file - 按长度对视频进行排序,需要效率,如果可能的话还需要可靠性

标签 batch-file video batch-processing

这使用 mediainfo 提取视频属性,然后检查轨道长度并根据长目录或短目录对视频进行排序。

mediainfo.exe %1 >%temp%\vdata
type %temp%\vdata | find ": 9 h" >nul && move %1 long && goto next
type %temp%\vdata | find ": 8 h" >nul && move %1 long && goto next
type %temp%\vdata | find ": 7 h" >nul && move %1 long && goto next
type %temp%\vdata | find ": 6 h" >nul && move %1 long && goto next
type %temp%\vdata | find ": 5 h" >nul && move %1 long && goto next
type %temp%\vdata | find ": 4 h" >nul && move %1 long && goto next
type %temp%\vdata | find ": 3 h" >nul && move %1 long && goto next
type %temp%\vdata | find ": 2 h" >nul && move %1 long && goto next
type %temp%\vdata | find ": 1 h" >nul && move %1 long && goto next
type %temp%\vdata | find ": 59 min" >nul && move %1 long && goto next
type %temp%\vdata | find ": 58 min" >nul && move %1 long && goto next
type %temp%\vdata | find ": 57 min" >nul && move %1 long && goto next
type %temp%\vdata | find ": 56 min" >nul && move %1 long && goto next
type %temp%\vdata | find ": 55 min" >nul && move %1 long && goto next
type %temp%\vdata | find ": 54 min" >nul && move %1 long && goto next
type %temp%\vdata | find ": 53 min" >nul && move %1 long && goto next
type %temp%\vdata | find ": 52 min" >nul && move %1 long && goto next
type %temp%\vdata | find ": 51 min" >nul && move %1 long && goto next
type %temp%\vdata | find ": 50 min" >nul && move %1 long && goto next
type %temp%\vdata | find ": 49 min" >nul && move %1 long && goto next
type %temp%\vdata | find ": 48 min" >nul && move %1 long && goto next
type %temp%\vdata | find ": 47 min" >nul && move %1 long && goto next
type %temp%\vdata | find ": 46 min" >nul && move %1 long && goto next
type %temp%\vdata | find ": 45 min" >nul && move %1 long && goto next
type %temp%\vdata | find ": 44 min" >nul && move %1 long && goto next
type %temp%\vdata | find ": 43 min" >nul && move %1 long && goto next
type %temp%\vdata | find ": 42 min" >nul && move %1 long && goto next
type %temp%\vdata | find ": 41 min" >nul && move %1 long && goto next
type %temp%\vdata | find ": 40 min" >nul && move %1 long && goto next
type %temp%\vdata | find ": 39 min" >nul && move %1 long && goto next
type %temp%\vdata | find ": 38 min" >nul && move %1 long && goto next
type %temp%\vdata | find ": 37 min" >nul && move %1 long && goto next
type %temp%\vdata | find ": 36 min" >nul && move %1 long && goto next
type %temp%\vdata | find ": 35 min" >nul && move %1 long && goto next
type %temp%\vdata | find ": 34 min" >nul && move %1 long && goto next
type %temp%\vdata | find ": 33 min" >nul && move %1 long && goto next
type %temp%\vdata | find ": 32 min" >nul && move %1 long && goto next
type %temp%\vdata | find ": 31 min" >nul && move %1 long && goto next
type %temp%\vdata | find ": 30 min" >nul && move %1 long && goto next
type %temp%\vdata | find ": 29 min" >nul && move %1 long && goto next
type %temp%\vdata | find ": 28 min" >nul && move %1 long && goto next
type %temp%\vdata | find ": 27 min" >nul && move %1 long && goto next
type %temp%\vdata | find ": 26 min" >nul && move %1 long && goto next
:: sort long making of videos, leave short ones for manual checkup
echo "%~n1" | find /i "making of " >nul && goto next
type %temp%\vdata | find ": 25 min" >nul && move %1 short && goto next
type %temp%\vdata | find ": 24 min" >nul && move %1 short && goto next
type %temp%\vdata | find ": 23 min" >nul && move %1 short && goto next
type %temp%\vdata | find ": 22 min" >nul && move %1 short && goto next
type %temp%\vdata | find ": 21 min" >nul && move %1 short && goto next
type %temp%\vdata | find ": 20 min" >nul && move %1 short && goto next
type %temp%\vdata | find ": 19 min" >nul && move %1 short && goto next
type %temp%\vdata | find ": 18 min" >nul && move %1 short && goto next
type %temp%\vdata | find ": 17 min" >nul && move %1 short && goto next
type %temp%\vdata | find ": 16 min" >nul && move %1 short && goto next
type %temp%\vdata | find ": 15 min" >nul && move %1 short && goto next
type %temp%\vdata | find ": 14 min" >nul && move %1 short && goto next
type %temp%\vdata | find ": 13 min" >nul && move %1 short && goto next
type %temp%\vdata | find ": 12 min" >nul && move %1 short && goto next
type %temp%\vdata | find ": 11 min" >nul && move %1 short && goto next
type %temp%\vdata | find ": 10 min" >nul && move %1 short && goto next
type %temp%\vdata | find ": 9 min" >nul && move %1 short && goto next
type %temp%\vdata | find ": 8 min" >nul && move %1 short && goto next
type %temp%\vdata | find ": 7 min" >nul && move %1 short && goto next
type %temp%\vdata | find ": 6 min" >nul && move %1 short && goto next
type %temp%\vdata | find ": 5 min" >nul && move %1 short && goto next
type %temp%\vdata | find ": 4 min" >nul && move %1 short && goto next
type %temp%\vdata | find ": 3 min" >nul && move %1 short && goto next
type %temp%\vdata | find ": 2 min" >nul && move %1 short && goto next
type %temp%\vdata | find ": 1 min" >nul && move %1 short && goto next
type %temp%\vdata | find ": 59 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 58 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 57 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 56 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 55 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 54 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 53 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 52 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 51 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 50 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 49 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 48 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 47 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 46 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 45 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 44 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 43 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 42 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 41 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 40 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 39 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 38 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 37 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 36 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 35 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 34 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 33 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 32 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 31 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 30 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 29 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 28 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 27 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 26 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 25 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 24 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 23 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 22 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 21 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 20 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 19 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 18 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 17 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 16 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 15 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 14 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 13 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 12 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 11 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 10 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 9 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 8 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 7 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 6 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 5 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 4 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 3 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 2 s " >nul && move %1 short && goto next
type %temp%\vdata | find ": 1 s " >nul && move %1 short && goto next
:next

如您所见,它的效率非常低。这可以减少到几行吗?另请注意,此轨道长度检查不是很可靠,因为有时视频会集成错误的轨道(通常是字幕),这意味着附加轨道的不正确长度将决定视频的播放位置。

这就是 mediainfo 将数据输出到 vdata 文件的方式。视频轨道持续时间应始终位于第 7 行。

General
Unique ID                                : 46047801939398570510895581797401581513 (0x22A47BEB8AA8348EF96251DF04E557C9)
Complete name                            : Tomorrowland 2017 GoPro.mp4
Format                                   : Matroska
Format version                           : Version 4 / Version 2
File size                                : 3.86 GiB
Duration                                 : 1 h 0 min
Overall bit rate                         : 9 074 kb/s
Writing application                      : Lavf57.41.100
Writing library                          : Lavf57.41.100 / Lavf57.41.100

Video
ID                                       : 1
Format                                   : HEVC
Format/Info                              : High Efficiency Video Coding
Format profile                           : Main@L4@Main
Codec ID                                 : V_MPEGH/ISO/HEVC
Duration                                 : 1 h 0 min
Width                                    : 1 920 pixels
Height                                   : 1 080 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 25.000 FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Writing library                          : x265 1.9:[Windows][GCC 5.2.0][64 bit] 8bit
Encoding settings                        : wpp / ctu=64 / min-cu-size=8 / max-tu-size=32 / tu-intra-depth=1 / tu-inter-depth=1 / me=1 / subme=1 / merange=57 / no-rect / no-amp / max-merge=2 / temporal-mvp / early-skip / rdpenalty=0 / no-tskip / no-tskip-fast / strong-intra-smoothing / no-lossless / no-cu-lossless / no-constrained-intra / fast-intra / open-gop / no-temporal-layers / interlace=0 / keyint=250 / min-keyint=25 / scenecut=40 / rc-lookahead=15 / lookahead-slices=6 / bframes=4 / bframe-bias=0 / b-adapt=0 / ref=2 / limit-refs=3 / no-limit-modes / weightp / no-weightb / aq-mode=1 / qg-size=32 / aq-strength=1.00 / cbqpoffs=0 / crqpoffs=0 / rd=2 / psy-rd=2.00 / rdoq-level=0 / psy-rdoq=0.00 / signhide / deblock / sao / no-sao-non-deblock / b-pyramid / cutree / no-intra-refresh / rc=crf / crf=21.0 / qcomp=0.60 / qpmin=0 / qpmax=51 / qpstep=4 / ipratio=1.40 / pbratio=1.30
Language                                 : English
Default                                  : Yes
Forced                                   : No
DURATION                                 : 01:00:58.103000000

Audio
ID                                       : 2
Format                                   : AAC
Format/Info                              : Advanced Audio Codec
Format profile                           : LC
Codec ID                                 : A_AAC
Duration                                 : 1 h 0 min
Channel(s)                               : 2 channels
Channel positions                        : Front: L R
Sampling rate                            : 44.1 kHz
Frame rate                               : 43.066 FPS (1024 spf)
Compression mode                         : Lossy
Delay relative to video                  : -743 ms
Writing library                          : Lavc57.48.101 aac
Default                                  : Yes
Forced                                   : No
DURATION                                 : 01:00:58.028000000

最佳答案

可以将 𝑛 h 𝑛𝑛 min 𝑛𝑛 s 约定转换为整数,方法是使用字符串替换将“h”、“min”和“s”替换为它们的数学等价物,然后使用 set/a 将整个事情计算成秒。得到秒整数后,除以 60 即可得到分钟。

此外,无需将 mediainfo 的输出转储到文本文件中。只需使用 for/f 捕获它即可。

@echo off & setlocal

set "video=%~f1"

rem // Change "args" to whatever arguments mediainfo requires.  I don't know its syntax.
for /f "tokens=2*" %%I in (
    'mediainfo args "%video%" ^| findstr /irc:"Duration.*[0-9] [hms]"'
) do if not defined duration set "duration=%%J"

set "duration=%duration: h=*3600%"
set "duration=%duration: min=*60%"
set "duration=%duration: s=%"
set /a "minutes=%duration: =+% / 60"

if %minutes% leq 25 (
    move "%video%" short\
) else (
    move "%video%" long\
)

...或类似的。


不过,有一个更好的工具可以抓取视频文件的持续时间。 ffprobe (FFmpeg 包的一部分)将允许您使用以下命令以秒为单位获取视频的全局持续时间。微秒:

ffprobe -v quiet -show_entries "format=duration" -of csv "filename.mkv"

输出类似于:

format,5028.080000

与上面的 mediainfo 示例一样,使用 for/f 循环来捕获 ffprobe 的输出。

@echo off & setlocal

set "video=%~f1"

for /f "tokens=2 delims=,." %%I in (
    'ffprobe -v quiet -show_entries "format=duration" -of csv "%video%"`
) do set /a "minutes = %%~I / 60"

if %minutes% leq 25 (
    move "%video%" short\
) else (
    move "%video%" long\
)

关于batch-file - 按长度对视频进行排序,需要效率,如果可能的话还需要可靠性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45376670/

相关文章:

javascript - 使用 HTML 和 Javascript 的视频的控制按钮不起作用

batch-file - 用于查找带有目录通配符的文件的批处理单行

ms-access - 使用批处理脚本比较文件版本

batch-file - 如何从批处理文件中确定分支名称

video - 使用 libx264 的 ffmpeg 转换看起来很糟糕 - 交错

python - 在 Keras 中实现多输入模型,每个模型都有不同的样本量(每个批处理大小不同)

javascript - 如何自动下载由javascript控制的多个链接?

Ios:从视频中删除音频

haskell - QuickCheck 2 批处理

image - 使用 ImageMagick 将不同的图像格式批量转换/调整大小为特定分辨率的 JPEG