batch file - sort videos by length, need efficiency and if possible reliability -


this uses mediainfo extract video properties , checks track lengths , sorts video accordingly either long or short directories.

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 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 

as can see inefficient. can reduced few lines? side note track length check not reliable since videos have wrong track integrated (usually subtitles), meaning incorrect length of additional track determine video should go.

this how mediainfo outputs data to vdata file. video track duration should @ line 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 video                  : -743 ms writing library                          : lavc57.48.101 aac default                                  : yes forced                                   : no duration                                 : 01:00:58.028000000 

it possible convert 𝑛 h 𝑛𝑛 min 𝑛𝑛 s convention integer replacing "h", "min", , "s" mathematical equivalents using string substitution, using set /a math whole thing seconds. once have seconds integer, divide 60 minutes.

also, there's no need dump output of mediainfo text file. capture for /f.

@echo off & setlocal  set "video=%~f1"  rem // change "args" whatever arguments mediainfo requires.  don't know syntax. /f "tokens=2*" %%i in (     'mediainfo args "%video%" ^| findstr /irc:"duration.*[0-9] [hms]"' ) 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\ ) 

... or similar.


there's better tool scraping duration of video files, though. ffprobe (a part of ffmpeg package) let video's global duration in seconds.microseconds following command:

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

output resembles this:

format,5028.080000

as mediainfo example above, use for /f loop capture output of ffprobe.

@echo off & setlocal  set "video=%~f1"  /f "tokens=2 delims=,." %%i in (     'ffprobe -v quiet -show_entries "format=duration" -of csv "%video%"` ) set /a "minutes = %%~i / 60"  if %minutes% leq 25 (     move "%video%" short\ ) else (     move "%video%" long\ ) 

Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -