1
votes

I have used FFMPEG to convert JPG files to a MP4 file. Are they any compression techniques/flags/settings/switches i can use to further reduce the size of this MP4 files. I had used gZIP to compress the bytes of this files but it actually resulted in a bigger file.

I am using C#

Thanks

2

2 Answers

2
votes

MP4 is a container format. Depending on your ffmpeg configuration ffmpeg will either use the encoder mpeg4 for MPEG-4 Part 2 video or libx264 for H.264 video.


mpeg4

Rate control methods include -qscale:v and -b:v. These are mutually exclusive so you should use one or the other.

-qscale:v

Sets a constant quantizer, but general users can just think "constant quality". Effective range is 2-31 where 2 is highest quality.

ffmpeg -i input -codec:v mpeg4 -codec:a libmp3lame -qscale:v 4 -qscale:a 5 out.mp4

-b:v

Allows a video bitrate to be applied. Can be used to target a specific output file size (filesize = duration x bitrate).

ffmpeg -i input -codec:v mpeg4 -codec:a libmp3lame -b:v 512k -b:a 128k out.mp4

Also see:


libx264

Rate control methods include -crf, -b:v, and -qp, but for the vast majority of users -qp can be ignored.

-crf

Constant Rate Factor. Think of it as a "smart" version of -qscale:v. Range is logarithmic 0-51. 0 is lossless (big files), ~18 is roughly visually lossless, 23 is default, and 51 is worst quality.

ffmpeg -i input -codec:v libx264 -crf 23 -preset medium -codec:a libfdk_aac -vbr 5 output.mp4

-b:v

Allows a video bitrate to be applied. Can be used to target a specific output file size (filesize = duration x bitrate). Two-pass example:

ffmpeg -y -i input -pass 1 -codec:v libx264 -preset medium -b:v 800k -an -f mp4 /dev/null
ffmpeg -y -i input -pass 2 -codec:v libx264 -preset medium -b:v 800k -codec:a libfdk_aac -b:a 128k output.mp4

Also see:

-1
votes

Compressing an already compressed file usually doesn't make much difference (and it can result in a bigger file).

So if you want a smaller file, I suggest you to change the compression quality of the mp4 file (whatever technique you are using I think you have this option).

If you are using the command line tool, you can play with the video bitrate to reduce the size of your file:

ffmpeg -f your_image_files*.jpg -vcodec mpeg4 -b 1200kb your_video.mp4

just replace 1200kb with a lower value and your file size will be smaller

If you want to do it all in C#, and see the encoding progression, you can use this .Net wrapper for ffmpeg: http://www.ffmpeg-csharp.com/