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;

Published by

tracey pooh

i like digital video and road cycling

3 thoughts on “convert yuvj420p to yuv420p (chrome playable!) mp4 video (eg: canon/nikon video)”

  1. thanks for this, a neat solution. for any fellow mac users like me, it works great on a macbook too with a minor modification – commenting out the “make a static binary” and “qt-faststart” lines. I also ran into a problem in that my ffmpeg doesn’t do aac encoding. However there is a command line utility “afconvert” on the mac for qt encoding which does the job. So I added an extra line after the MP4Box line:
    afconvert -f mp4f -b 256000 audio.wav audio.aac
    and then modified the ffmpeg line to use the file generated above rather than convert on the fly
    ffmpeg -y -i tmp.mp4 -i audio.aac -acodec copy -vcodec copy "$OUT"

  2. This is the second article, of your blog I personally went through.
    However , I personally enjoy this particular 1, “convert yuvj420p to yuv420p (chrome playable!
    ) mp4 video (eg: canon/nikon video) | PoohBot Pictures and more” the most.

    All the best ,Micki

Leave a Reply

Your email address will not be published. Required fields are marked *