simple way to make h.264 mp4 web and iOS/mobile playable video mp4 files for linux and macosx using ffmpeg

Greetings video geeks! 😎

At my job, I’ve updated the process and way we create our .mp4 files that are shown on video pages on archive.org

It’s a much cleaner/clearer process, namely:

  • I opted to ditch ffpreset files in favor of command-line argument 100% equivalents. It seems a bit easier for someone reading the task log of their item, trying to see what we did.
  • I no longer need qt-faststart step and dropped it. I use the cmd-line modern ffmpeg “-movflags faststart”

Entire processing is now done 100% with ffmpeg, in the standard “2-pass” mode
As before, this output .mp4:

  • plays in modern html5 video tag compatible browsers
  • plays in flash plugin within browsers
  • works on all iOS devices
  • makes sure the “moov atom” is at the front of the file, so browsers can playback before downloading the entire file, etc.

Here is an example (you would tailor especially the “scale=640:480” depending on source aspect ratio and desired output size; change or drop altogether the “-r 20” option (the source was 20 fps, so we make the dest 20 fps); tailor the bitrate args to taste):

  • ffmpeg -y -i stairs.avi -vcodec libx264 -pix_fmt yuv420p -vf yadif,scale=640:480 -profile:v baseline -x264opts cabac=0:bframes=0:ref=1:weightp=0:level=30:bitrate=700:vbv_maxrate=768:vbv_bufsize=1400 -movflags faststart -ac 2 -b:a 128k -ar 44100 -r 20 -pass 1 -acodec aac -strict experimental stairs.mp4;
  • ffmpeg -y -i stairs.avi -vcodec libx264 -pix_fmt yuv420p -vf yadif,scale=640:480 -profile:v baseline -x264opts cabac=0:bframes=0:ref=1:weightp=0:level=30:bitrate=700:vbv_maxrate=768:vbv_bufsize=1400 -movflags faststart -ac 2 -b:a 128k -ar 44100 -r 20 -pass 2 -acodec aac -strict experimental -metadata title='”Stairs where i work” – lame test item, bear with us – http://archive.org/details/stairs’ -metadata year=’2004′ -metadata comment=license:’http://creativecommons.org/licenses/publicdomain/’ stairs.mp4;

Happy hacking and creating!

PS: here is the way we compile ffmpeg (we use ubuntu linux at work, but this script works on macosx, too).

honda CB400A — fixing turn signal and neutral LEDs (to new speedometer)

Whups, my new speedo’s turn indicator LED was only going on when left signal was running.

Thankfully, found this post on hondatwins that mentioned the orange and light blue bike lines were actually active lines for when left or right turn signal was on — not that they were positive and negative general lines. It also mentioned a (cheap/simple, yay!) fix to use two 3-amp diodes and tie them in together. A quick putt-putt to Radioshack and $2 later…

Success!

I focus mainly on that in this image, but also some other related notes.

annotated picture of wiring behind headlight

 

I also have my new speedo’s neutral LED light now turning on when bike is on (but not running) — will see tomorrow if it *also* properly goes *off* when shift up when bike is running.

decaf 1978 honda CB400A speedometer and instruments replaced!

OK, so I sorted out all my re-wiring and was able to replace my stock honda huge instrument cluster with a much smaller and streamlined single mini-speedometer with four instrument lights combined in it.

I used a CB400A wiring clymer manual image that I found online to sort out which wires connect where. I also cleared up quite a few wire clusters that no longer needed to leave the headlight wire storage area and made space for the new connections.

VERY satisfying! Can’t wait to fire her up tomorrow and hopefully the speedo/odometer work properly and track accurately. The indicator lights I could test (blinkers, hi-beam, as well as instrument backlight) work. Will see if my neutral light works tomorrow too (and hopefully will not see the “oil pressure” light come on ever 😎 )

replacing CB400A instruments to smaller cafe racer style

Today I did much more than I thought I would — I pulled out and disconnected all instruments and relocated the ignition/key switch.

The plan is to combine the current speedometer/odometer with four of the seven indicator lights (neutral, high beam indicator, oil warning light, turn signal indicator) into a smaller chrome combined unit, and just plain omit the other three lights (parking brake, 1st gear, 2nd gear).

Now that I’ve done more than I had planned (“oh, maybe just two bolts today to see if I can figure out more what I’m up against…”) it is time to order parts! 😎

decaf! Honda CB400A automatic cafe racer. I’ve been a bad girl today….

Today Hunter helped me inspect, test-drive, buy, and drive 100+ miles home from a mom-n-pop custom bike modifier in California’s central valley.

We avoided the 5 and all freeways and started out with about an hour of “country roads” and farm roads that were mostly straight and flat. Next we nearly ran out of gas but recovered thanks to the “reserve switch” to fillup in Tracy. Finally, we started the fun curvy and up-and-down stuff through the northwest backside of Mt. Diablo and had a late lunch in Clayton. We wrapped it up through Moraga, and then our favorite twisty mountain pass up Pinehurst to Skyline Blvd and home

What an wild day!

I’ve named her “decaf” since she’s an automatic (with just “lo” and “hi” gears, no clutch) *and* a cafe racer style modified bike. I’m really pleased she did so well on the first ambitious ride all the way home.

Here’s some bike porn / pix!

20121013-200557.jpg

20121013-200621.jpg

20121013-200645.jpg

convert yuvj420p to yuv420p (chrome playable!) mp4 video (eg: canon/nikon video)

hooray!

found a nice (video lossless, best i can tell) way to convert the video from cameras like my Canon ELPH SD1400,
which is *already* h.264 video + PCM mono audio

to a new mp4 container with aac audio. that part’s easy/cake w/ ffmpeg — but the trick to get the h.264
video part to play in chrome browser and/or with a flash plugin is to get the flagged “yuvj420p” colorspace pixels
to be considered “yuv420p”. it seems like the former is >= 8 bits-per-pixel and has a range wider than the 256 values;
while the later is 8 bit per pixel. ( brief info/notes/background )

at any rate, finally found this nice post:

https://blendervse.wordpress.com/2012/04/02/waiving-the-fullrange-flag/

which refers to this modified MP4Box/gpac tree, to switch the “fullrange” color-related flag off:
https://github.com/golgol7777/gpac

and then, voila! i have a nice little script where i can convert my canon ELPH videos to a html5 video tag and flash plugin compatible mp4:


#!/bin/bash -ex

IN=${1:?"Usage: [input video] [output video]"};
OUT=${2:?"Usage: [input video] [output video]"};

# make a hacked version of "mp4box" that can toggle a colorspace-related flag in our video!
if [ ! -e $HOME/scripts/mp4box ]; then
(git clone https://github.com/golgol7777/gpac.git && cd gpac) || \
( cd gpac && git reset --hard && git clean -f && git pull && git status );

./configure --enable-pic --static-mp4box --enable-static-bin
make -j4;

# bonus points: make a *static* binary so if we change linux/OS versions, dont hafta worry!
cd applications/mp4box;
gcc -o $HOME/scripts/mp4box -static main.o filedump.o fileimport.o live.o -L../../bin/gcc -lgpac_static -lm -lpthread -ldl -lz
fi

# demux
ffmpeg -y -i "$IN" -an -vcodec copy video.mp4;
ffmpeg -y -i "$IN" -vn -acodec copy audio.wav;

# convert yuvj420p to yuv420p the cheater way (for chrome and flash plugin playback!)
rm -fv tmp.mp4;
$HOME/scripts/mp4box -add video.mp4#:fullrange=off tmp.mp4

# convert wav audio to aac
ffmpeg -y -i tmp.mp4 -i audio.wav -acodec libfaac -ac 1 -ab 256k -vcodec copy t2.mp4;
qt-faststart t2.mp4 "$OUT";
rm -fv video.mp4 audio.wav t2.mp4 tmp.mp4;

deinterlacing 2323 telecine video into fields for visual analysis

Having some challenging fun working on trying to deinterlace some toughie clips
from my brother’s upcoming feature film.

His camera recorded in 24fps (24000/1001 to you fellow geeks 😎 and smartly
did a “2323” writing/stretching of it to 60i (60 half-frames).
After correcting back to 24fps progressive most of his clips, he’s found ~10-20%
are not able to be put back together visually properly even with CineTools
and manually specifying the “cadence” and sequence starting frames, etc…

I started with code that I wrote to take a small segment of a video
and split the interlaced frames into 1/2 height “fields” and then drop them
down to grayscale to compare them all to each other to find the best matches
(to verify the cadence is right and/or the fields aren’t “off by 1”, etc..)

It uses mplayer and ImageMagick (“convert” and “compare”) for pretty high-quality
extraction of frames from the source video into the 1/2 height “fields”.

So I just do about 0.3 seconds to get 10 frames, and thus 20 1/2 frame fields for analyzing.
It will output the best matches of frames. For example:

php lacer.php good.mov 0.5 0.8

I then extended it into a web page (screenshot above, where I’m left-shifting one field by 4 pixels for visual inspection)
PHP script <== try it out online! (source)
that uses some CSS cleverness (clip property is your BFF!) to interlace together a pair of fields.
It supports:

  • field swapping (move one 1/2 image to be the 1st, 3rd, 5th, etc. lines — if it was
    previously the 2nd, 4th, 6th, etc. lines)
  • left and right shifting a field
  • pairing arbitrary fields
  • showing a “raw” 60i telecined sequence
  • showing the 60i sequence as a “deinterlaced” 24P sequence

my town, 1947 style!

Our amazing next door neighbor, Reenie Raschke, the super talented photographer has lovingly chronicled our town in a black-and-white pictorial called “My Town Montclair“.

We saw her present slides and background from her book last night at our local indie bookstore. She passed around this gem of an original 60+ year old newspaper showing our downtown as it was!

20120210-211412.jpg