Hey Everyone!!!
I have a folder of thousands of videos that have varying dimensions and aspect ratios..
I need to resize all of the videos to 320x240 exactly, and I don't want to distort the aspect ratio of the original videos.
Right now, I'm running the following batch script in Win7 to conform all of the widths to 320.. but to keep the aspect ratio correct, the height dimensions will vary:
How can I modify this script to ensure all resized videos are 320x240 exactly, and fill any blank space (due to the original video being too tall or too wide) with the color black?Code:set ffmpeg="C:\Program Files\ffmpeg\bin\ffmpeg.exe" for %%f in (*.flv) do %ffmpeg% -i "%%f" -vf "scale=320:trunc(ow/a/2)*2" -crf:v 20 -acodec copy -vcodec libx264 -threads 0 -f flv -y ".\RESIZED\%%f_resized.flv" for %%f in (*.mp4) do %ffmpeg% -i "%%f" -vf "scale=320:trunc(ow/a/2)*2" -crf:v 20 -acodec copy -vcodec libx264 -threads 0 -f mp4 -y ".\RESIZED\%%f_resized.mp4" for %%f in (*.avi) do %ffmpeg% -i "%%f" -vf "scale=320:trunc(ow/a/2)*2" -crf:v 20 -acodec copy -vcodec libx264 -threads 0 -f mp4 -y ".\RESIZED\%%f_resized.mp4"
any input is greatly appreciated!!!
Thanks!
+ Reply to Thread
Results 1 to 8 of 8
-
-
https://trac.ffmpeg.org/wiki/Scaling%20%28resizing%29%20with%20ffmpeg
based on this and on few other examples personally i use something like this (PSP):
Code:ffmpeg -i %1 -c:v libx264 -preset slow -tune film -profile:v main -crf 22 -b:v 1000k -x264opts "level=30:vbv_maxrate=4000:vbv_bufsize=3000:cabac=1:b-pyramid=0:weightp=1:weightb=1:trellis=2:keyint=250:nal_hrd=none:bframes=7:ref=3:partitions=all:8x8dct=0:bluray-compat" -vf "unsharp=3:3:2:3:3:2,scale=out_range=auto:force_original_aspect_ratio=decrease:'if(gt(a,30/17),480,-1)':'if(gt(a,30/17),-1,272)':sws_flags=bicubic+accurate_rnd+full_chroma_inp+full_chroma_int:sws_dither=bayer,pad=480:272:(ow-iw)/2:(oh-ih)/2,setsar=sar=1/1" -af "lowpass=frequency=12000,volume=1.50,earwax,aresample=resampler=soxr:osr=48000:cutoff=0.65:dither_method=2" -strict experimental -c:a aac -b:a 96k -ac 2 -shortest -f psp %1.mp4
Code:pad=320:240:(ow-iw)/2:(oh-ih)/2
Last edited by pandy; 10th Jan 2014 at 02:49.
-
Thanks!! I'll try it out as soon as I get home and report back..
I noticed a number of agruments for audio.. are you modifying the source's audio with these parimeters?
I may need to simplify it a bit, as I don't want to change anything from the original other than the size.. -
I seem to still be having an issue with this...
To be honest, I'm getting a bit lost in your parameters.. so I tried to amend the sectionCode:pad=320:240:(ow-iw)/2:(oh-ih)/2
Code:set ffmpeg="C:\Program Files\ffmpeg\bin\ffmpeg.exe" for %%f in (*.mp4) do %ffmpeg% -i "%%f" -vf "pad=320:240:(ow-iw)/2:(oh-ih)/2" -crf:v 20 -acodec copy -vcodec libx264 -threads 0 -f mp4 -y ".\RESIZED\%%f_resized.mp4"
I defiantly don't want to alter audio or anything like that.. just resize all videos to 320x240 and fill in any blank space with black to preserve aspect ratio..
Can anyone spot where I'm going wrong?? -
Try this - you need both (pad and resize) to resize and fill margins.
ffmpeg -i %1 -vf "unsharp=3:3:2:3:3:2,scale=out_range=auto:force_or iginal_aspect_ratio=decrease:'if(gt(a,4/3),320,-1)':'if(gt(a,4/3),-1,240)':sws_flags=bicubic+accurate_rnd+full_chroma _inp+full_chroma_int,pad=320:240:(ow-iw)/2:(oh-ih)/2,setsar=sar=1/1" -crf:v 20 -acodec copy -vcodec libx264 -threads 0 -f mp4 -y %1.mp4 -
I'm getting closer.. but still no cigar..
I ran the script as follows:
Code:set ffmpeg="C:\Program Files\ffmpeg\bin\ffmpeg.exe" for %%f in (*.mp4) do %ffmpeg% -i "%%f" -vf "unsharp=3:3:2:3:3:2,scale=out_range=auto:force_or iginal_aspect_ratio=decrease:'if(gt(a,4/3),320,-1)':'if(gt(a,4/3),-1,240)':sws_flags=bicubic+accurate_rnd+full_chroma _inp+full_chroma_int,pad=320:240:(ow-iw)/2:(oh-ih)/2,setsar=sar=1/1" -crf:v 20 -acodec copy -vcodec libx264 -threads 0 -f mp4 -y ".\RESIZED\%%f_resized.mp4"
Is there anything wrong with my parimeters? I know ffmpeg run in a batch script in win7 can get picky about things like quotation marks, etc..
Any ideas on what I'm doing wrong? -
@md .\RESIZED\
@set ffmpeg="ffmpeg.exe"
@for %%f in (*.mp4) do %ffmpeg% -i "%%f" -vf "scale=out_range=auto:force_original_aspect_ratio= decrease:'if(gt(a,4/3),320,-1)':'if(gt(a,4/3),-1,240)',pad=320:240:(ow-iw)/2:(oh-ih)/2,setsar=sar=1/1" -crf:v 30 -vcodec libx264 -preset ultrafast -profile:v main -af "lowpass=frequency=10000,aresample=resampler=soxr: osr=48000:cutoff=0.50:dither_method=2" -strict experimental -c:a aac -b:a 64k -ac 2 -shortest -threads 2 -f mp4 -y ".\RESIZED\%%f_resized.mp4"
Tested with:
ffmpeg version N-57821-g1fb3b49 Copyright (c) 2000-2013 the FFmpeg developers
built on Nov 2 2013 18:01:35 with gcc 4.8.2 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetype --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib
libavutil 52. 49.100 / 52. 49.100
libavcodec 55. 40.101 / 55. 40.101
libavformat 55. 21.100 / 55. 21.100
libavdevice 55. 5.100 / 55. 5.100
libavfilter 3. 90.100 / 3. 90.100
libswscale 2. 5.101 / 2. 5.101
libswresample 0. 17.104 / 0. 17.104
libpostproc 52. 3.100 / 52. 3.100Last edited by pandy; 10th Jan 2014 at 03:43.
-
my suggestion for a better batch syntax:
Code:@echo off &setlocal set "ffmpeg=%ProgramFiles%\ffmpeg\bin\ffmpeg.exe" for %%f in (*.mp4) do "%ffmpeg%" -i "%%~f" -vf "scale=out_range=auto:force_original_aspect_ratio= decrease:'if(gt(a,4/3),320,-1)':'if(gt(a,4/3),-1,240)',pad=320:240:(ow-iw)/2:(oh-ih)/2,setsar=sar=1/1" -crf:v 30 -vcodec libx264 -preset ultrafast -profile:v main -af "lowpass=frequency=10000,aresample=resampler=soxr: osr=48000:cutoff=0.50:dither_method=2" -strict experimental -c:a aac -b:a 64k -ac 2 -shortest -threads 2 -f mp4 -y "RESIZED\%%~nf_resized.mp4"
Similar Threads
-
How to Maintain Correct Aspect Ratio in PotPlayer with Full Screen
By drstew12 in forum Software PlayingReplies: 1Last Post: 20th Dec 2011, 19:25 -
Converting .mov to Flash - Can't Maintain Aspect Ratio
By cchrisj in forum Newbie / General discussionsReplies: 2Last Post: 9th Sep 2010, 09:53 -
How To Maintain Proper Aspect Ratio?
By Bonie81 in forum Authoring (DVD)Replies: 4Last Post: 2nd Sep 2010, 19:23 -
How can I maintain the Aspect Ratio in MeGUI?
By Newtype in forum Video ConversionReplies: 2Last Post: 1st Feb 2010, 09:06 -
Converting file w/fixed dimensions to one where only vertical dim is known
By nehickel in forum Video ConversionReplies: 0Last Post: 22nd Oct 2009, 19:56