Velvet Star Monitor

Standout celebrity highlights with iconic style.

news

How do I resize multiple videos using ffmpeg?

Writer Mia Lopez

I tried to resize multiple Video in different way on my slow server instance with Ubuntu 18.

When generate a batch script file with:

ffmpeg -i video1.MP4 -vf scale=854:480 smallvideo1.MP4 &
ffmpeg -i video2.MP4 -vf scale=854:480 smallvideo2.MP4 &
ffmpeg -i video3.MP4 -vf scale=854:480 smallvideo3.MP4 &
...

Somehow it only converts randomly two or three of the videos and then it quits. Every time all the ouput files smallvideo[i].mp4 have been created, but they were not readable. I tried also with -nostdin and without &, still not working properly.

No I tried it this way:

ffmpeg -i video1.MP4 -i video2.MP4 -i video3.MP4 ...
-map 0 -vf scale=854:480 smallvideo1,MP4 & \
-map 1 -vf scale=854:480 smallvideo2.MP4 & \
-map 2 -vf scale=854:480 smallvideo3.MP4 & \
...

and it gave me this error:

$
./ffmpeg.sh: line 6: -map: command not found
./ffmpeg.sh: line 5: -map: command not found
...

It only converts the 1st one.

I'd really appreciate if someone could help me figuring out the problem!

3 Answers

You are putting an ampersand ("&") at the end, which means: fork into background. That means that all your conversions are simultaneously started. That is a problem for your slow server, because the CPU has to do x encodings at the same time. So any of the take a very long time to finish, not accounting for the overhead involved in the multitasking needs.

Just delete the ampersands at the end and try again. It should work, but it will take time if this is a slow server.

One simple way to sequentially encode all files in a folder is with a bash loop:

for f in *.MP4 ; do ffmpeg -i "$f" -vf scale=854:480 "small$f" ; done
3

You can define the following shell function:

# Usage: video-resize (file) (scale)
video-resize() { ffmpeg -y -i "${1}" -vf scale=854:${2:-480} "${1%.*}.resized.${1##*.}"
}

Then run as:

for file in DJI_*.MP4; do video-resize $file; done

I found a complete solution for my specific Problem:

Run the bash-script:

# screen ./ffmpeg.sh

and inside the script

#!/bin/bash
for f in DJI_*.MP4 ; do ffmpeg -i "$f" -vf scale=854:480 "small$f" ; done

or with -nostdin flag after "ffmpeg". Now I can disconnect with alt+A alt+D, reconnect with screen -r and even close the terminal =)

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy