Posts tagged command line

Setting up/Moving a Cinelerra Project

I finally decided to reorganize my current video project to make things easier to find.  For starters, I realized that all the raw dv footage I’ve captured should not be in the same folder as the project itself.  That is a recipe for creating copies of the same footage later when I want to use it in another project.

Instead, I created a folder for my footage named by date and subject and stored it with the rest of my similar captured footage.  That way it is ready for me to grab for any project.  Next, I created a project folder (I called it “project_wbp” in my case).  Inside that I added another folder called “media_rawdv”.  Then I used this command in a terminal:

ln -s -t /path/to/media_rawdv /path/to/original/*.dv

That command creates symbolic links (i.e. shortcuts) to all the original files.  Cinelerra doesn’t care whether its resources are real files or links, so this works fine.  Later, if I move the original files, I can just recreate the links and I’m all set.

There are two important steps  you need to do when you move things around or rename them in your project:

1. You should edit your project .xml file and change the paths as necessary (note that Cinelerra doesn’t seem to like relative paths, so you should use absolute ones).  Don’t forget to change the path to the xml file itself if that has moved.  Any text editor can handle this.

2. To save a lot of processing on large projects with many resources, you should rename all the project’s index files (you can change the location in Cinelerra’s settings, but they’re usually in ~/.bcast”) and change the internal paths in each file.  The following program should do the trick:

#!/bin/bash
#first rename the files in .bcast
rename ‘s/home_video_oldname/home_video_project_wbp_media_rawdv/’ ~/.bcast/*.idx
#next use this to fix the internal paths in the index files
OLD=”\/home\/video\/oldname\/”
NEW=”\/home\/video\/project_wbp\/media_rawdv\/”
DPATH=”~/.bcast/*.idx”
BPATH=”~/.bcast/bak/”
TFILE=”/tmp/out.tmp.$$”
[ ! -d $BPATH ] && mkdir -p $BPATH || :
for f in $DPATH
do
if [ -f $f -a -r $f ]; then
/bin/cp -f $f $BPATH
echo $f
sed “s/$OLD/$NEW/g” “$f” > $TFILE && mv $TFILE “$f”
else
echo “Error: Cannot read $f”
fi
done
/bin/rm $TFILE

The only things to change in the preceding script are the two paths in the rename command and the same in the OLD and NEW variables.  Note the the index files include real paths (hence the \ escapes to make the literal / characters work), but in their names they replace the / characters with underscores.

For smaller projects, you could probably skip this step, as Cinelerra will regenerate the files anyhow.  For my 40 minute video, which has hundreds of clips, it takes hours to do this.   The script does the job in a couple of minutes.

Ubuntu Studio Tweaks

As I’ve been using Ubuntu Studio, I’ve discovered a number of must-have (for me, anyhow)  packages which were not installed by default.

As with any Ubuntu-based distro, there are a number of steps required to enable non-free and/or non-supported software.  I won’t bother to go into them, because Ubuntu has reached the point where it mostly prompts you to add codecs and things when you need them.  Of course, you should enable all repositories in the application manager (better yet, use Synaptic or, my favourite, Aptitude from the command line).

One exception I had to add was the “unstripped” versions of all the ffmpeg libraries.  I don’t think this is actually broken, just disabled in the default version of Ubuntu.  I just went into Synaptic, searched for ffmpeg, and added all the packages with “unstripped” in the name. (for details see Bug #254201 in ffmpeg-debian (Debian): “feature regression: ffmpeg lacks some video encoders (like h263+, MPEG4, maybe more…)”).  I use ffmpeg at the command line to encode video files and it is used in the background by many other video manipulation tools.

Some other packages I wanted to add to UbuStu:

  • openoffice (I used it to log my clips in a spreadsheet)
  • emacs (indispensable for tweaking config files and taking notes)
  • ntp (to make sure I’ve got the right time)
  • fslint (very useful for finding and removing duplicate files)
  • most (better than more or less for paging)
  • flashplugin-nonfree (to play flash in Firefox)
  • gstreamer (and plugins)
  • rhythmbox (my favourite jukebox for large music collections)
  • mplayer (commandline video player)
  • wv (commandline msoffice document dump)
  • elinks (commandline browser — comes in handy more often than you’d think)

I’m sure I’ll add plenty of more packages as I go along, but these are a few of the ones I’ve wanted so far.  I’ve also added a number of other applications, such as PiTiVi, Kdenlive, Avidemux, VideoCut, which I’m hoping to play with and get to know better.

Capturing Video Over Firewire in UbuStu

Today I wanted to capture some video from mini-DV tapes using my camera, a Panasonic mini-DV model. I have done so in the past using a firewire cable, but this is the first time I’ve tried with my new Ubuntu Studio setup.

Here are the steps to follow:

1. In “Ubuntu Studio Controls,” check “enable raw1394 access.” If you try to use your firewire device now, it may crash the machine, so you should reboot before proceeding. I had the system freeze up on me two or three times before I had everything working reliably (this may be a result of the wonky firewire connection on my camera, which seems to be loose).

2. After the reboot, put the camera into VCR mode and press play. Then run Kino (from a terminal as root) and switch to capture mode. You should see the video playing in the Kino window. Rewind the tape again before you proceed. This step seems to be necessary in order to get Ubuntu Studio to recognize the camera as a firewire device (dvgrab may work just as well).

3. If you aren’t capturing a whole tape, you could just use Kino to control the camera and capture the clips. I actually prefer to do the capture from the command line using dvgrab.  To begin capture, enter this command (again as root):

#dvgrab –autosplit –frames 0 –size 0 –format raw –timestamp <dest>/<foo>

In this command, <dest> is the place you want to store the clips (e.g. /home/video), and
<foo> is whatever prefix you want the resulting filenames to have (e.g. tape1-). The clips will automatically be split into files and the timestamp will follow the prefix in each name.

Once you run the dvgrab command, it will wait for you to press play on the camera and begin capturing the clips. You’ll have to press <ctrl>-c once the clips are finished being captured.

Because of the broken firewire connection on my camera, I investigated the possibility of using USB to capture video, but that doesn’t appear to be a viable choice (and much slower, even if one could get it to work).

More info on firewire in Ubuntu here: Firewire – Community Ubuntu Documentation

Sorting Out My Music Library

I have about 140GB of music which I have ripped from my CD collection or downloaded.  Since I was moving files around anyhow and eliminating my server, I decided I should reorganize my music library a little.  It contains files in several formats, with many duplicates.  I’m not finished, but I did make significant progress using the following techniques (some of which would work for any large collection of files of any type).

First, I decided that I would try to store everything in directories according to <Artist>, then <Album>.  I used to think that it didn’t matter how the files were organized because jukebox programs (like Rhythmbox, my usual choice) use tags to sort things out anyhow.  My son puts the <Artist> directories in <Genre> directories to help manage them.  I find that too arbitrary (plus it is a daunting task requiring even more hand-sorting).  I would’ve kept the <Artist> directories all together, but there are simply too many to be manageable, so I decided to put them in alphabetical ranges (<A-F>, <G-M>, etc.).

Secondly, I decided that I would try to name the files according to “<Artist> – <Title>.<extension>” format.  That doesn’t matter for the files which are already sorted into directories, but it was necessary for all the unsorted files named things like “Track 05.mp3″.

Tools which I found useful:

EasyTAG – Tag editor for MP3, Ogg Vorbis, FLAC, MusePack and Monkey’s Audio files, …

This program is not extremely friendly, but it bridges the gap between filenames and tags.  The tags can be used to create new filenames.  Beware that this can be a fairly slow process.  Some notes about Easytag:

  • you must navigate to the folder where your files are, but every time you move from one folder to the next in the program, it prompts you to save changes even if you haven’t made any;
  • be careful to select all of the files you want to modify in the middle window before proceeding;
  • select “Rename Files and Directory” from the “Scanner” menu.  Select the naming pattern you want from the drop down and click the greenish scan button.
  • note that the changes don’t actually happen until you navigate away from the current directory and confirm that you want to make the changes;
  • the file renaming works quite reliably, but takes a long time if you have many files.

Easytag has lots of other features, but I haven’t tried them yet.

Bulk Rename Utility

This is a great utility for renaming many files at once and previewing the results before you commit the changes.  Unfortunately, it doesn’t seem to work on directory names (though it does work on filenames across directories).

The rename command

This is a bash utility for renaming files according to a regular expression pattern.  It does work on directories as well as files.  I love sed and this tool is a quick and easy way to use it’s power for renaming.  For example, to replace underscores in file or directory names with spaces:

$rename ‘s/_/ /g’ *