Cutting Music Videos

From MythTV Official Wiki
Revision as of 23:48, 12 November 2008 by Malban (Talk | contribs)

Jump to: navigation, search

Editing a long recording to cut out (multiple) shorter sections can be tedious and usually involves the use of external editing tools such as avidemux. Presented below is a crude method for performing this task from the frontend using a custom user job.


SCRIPT

Script.png cut_music.sh

#!/bin/bash
# cut_music.sh
#
# A small script to process a cutlist from a recording a place
#+ the result in your music videos directory.
#
# Written by Marcus Brown for the purpose of sharing with the mythtv project and it's users.
# Do what you like with it ... no license or copyright.
#
#

NICE="nice -n19"
TRANS_OPTS="--mpeg2 --honorcutlist"

# The variables passed to the script
CHANID="$1"
STARTTIME="$2"
TITLE="$3"
 
MUSICVIDEO_DIR="/myth/video/videos/Music"
MUSICVIDEO_PLS="/myth/video/videos/All Music Videos.pls"


# Assume that the title is in the format "BANDNAME - SONGNAME"
BAND="${TITLE%% - *}"
if [ -z "$BAND" ]; then
    echo "UNABLE TO PROCESS MUSICVIDEO \"$TITLE\""
    exit 1
fi

OUTDIR="$MUSICVIDEO_DIR/$BAND"
mkdir -p "$OUTDIR"
OUTFILE="$OUTDIR/$TITLE.mpg"

if [ -f "$OUTFILE" ]
  then
    #echo "ERROR: OUTFILE ALREADY EXISTS FOR \"$TITLE\""
    #exit 1
    echo "OVERWRITING OUTFILE: \"$TITLE\""
  fi
 
echo "mythtranscoding MUSICVIDEO from $INFILE to $OUTFILE"
if $NICE mythtranscode -c "$CHANID" -s "$STARTTIME" $TRANS_OPTS --outfile "$OUTFILE"
  then
    echo "MUSICVIDEO \"$TITLE\" SUCCESSFULLY PROCESSED"
  else
    echo "ERROR TRANSCODING \"$TITLE\""
    exit 1
fi


# Marcus might want to post-processs
#+ ... not a good idea when doing a lot of videos

### REMOVE =EXIT 0= FOR POST-PROCESSING ####
exit 0

# Marcus uses a dummy playlist which is executed by a custom command that fills the playlist on execution.
#+ The DUMMY option is to fill the list without playing
#$NICE play_random.sh "$MUSICVIDEO_PLS" DUMMY

# Marcus wants the video items with length=0 to be updated to real minutes.
#$NICE fixzerolength.sh

# Marcus has the playlist at parentalrating=1, and the videos at parentrating=2
#$NICE update_ratings.sh

# Marcus likes the playlist summary to show the total play time
#$NICE update_playlist_times.sh


# Marcus copies the playlist to the frontends
FRONTENDS="loungetv bedtv"
for FRONTEND in $FRONTENDS
  do
    echo "Copying new playlist to $FRONTEND"
    scp "$MUSICVIDEO_PLS" $FRONTEND:"$(dirname "$MUSICVIDEO_PLS")"
  done

exit 0


Important.png Note: Sections starting with "# Marcus..." can be ignored, commented or deleted.


INSTALLATION

Copy the script to somewhere in the $PATH on the backend (eg. /usr/local/bin/), and make it executable. Stop the backend, and using mythtv-setup, create a user job called "Cut to Music" with:

cut_music.sh "%CHANID%" "%STARTTIME%" "%TITLE%"

and ensure that the backend is allowed to run this user job.


USAGE

Let's say you've recorded a show called "Hot Video Clips" (in mpeg2). Edit the show, and insert cut-points for the first song. Exit, and by selecting "Recording Options", then "Change Recording Title" proceed to change the name of the show to that of the song in the format "BAND NAME - SONG NAME". The recordings list will reload and then the recording can be processed by the user job by selecting "Job Options", "Cut to Music". The resulting mpeg2 video will be placed in

$MUSICVIDEO_DIR/$BAND/

where a hyphen ("-") is used to delimit the band and song.

When the transcode is finished, you can then proceed to cut the next song. Simply rename the recording, insert new cut points and run "Cut to Music" again.


CRUDENESS and WORKAROUNDS

Only one job per recording can be processed at a time.

As the cutlist needs to be present during the transcode, editing the recording for the next song is not possible until the previous job has completed.

Title-changing awkwardness

Using a simple remote control is a little tedious for renaming titles. A real keyboard makes this a lot easier.

Simultaneous editing and transcoding

By using a multirec-enabled version of mythtv ( >= 0.21, or 0.20-multirec) multiple overlapping recordings can be made thus enabling you to edit+cut one recording while another is being processed.