I was recently guided toward ffmpeg for batch re-sizing video files and I've almost perfected it, but am running into a stumbling block with some files..
I have a folder containing many .flv and .mp4 files with varying resolutions.
All files need to be re-sized to 320 pixels in width, while maintaining the original aspect ratio, so frame heights will vary from file to file.
Included in the folder is the following batch file:
Code:set ffmpeg="C:\Program Files\ffmpeg\bin\ffmpeg.exe" for %%f in (*.flv) do %ffmpeg% -i "%%f" -vf scale=w=320:h=-1 -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=w=320:h=-1 -crf:v 20 -acodec copy -vcodec libx264 -threads 0 -f mp4 -y ".\RESIZED\%%f_resized.mp4"
This works almost perfectly except for two issues..
1. A number of files in the destination folder are 0kb, and upon investigating I noticed ffmpeg returned the following error for each:
(sorry about the image.. i was having difficulty pasting the text)
... is there anyway to modify the command line so it doesn't error out when processing these files?
2. I've also noticed a slight affect to the framerates on the re-sized files.. its most noticeable when there is a long pan or steady movement across the screen.. Is this an unavoidable degradation due to the lossy nature of what im doing? .. or can the command line be tweaked to make the results as fluid as the original files?
Any help is greatly appreciated!!
+ Reply to Thread
Results 1 to 3 of 3
height not divisible by 2
Where you have used scale=320:h=-1
ffmpeg -i foo.mp4 -vf "scale=320:trunc(ow/a/2)*2" -c:v libx264 -crf 23 -preset ultrafast -c:a copy foo_resized.mp4
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"
Worked like a charm! My endless thanks!!
Regarding the playback not being as smooth as the original files.. it looks like a dropped frame every now and then.. almost like a subtle hiccup that becomes more apparent during tracking shots or smooth camera panning.. is there anyway around that or is it just a side effect of re-sizing videos to a smaller resolution?