User Tools

Site Tools


scripts:cat5convert
Description

Category5 Technology TV broadcasts a live show each week, and after each show, I have to convert a lot of junk. A long time ago, I created a dirty little script to do most of the work for me. A number of weeks ago, [http://www.ubuntupodcast.net The Ubuntu Podcast] mentioned this on their show (thanks for the props, guys!), wondering if they could get a copy of my handy-dandy script to save themselves some time and headache each week.

So, I cleaned up the code (as it was never actually intended for distribution) and here it is. Hope you enjoy.

Please feel free to post improvements if you have any, which can benefit anyone who decides to use this.

What You Get

When you apply your video file to this script, you'll get: * an OGV version * an MP3 audio-only version * screengrab thumbnails in 640, 320 and 200 width JPG images * a packaged ZIP file with all the thumbnails from the video

I'm always willing to make additions or improvements, so feel free to post suggestions and/or requests.

Known Issues

* With some source files, OGG video files are playing back too fast.

Current Official Version

1.2

Operating Platform

* Linux

Dependencies

* a computer running Linux * minimum 2 core system for reasonable performance * ffmpeg * ffmpeg2theora * imagemagick

The Script
cat5convert.sh
#!/bin/bash
 
# set the source extension (eg. avi, flv, mp4, etc)
SOURCETYPE=avi
 
echo
echo Video file converter script based on Category5.TV\'s method.
echo Slapped together by Robbie Ferguson for the guys over at www.ubuntupodcast.net
echo Version 1.2
echo
echo Please note: this is an extremely CPU-intensive script.
echo              Not recommended for anything less than a dual-core system.
echo
echo To install:  sudo apt-get install ffmpeg ffmpeg2theora imagemagick
echo To run:  $0 filename
echo          Don\'t specify extension\; must match SOURCETYPE \(currently $SOURCETYPE\)
echo          You can change this by editing $0
echo
 
if [ -z "$1" ]; then
exit 1;
else
 
# make mp3
# because we love to appease the masses
 
  echo Creating MP3 file from $1.$SOURCETYPE
	echo
	ffmpeg -acodec mp3 -vn -ab 112k -i $1.$SOURCETYPE $1.mp3 &
 
 
# make ogv
# because we love to support open source!
 
	# Specify the source bitrate here
	# (if playback seems fast or slow, set value to match source video)
	FPS=29.97
 
	# specify video quality 1-10
	VIDQUALITY=5
 
	# specify video bitrate 1-16778
	VIDBITRATE=500
 
	# specify audio quality -2-10
	AUDQUALITY=8
 
	# specify audio bitrate
	AUDBITRATE=112
 
	# choose deinterlacer (lb, li, ci, md, fd) - see 'ffmpeg2 --pp help' for details
	DEINTERLACER=lb
 
	echo Creating OGV file from $1.$SOURCETYPE
	echo
	ffmpeg2theora -F $FPS -v $VIDQUALITY --optimize -V $VIDBITRATE --pp $DEINTERLACER --deinterlace -a $AUDQUALITY -A $AUDBITRATE -o $1.ogv $1.$SOURCETYPE &
 
 
# make screenshots
# First, extract 1fps to PNG files.  Then save those into an accelerated video file.  Then, extract images at 1fps from the accelerated file.
# There might be a better way to do this, but it is pretty zippy, and gets the job done.
# This results in approximately 150 pictures of a one-hour video.
# I output in 640, 320 and 200 widths.  The 200 is what we use for web site thumbs, 320 is for RSS, and 640 is for archive.
 
	echo Creating screen grabs from $1.$SOURCETYPE
	echo
 
	mkdir $1_640
	ffmpeg -i $1.$SOURCETYPE -s 640x480 -r 1 -f image2 $1_640/%05d.png
	ffmpeg -i $1_640/%05d.png -b 512 -qscale .1 $1_640/$1_accel.avi
	rm $1_640/*.png
	ffmpeg -i $1_640/$1_accel.avi -an -r 1 -y $1_640/$1_%d.jpg
	rm $1_640/$1_accel.avi
	mkdir $1_320
	mkdir $1_200
	cp $1_640/* $1_320/
	cp $1_640/* $1_200/
	mogrify -resize 320 $1_320/*.jpg
	mogrify -resize 200 $1_200/*.jpg
 
# create a distributable zip archive of the thumbnail images
# because we like to share...
	zip thumbs_$1.zip $1_640/* $1_320/* $1_200/*
fi
Changelog

1.2 - Added dynamic script name to usage instructions. Very minor.

1.1 - Added FPS override to fix framerate issues when video framerate is not detected correctly. Make sure you set FPS to match the source video if OGV playback seems fast or slow.

1.0 - Cleaned up my code and created this redistributable version of my conversion script at the request of www.ubuntupodcast.net

scripts/cat5convert.txt · Last modified: 2012/01/26 09:18 by import