VideoHelp Forum
+ Reply to Thread
Results 1 to 8 of 8
Thread
  1. 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:

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

    any input is greatly appreciated!!!
    Thanks!
    Quote Quote  
  2. 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
    In your case
    Code:
    pad=320:240:(ow-iw)/2:(oh-ih)/2
    Last edited by pandy; 10th Jan 2014 at 02:49.
    Quote Quote  
  3. 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 section
    Code:
    pad=320:240:(ow-iw)/2:(oh-ih)/2
    to my command line as follows:

    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"
    ..but it returns the following error:

    Name:  error.jpg
Views: 646
Size:  153.9 KB

    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??
    Quote Quote  
  4. 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
    Quote Quote  
  5. Originally Posted by pandy View Post
    Try this..
    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"
    ..and it returned the following error:


    Name:  error.jpg
Views: 632
Size:  202.7 KB


    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?
    Quote Quote  
  6. @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"
    just tested - works OK on my computer...

    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.100
    Last edited by pandy; 10th Jan 2014 at 03:43.
    Quote Quote  
  7. batch expert Endoro's Avatar
    Join Date: Dec 2013
    Location: Bozen
    Search PM
    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"
    Quote Quote  



Similar Threads