3

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 3

7

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
  • Thanks for the useful answer! I allready tried it without "&", but I had the issue that I couldn't do anything else in the terminal during the time of conversion (I additional used a "-nostdin" and "-loglevel panic"). Also Im not sure if I can just close the bash window , because often it just stopped. How is this dependent on wether Im using "&" or not and can I even just close the Terminal?
    – Mathis
    Jun 19, 2020 at 23:17
  • You are having specific issues: could be low memory, could be faulty hardware. On a healthy system, a one-by-one conversion may be very slow, but should never freeze. Closing the bash window will terminate the running process. For the &, see the answer.
    – vanadium
    Jun 20, 2020 at 7:38
  • I think youre right, because yesterday I tried to get around the "terminal close problem" with 'screen' and alt+A, alt+D and the shell started freezing with the third process (its really a low level server!). My aim is to just run a script that converts every video in the folder within a few hours and being able to close the terminal after starting the script. For that I have to unattach the process from the terminal and make him able to convert the next video when another one has finished. Maybe I should ask another question, but can you give me an advice how to that?
    – Mathis
    Jun 20, 2020 at 14:37
1

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 =)

1

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .