DEAR PEOPLE FROM THE FUTURE: Here's what we've figured out so far...

Welcome! This is a Q&A website for computer programmers and users alike, focused on helping fellow programmers and users. Read more

What are you stuck on? Ask a question and hopefully somebody will be able to help you out!
+3 votes

I've maxed the storage space I have and I would like to make some space.

I've thought of converting all files to mkv and down-scaling high resolution files to a lower resolution.

So to convert mp4 to mkv there is

ffmpeg -i input.mp4 -vcodec copy -acodec copy output.mkv

And to downscale there is

ffmpeg -i input.mp4 -vf scale=$w:$h <encoding-parameters> output.mp4

but I need to convert all files not a single mp4 one, I need to remove the input file after done processing it and I have to do this only for files above a given resolution. Also I would like to keep the aspect ratio and I don't know if this is doing that.

There is a tool called video-diet that does part of this.

This is what I would like to do

Recursively find every file under the current directory
If the file resolution has a height equal or greater to a given height.
  Convert the file to mkv if it's in another format avi, mp4, flv, etc
  Downscale to a lower resolution height, keeping the aspect ratio.

Maybe I should also lower the frame rate to 24 fps?

If there is a better way, I would like to hear it.


2 Answers

+1 vote
Best answer

I have tried to write a script based on the other answers:


for video in input/*
        filename=$(basename "$video")
        height=$(mediainfo --Inform="Video;%Height%" "$video")

        if (( $height > 720 ))
                ffmpeg -i "$video" -vf scale=-1:720 "output/${filename}.mkv"
selected by
+1 vote

There isn't a "better" way, it depends how much of the original videos you want to preserve. By transcoding to a lower quality you will inevitably lose information. If you want to preserve the original quality, buy more space. If you are ready to lose information, create an "output" directory, loop through all your file, for each file execute ffmpeg and save the new files in output. Ffmpeg has many options for converting formats, such as -c (select/change codec), -b (change the bit rate), -r (change the frame rate), -s (change frame size, for example -s 1280x720). You can use ffprobe or mediainfo for retrieving information about a file.

Contributions licensed under CC0