Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Is there a simple way (on the command line - I want to write a script which compresses all videos in a folder) to reduce the filesize of a video (almost) without quality loss? Is there a method which works equally well for different video format (mp4, flv, m4v, mpg, mov, avi)?

I should mention that most of the videos I would like to compress are downloaded web-videos (mp4, flv), so it's not clear if there is much room for further compression.

share|improve this question
flv videos are already highly compressed. I doubt whether you will gain anything by recompressing them. As for the others there is mencoder. –  tinhed Mar 8 '11 at 11:13
Furthermore, to improve such compressions, you have to tweak each file individualy to fit its own needs and individually optimize compression for each of them. I don't really think that's easy (I won't dare to say it's not possible, tho) to script. –  luri Mar 8 '11 at 11:22

1 Answer 1

In the mystical land of the PNG, the most effective way of near-lossless compression is to compress the image with almost every possible combination of settings and compare the output. This is what applications like pngcrush do.

There's no reason why a similar process wouldn't work, on paper. In practice, there are a few issues:

  • Compressing video once is already a much longer process than encoding a PNG image.
  • There are about 1000 times as many configuration combinations.
  • Those two conspire to make the process exponentially longer by several powers.
  • It would also use an unreasonable amount of disk space, memory and CPU time.
  • Frames blend if there's a framerate change and obviously change if you change the frame size or crop, making comparison process even harder

To top it all off, you're dealing with content that's already poisoned with artefacts and encoding sludge. My simple answer for "Is there a simple way" has to be No.

But if you have a shed load of low-compression videos like FLV (a fairly rubbish compression in my experience with the format), it might be worth having a go with ffmpeg or mencoder for the FLVs. Something like this might work:

find -iname '*.flv' -exec \
    mencoder {} -o {}.recomp.avi -ovc x264 -x264encopts threads=9:bitrate=400 -oac mp3lame -lameopts abr:br=52 \;

But there will be loss. You just have to judge how much is acceptable.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.