4

I have a root directory which haves a lot of folders, and inside those more folders. There are no real structure, just a bunch of folders with some having a mp4 file inside. I would like to compress them, as the mean size for those videos are around 200 Mb. Also, I would like to have them store in the same path as the original folder where the file is located.

Is there any way to solve this problem with ffmpeg?

1
  • Most likely are already compressed. Try zipping some, like 10, and see how much it can reduce size. Commented Dec 27, 2022 at 1:08

1 Answer 1

1
+50

I thought of a solution very similar to one answer, deleted from a community boot, which is therefore not visible to all users.

I don't think ffmpeg can do it all by itself. Better to use find to find the files and then call ffmpeg on them with the right parameters.

ffmpeg

You can use a codec that has better compression on its own, like libx265, and then choose to reduce the definition and/or the number of frames per second. The parameters to choose for ffmpeg is up to you, it will be something like this

ffmpeg -i input.mp4 -vf scale=1280:-2 -c:v libx265 -crf 30 output.mp4

Note on crf:

If you’re unsure about what CRF to use, begin with the default and change it according to your subjective impression of the output. Is the quality good enough? No? Then set a lower CRF. Is the file size too high? Choose a higher CRF. A change of ±6 should result in about half/double the file size, although your results might vary.

find

From the root directory which haves a lot of folder inside you can run find with the ffmpeg command line with your desired parameters.

find . -type f -name "*.mp4" -exec ffmpeg -i {} -vf scale=1280:-2 -c:v libx265 -crf 30 {}.newlycompressed.mp4 \;

Note:
you may want to run in advance another call to find to store the filenames to delete after you check it was all ok...

find . -type f -name "*.mp4" -exec echo "rm " {} \; >> Files_to_be_deleted
2
  • It's actually easy to find all the X.newlycompressed.mp4 and mv each of them to the corresponding X.mp4 (at least with the help of a for loop and string manipulation in bash; not sure if there's a pure find equivalent though).
    – Tom Yan
    Commented Jan 2, 2023 at 15:39
  • @TomYan Yes there are thousands of ways to do this (not least having find run a complex command with && to move the file if the conversion was successful), but that was beyond the scope of the question... That's correct IMHO do it in separate times to verify the result. Or make a script or list of commands to execute linearly (to minimize the risk of running out of disk space)...
    – Hastur
    Commented Jan 2, 2023 at 18:19

You must log in to answer this question.

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