As usual it started with a tweet:
— Jim Groom (@jimgroom) June 30, 2016
The referenced tweet looked interesting:
RT for the early birds… https://t.co/OAXUuDbgY7
— Cartoon Brew (@cartoonbrew) June 29, 2016
I’ve tried Rotoscoping before, but this looked good. I hied over to MacOS/OSX – Paint of Persia community – itch.io, read about it. paid $5 and set things up.
At that point I realise that the app helps you to manually trace frames, seemed a wee bit time consuming. I though I’d leave it for another day. I did start musing on doing something similar, I was thinging FFmpeg & ImageMagick.
Google takes me to Fred’s ImageMagick Scripts: CARTOON.
so the plan is:
- export a movie to a series of images.
- cartoonise those image
- create a move from the cartoon images
Bounus points for getting the sound track back in.
I already have ffmpeg & imagemagick installed on my mac. These are commandline tools.
I downloaded the cartoon script
First find a video:
Rename the downloaded file shower.mp4
Open the terminal and cd into the folder that has the cartoon script and the movie in it.
First extract lots of still images (make a folder shower first
ffmpeg -i shower.mp4 -r 6 shower/out_%04d.jpg
this takes the input file (-i) at 6 frames per second and create jpg files in the shower folder with the file name out_0001.jpg ,out_0002.jpg ect
Given the movie is 3 minutes 22 seconds long I end up with 1212 images in the folder. I delete the last few manually to give me 1023 images.
I now need to loop through all of those images and create a cartoon version.
the use of cartoon is basically:
./cartoon face.jpg temp.jpg
There are some paramaters you can use but I stuck to the default.
This would take the image on the left and create the one on the right:
So I move into the shower folder
mkdir out;for i in *.jpg; do ../cartoon $i out/$i.jpg;done
makes a nother folder called out
for i in *.jpg for each file with a .jpg extension in the current folder do does:
../cartoon $i out/$i.jpg runs the cartoon script from the folder above (../), and saves the output file in the out folder with the same name.
When I kicked this off I quickly realised it would take a while to r=un through 1212 images, so went to bed.
Time to stich these together, it took me a few goes to get the paramaters right. (google helps).
ffmpeg -f image2 -framerate 6 -i out_%04d.jpg -c:v libx264 -pix_fmt yuv420p out.mp4
- -f chooses the format image2 which makes an image sequence.
- -framerate 6 to get the smae length of movie as I started with
- -i infiles confusinging names out_0001.jpg ect the %04d means look for 4 figured numbers starting with 0001
- -c codec
- -pix_fmt is the pixel format, I dn’t know much about these but the script failed until I added it in
It took me a few shots until I got this right.
I then moved the out.mp4 video to the same folder as the original and
ffmpeg -i shower.mp4 -acodec copy -vn shower-audio.mp4
To extract the audio from the original file.
ffmpeg -i out.mp4 -i shower-audio.mp4 -vcodec copy -acodec copy -shortest final.mp4
To add the audio from the original to the out video to give me a final one.
the -shortest parameter gets rid of the audio at the end to make up for the frames I removed.
At this point I remembered iMovie has a comic filter…
This post is mostly as an aid to my occasional dip into the world of commandline video editing. Posting helps me remember. It also plays a wee bit fast and loose with copyright.
The featured image is a gif giffed from a few of the stills.
ps this is quite a disturbing clip, I didn’t really watch it till I finished, could have picked a nice one!
Update, Ron commented: