Reputation: 4553
I am using ffmpeg to convert the videos into mp4.Its working fine and its playing with high quality.No problem.But the worst case is I uploaded 14Mb file and after converting it goes to 30 Mb file.I am using the following the script to convert
exec("ffmpeg -i videowithaudio.flv -vcodec libx264 -vpre hq -vpre ipod640 -b 250k -bt 50k -acodec libfaac -ab 56k -ac 2 -s 480x320 video_out_file.mp4 > output1.txt 2> apperror1.txt"); //webkit compatible
I am using PHP for executing this command.Could you please help me how to reduce the file size from this 30Mb (nearly to uploaded file size is ok) with same quality.
Upvotes: 2
Views: 6036
Reputation: 15232
exec("ffmpeg -i videowithaudio.flv -vcodec libx264 -vpre hq -vpre ipod640 -b 250k -bt 50k -acodec libfaac -ab 56k -ac 2 -s 480x320 video_out_file.mp4 > output1.txt 2> apperror1.txt"); //webkit compatible
Important for the filesize, is the bitrate. The bitrate specifies how many bytes to use per second video. If you decrease the bitrate, the filesize will also become smaller.
You are currently using 250kbit/s video (-b 250k
) and 56kbit/s audio (-ab 56k
), so you have to decrease those numbers. For example you can try :-b 100k -ab 32k
. But keep in mind that the quality will also decrease when you decrease the bitrate. If the quality becomes too bad, you can also decrease the framerate or frame size to increase the quality.
Upvotes: 0
Reputation: 12721
You should try playing around with your key frames rate (-g). Frames between key frames have only the pixels different from the previous key frame. If your key frames are too far apart, all pixels are present in middle frames (increasing size), too close and the number of key frames increases the file size.
Note that the optimal key frame rate will be different for each video, so you need to find a middle ground.
Upvotes: 0
Reputation: 25493
Files converted from flv
to mp4
will always have greater size than the source file. Generally flv files are smaller than other formats, thats why youtube converts all files to flv.
you can use -sameq
parameter to retain the quality of video and lesser file size of resulting output file.
Example 1:
ffmpeg -i input.flv -sameq -ar 22050 output.mp4
Example 2:
exec("/usr/bin/ffmpeg -y -i input.flv -acodec libfaac -sameq -ar 44100 -ab 96k -coder ac -me_range 16 -subq 5 -sc_threshold 40 -b 1600k -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -i_qfactor 0.71 -keyint_min 25 -b_strategy 1 -g 250 -r 20 output.mp4");
I created this command by searching alot and this fulfills my requirements, using this you can get a bit less file size but with same quality.
Hope this works for you also.
Upvotes: 1