Monday, February 21, 2011

The New And Improved Clockwork PC Webcasting Script

WARNING: THIS IS A VERY GEEKY POST! READ AT YOUR OWN PERIL!!!

#!/bin/bash

### The Clockwork PC Webcasting Script###

# This script is the fruit of many hours of research into FFMPEG.

# You will need ffmpeg with x11grab, and a number of libraries that should be installed automatically.

# You will need a custom directory ~/Videos/Screencasts, otherwise change the output directory in the commands.

# You will also need to download and install the newest xcowsay from its homepage,
# because the older xcowsay from the Ubuntu repositories (2010-08-31 at the time of writing) will not work with the --monitor option.

# The chained command creates THREE separate files:
# x11grab for your desktop,
# video4linux2 for your webcam,
# alsa for your microphone or headset.

# This is very important to me because I use Openshot Video Editor, which cannot split audio and video yet, but can combine them very well.
# If this is not important to you, there are many fine commands that combine audio and video streams into a single file, so you don't have to use mine.

# However, this chained command will record everything synchronously, including webcam and audio.

# Enjoy!

# Alexander,

###

# Create a temporary folder called "video bin"
mkdir $HOME/Videos/Screencasts/video_bin/

#!/bin/bash

# Record the desktop at 1440x900 (change to your resolution) using ffmpeg
gnome-terminal -x ffmpeg -f x11grab -r 25 -s 1440x900 -i :0.0 -qscale 1 -vcodec libx264 -vpre lossless_ultrafast $HOME/Videos/X11Grab/X11Grab_on_$(date +%F_%A_at_%H:%M:%S).m4v ;
#!/bin/bash

# Record the microphone audio using ffmpeg && Open a GUVcview recording to the same folder as the other two
gnome-terminal -x ffmpeg -f alsa -ac 2 -i pulse -acodec pcm_s16le $HOME/Videos/Audio/Audio_on_$(date +%F_%A_at_%H:%M:%S).wav ;
#!/bin/bash

# Open a GUVcview recording to the GUVCView and video_bin folders
guvcview --device=/dev/video0 --video=$HOME/Videos/GUVCView/capture.mkv &&
cp $HOME/Videos/GUVCView/capture.mkv $HOME/Videos/GUVCView/webcam_on_$(date +%F_%A_at_%H:%M:%S).mkv && mv $HOME/Videos/GUVCView/capture.mkv $HOME/Videos/Screencasts/video_bin/webcam_on_$(date +%F_%A_at_%H:%M:%S).mkv
#!/bin/bash

# Copy the X11grab into the video_bin
cd $HOME/Videos/X11Grab && cp `ls -x1tr *.m4v | tail -n 1` newest.m4v &&
cp $HOME/Videos/X11Grab/newest.m4v $HOME/Videos/Screencasts/video_bin/x11grab_$(date +%F_%A_at_%H:%M:%S).m4v &&

# Copy the Audio into the video_bin
cd $HOME/Videos/Audio && cp `ls -x1tr *.wav | tail -n 1` newest.wav &&
cp $HOME/Videos/Audio/newest.wav $HOME/Videos/Screencasts/video_bin/audio_$(date +%F_%A_at_%H:%M:%S) &&

# Rename "video bin" to a "bin [date stamp]"
mv $HOME/Videos/Screencasts/video_bin/ $HOME/Videos/Screencasts/bin_$(date +%F_%A_at_%H:%M:%S)
#!/bin/bash

# Call up a cute cow with a message
(gnome-terminal -x xcowsay --cow-size=large --time=3 --monitor=0 "Your video has been recorded :)"&);

# Play an audio track of your choice (Moo!)
(gnome-terminal -x mplayer $HOME/Videos/Sound_effects/moo.wav)

2 comments:

  1. I was playing around a bit about something just like this!

    I had to make some changes just to fit on my settings but it was nice to found this recipe ;-)

    ReplyDelete
  2. I tried the earlier version of this script I found in Ubuntu forum. That version output the screencast as AVI. The problem that I found for that script is:
    1. The audio and the webcam is shifted, I have to play the webcam about 2 sec later. But this is no big deal.
    2. The AVI file is not in sync with the other two files. I have to slow it down by 0.78 so that it syncs with the other two.
    3. Openshot does not like AVI, it crashes everytime I try to scale an AVI file. I have to change the file to an MP4 so that I can slow it down in Openshot.
    4. The most terrible thing is, even if I have sync everything perfectly during the preview in Openshot, it becomes unsync again during export so that the screencast is way too slow than the other.

    My questions are:
    1. Do you have the unsync problem that I have above? The AVI video is literally shorter than the other two files.
    2. Do you have the Openshot problem as I describe above?

    Thanks for the script. I have made just 3 videos so far with the old script. Is there anything I can do before I remake the video using this updated script?

    ReplyDelete