Click here to Skip to main content
15,066,499 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm having two types of videos in the same folder, first one is smaller than 640:800 pixel videos and other one is larger than 640:800 pixel videos. I used ffmpeg to resize video. It works perfect but I need to target only the videos whose pixels are larger than 640:800. How can I target only the specific videos(larger than 640:800) and resize them.

What I have tried:

BAT
for %%a in ("*.mp4") do ffmpeg -i "%%a" -vf scale=640:800 -preset slow -crf 18 "videos\%%~na.mp4"
Posted
Updated 20-Aug-21 3:13am

Use a loop to get from the values:
"width": 1280,
"height": 720

BAT
for /f useback^tokens^=2delims^=^,^  %%i in (`
    ^2^>^&1 ;ffprobe -v quiet -print_format json -show_format -show_streams -i "%~1" ^
    ^|%__AppDir__%findstr.exe "\"width\": \"height\":" ^|%__AppDir__%findstr.exe [0-9]

Let's say you add the values inside a loop and get:
720
1280

By adding outputs
720 + 1280 = 2000

By adding your limits:
640 + 800 = 1440

Having this, compare with the sum of in a variable and using:
if (condition)else (condition) it is possible to convert your videos:

if outputs gtr limits (convert video file) else do nothing
if 2000 gtr 1440 (ffmpeg ...) else (exit/b)

BAT
@echo off && setlocal 

cd /d "%~dp0" && for %%i in (*.mp4)do set "_cnt=" & call %:^) "%%~i"

%:^)
if "%~1"=="" (endlocal && exit /b) else for /f useback^tokens^=2delims^=^,^  %%i in (`
    ^2^>^&1 ;ffprobe -v quiet -print_format json -show_format -show_streams -i "%~1" ^
    ^|%__AppDir__%findstr.exe "\"width\": \"height\":" ^|%__AppDir__%findstr.exe [0-9]
    `)do call set/a "_cnt+=%%i"

if %_cnt% gtr 1440 (
    ;ffmpeg -i "%~1" -hide_banner -v error -stats -vf scale=640:800 -preset slow -crf 18 ^
	".\videos\%~n1.mp4" & echo\File: "%~1" [Done])else echo\File: "%~1" [Skipped] & exit/b 


Note that there is no space or other character at the end of the line ending in ^
   
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900