Skip to content

ffmpeg

Okay this is a short summary of lessons learned in my ffmpeg journey to encoding and compressing my files.

I use a 27in iMac (called ScarMac due to its beautiful left-side scar that came with it) and record videos using the built in camera and Screenflow. The default export to h264 gave a compression that led to say 100 mb while the lossless export would be for that size about 1 gb. Because I wanted to export it to both a web view and for iPhone, I wanted to encode twice. I am a command line kind of guy so I looked up how to do ffmpeg.

My first stop was installing for mac It explained the need to install lame, faac, and faad before ffmpeg. I would also recommend installing libx264 (source, commands)though I feel like it should have already been there, but things worked after I did that.

So after compiling from source and installing (usual config and make steps),  then one needs to encode the videos. I found this site to be helpful: Perfecting h264 conversion with ffmpeg I will paste the commands I use below. Here is a site of cheatsheet codec stuff and some more commands

Now running the encoding on each file takes awhile and so I setup a python script to run through them. I have other scripts that compile my tex documents and organize them and create the html code to upload it all–I work hard at being lazy.

So then I have a bunch of .mp4 videos. The full size ones would be say 20 mb while the iPhone ones would be 40mb in relation to the sizes above.  (1.36gb became 46mb for full, became 103mb for iphone   vs. 169 mb for screenflow default; this is for a 31 minute screencast with slides/geogebra demo and my talking head in the corner) Quality is the same or better for the most compressed one. These compressions vary, of course, but in general these compression rates seem to hold. Pretty nice.

I used jwplayer to play the videos and found their article on compression to be quite useful. The codecs vs. formats confused me. One thing that I had to figure out was that .flv files are not to be used. Just use .mp4 files as they work in the flash player and should work in html5 too. I still have not figured out the full story on getting things to work on the iPhone, but someday I may understand it. Or just upload to YouTube and let them worry about it.

My python script:

import os
import re
from os.path import join
import subprocess
import shutil
import glob

num = "04"

src = "~/Desktop/"

destf = "~/videos/compiled/W%s/W%s_full/"%(num,num)

desti = "~/videos/compiled/W%s/W%s_iPhone/"%(num,num)

files = glob.glob(src+'*.mov')

print files

for fili in files:
    fil = (fili.split("/")[-1]).partition('.')[0]
    print fil

    #ipodTouch compatible?
    p = subprocess.Popen("ffmpeg -i %s.mov -b 1200kb -mbd 2   -cmp 2 -subcmp 2 -s 480x320 %s_i.mp4"%(src+fil, desti+fil), shell=True)
    p.communicate()

    #main file, small and good
    p = subprocess.Popen("ffmpeg  -i %s.mov -acodec libfaac -ar 44100 -ab 96k -vcodec libx264 -vpre slow -level 41 -crf 20 -bufsize 20000k -maxrate 25000k -g 250 -r 30 -coder 1 -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -flags2 +dct8x8+bpyramid -me_method umh -subq 7 -me_range 16 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -rc_eq 'blurCplx^(1-qComp)' -bf 16 -b_strategy 1 -bidir_refine 1 -refs 6 -deblockalpha 0 -deblockbeta 0 %s.mp4"%(src+fil, destf+fil), shell=True)
    p.communicate()

And that is what I know about ffmpeg encoding. It works for me and does a beautiful job. To do file transfers, I am currently using forklift.

Enjoy!

Update:

I augmented the audio volume levels by using

-vol 1024

which augments it by 400%, I believe. The setup is that 256 represents 100%, 512 200%, and so on.

{ 1 } Comments

  1. mythiclogos | September 13, 2010 at 8:36 pm | Permalink

    I augmented the audio volume levels by using

    -vol 1024

    which augments it by 400%, I believe. The setup is that 256 represents 100%, 512 200%, and so on.

Post a Comment

Your email is never published nor shared. Required fields are marked *