Join the conversation

Join the community of Machine Learners and AI enthusiasts.

Sign Up
luigi12345Β 
posted an update 4 days ago
Post
2340
πŸ”₯ ULTRA VIDEO COMPRESSION (300MB β†’ 3MB!)
ffmpeg -i input.mp4 -vcodec libx264 -crf 28 -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" -y output.mp4

-i β†’ Input ⚑️ -vcodec libx264 β†’ H.264 codec ⚑️ -crf 28 β†’ Compression (lower = better quality) ⚑️-vf pad=... β†’ Even dimensions ⚑️ -y β†’ Overwrite

I have tried it on 72 MB video:

ffmpeg -y -hwaccel cuda -i /home/data1/protected/Media/Pictures/Pictures/Year-2025/03/2025-03-13/VID_20250313_154150.mp4 -vcodec libx264 -crf 28 -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" output.mp4

and I included -hwaccel cuda which sped up probably.

Result is 17M video and I see nothing strange as human. Looks same, it means compression is really good. Though it wasn't 94%, rather 77%.

Different ffmpeg formula

I have a bit different conversion formula, for videos on websites, I follow Google guideliness and compress it to webm:

(defun video2webm-dired ()
  "Converts any video to webm"
  (interactive)
  (let* ((bitrate (read-number "Bitrate: " 500))
     (videos (dired-get-marked-files))
     (videos (mapcar 'video-mime-type-p videos))
     (videos (seq-remove 'null videos))
     (async-shell-command-buffer 'new-buffer)
     (command (format "ffmpeg -y -hwaccel cuda -i `?` -c:v libvpx-vp9 -b:v %sk -pass 1 -passlogfile `?` -speed 4 -c:a libopus -f webm /dev/null -async 1 -vsync passthrough && ffmpeg -y -hwaccel cuda -i `?` -c:v libvpx-vp9 -b:v %sk -pass 2 -passlogfile `?` -speed 1 -c:a libopus \`?`.webm -async 1 -vsync passthrough && rm `?`-0.log;" bitrate bitrate)))
    (dired-do-async-shell-command command nil videos)))

that however, takes much longer time than your formula. I have now converted to 1000 bit rate, and I have got result of 5.4 M for same video.

That is like 92.5%

I can't see as human any visible differences with that bit rate.

Better to 500 bit rate

With 500 bit rate, I have got 2.9M from 72M, that is fantastic. It took longer, but compression is so much better.

I have achieved basically 96% which is more than you! πŸ˜›

I just got 400 to 300 mb :(

Amazing, thank you very much. I created a Space for everyone to use easily.
https://huggingface.co./spaces/eienmojiki/video-compression