H264 video has increasingly been used in flash videos recently.
The challenge of most people have been to find out a sweet spot for encoding h264 flash videos which delivers near original quality but with significantly less file size than the original.
Here’s a code snippet that you can use for ffmpeg as shown below:
ffmpeg -i /yourfile.mov -y -f mp4 -vcodec libx264 -crf 28 -threads 0 -flags +loop -cmp +chroma -deblockalpha -1 -deblockbeta -1 -refs 3 -bf 3 -coder 1 -me_method hex -me_range 18 -subq 7 -partitions +parti4x4+parti8x8+partp8x8+partb8x8 -g 320 -keyint_min 25 -level 41 -qmin 10 -qmax 51 -qcomp 0.7 -trellis 1 -sc_threshold 40 -i_qfactor 0.71 -flags2 +mixed_refs+dct8x8+wpred+bpyramid -padcolor 000000 -padtop 0 -padbottom 0 -padleft 0 -padright 0 -acodec libfaac -ab 80kb -ar 48000 -ac 2 outputfile.mp4
The resulting command line switch above can produce outstanding results. You can use the ffmpeg application available in my rpm repository.
See the resulting h264 file below (original 720p file is 397mb, the flash optimized file is 89.4mb):



#1 by Kaizoku on February 17, 2010 - 4:37 pm
Quote
Very neat, just what I was looking for
To have filesize down even further, why not resize the video. ffmpeg doesn’t have built in scale caluculation, so we have to do it manually.
#!/bin/bash
# get original dimensions
dm=$(ffmpeg -i “${1}” 2>&1 | grep Video | cut -d ‘ ‘ -f 10)
# put the width in a variable
ow=$(echo ${dm} | cut -d ‘x’ -f 1)
# put the height in a variable
oh=$(echo ${dm} | cut -d ‘x’ -f 2)
# calculate the width to proportion of height and make sure its divisible by 16
width=$(echo ${t}*${ow}/${oh}/16*16 | bc)
# run the encode
ffmpeg -i “${1}” -vcodec libx264 -r 25 -s ${width}x${t} -crf 28 -threads 0 -flags +loop -cmp +chroma -deblockalpha -1 -deblockbeta -1 -refs 3 -bf 3 -coder 1 -me_method hex -me_range 18 -subq 7 -partitions +parti4x4+parti8x8+partp8x8+partb8x8 -g 320 -keyint_min 25 -level 41 -qmin 10 -qmax 51 -qcomp 0.7 -trellis 1 -sc_threshold 40 -i_qfactor 0.71 -flags2 +mixed_refs+dct8x8+wpred+bpyramid -acodec libfaac -ar 44100 -ab 64k -ac 2 “${output}”
#2 by Kaizoku on February 17, 2010 - 4:39 pm
Quote
Forgot to add the t variable is what you want your target height is, mine is set to 432.
t=432
#3 by clintcan on February 17, 2010 - 4:46 pm
Quote
Hey, nice one Kaizoku.
.
#4 by Abid Hussain on February 23, 2010 - 2:50 pm
Quote
Thanks mate, your command work really great with me too.
#5 by flashtastic on March 5, 2010 - 3:13 am
Quote
After much experimentation, this worked really great! Thanks!