I am currently trying to create a shell interface for mplayer2 specifically for DVD playback. The (apparently unsolvable) problem is that the audio has gaps at the chapter marks on some DVDs during playback in dvdnav:// mode, and I get "ac-tex damaged" messages that I don't get in dvd:// mode (MacPorts-mplayer1 in Mac OS X has the same problem). The DVDs in question are OK because they play perfectly well in VLC and the Mac's DVD Player, and also with mplayer in dvd:// mode (which does not allow me to switch titles though, so I cannot play DVDs without menus properly).
VLC will switch titles on DVDs without menus correctly. However, I don't want to use VLC for DVD playback any more, because it obviously isn't primarily intended for that purpose (too many DVDs cannot be played at all, and frankly, I don't think that lua can do things like named bookmarks, starting DVD playback from a default bookmark, and resume. I already know that a VLC bookmark does not find the correct DVD title and audio track)
I don't want to use mplayer-tools either, because it is a bad idea to put config files in the same directory as the media files. I want to create individual settings files for every DVD in $HOME/.mplayer (or a subdirectory), using disc_id from libdvdread-0.9.7 (./configure --disable-shared --disable-static // make // do not install, copy files manually to /usr/local/bin) to get a (hopefully unique) serial number for the DVD, which I want to use for the settings file's filename. (The Mac's DVD player gives a different number in the settings file's name for the same DVD, but those files are encrypted)
Does anybody know how to fix the audio in DVD playback in dvdnav:// mode? Or a replacement for mplayer that actually works? I just compiled mpv which is a disappointment (No dvdnav support at all, no switch_title command)
I am using Ubuntu 12.04.2 with MATE desktop (mplayer audio does not work in LXDE either). iMac 7.1, ATI Radeon HD 2400 XT, sound hda-intel, kernel 3.8.0-22-generic. Installing the fglrx driver did not help, nor trying out various things in .mplayer/config. I will give more information if needed.
And no, I don't want to use the various graphical interfaces for mplayer. Been there, done that.
Here is what I have so far (No use going on with this if mplayer does not work):
Code:
#!/bin/bash
#dvdplayer script using mplayer
if [ ! -e "$HOME/.mplayer/fifo" ]; then
mkfifo $HOME/.mplayer/fifo
fi
rm -f $HOME/.mplayer/tmp
PROTOCOL='dvdnav://' #Maybe add a switch to choose between dvd:// and dvdnav://
if [ "$1" ]; then
DVD_DEVICE=`echo "$1" | sed "s/\'//g"` #drag an iso file or VIDEO_TS folder to the terminal
else
DVD_DEVICE=$(cat /etc/mtab | grep udf | awk '{print $1}') #will find external drive
#Mac OS X:
#DVD_DEVICE=$(echo '/dev/r'`disktool -l | grep udf | cut -d \' -f 2`)
fi
#in the following command, slave mode is not necessary but useful for testing
(mplayer $PROTOCOL -dvd-device $DVD_DEVICE -nocache -msglevel identify=9 -fs -slave -mouse-movements -input file=$HOME/.mplayer/fifo >> $HOME/.mplayer/tmp) &
#Even the highest msglevel will not give a DVD serial number in dvdnav:// mode. The libdvdnav messages will appear in the Terminal but that's not much help.
sleep 3
#The dvdnav developers seem to confuse titles with titlesets. If I understand correctly, the *titleset* N is the set of VTS_N_[0-9].{BUP,IFO,VOB} files in the VIDEO_TS folder, while the *titles* are coded in the .IFO files. The dvdnav message "switching to title N" actually refers to titleset N. So the following is actually dicey :(
case $PROTOCOL in #make a function of this and call it again with trap EXIT
dvdnav://)
TITLE=$(cat $HOME/.mplayer/tmp | grep 'DVDNAV, ' | tail -n1 | awk '{print $5}' | sed "s/\r//g")
;;
dvd://)
TITLE=$(cat $HOME/.mplayer/tmp | grep ID_DVD_CURRENT_TITLE | tail -n1 | cut -d \= -f2)
;;
esac
#creating custom variables for later use in scripts (More will follow, like CHAPTER, AUDIO_TRACK, SUBTITLE_TRACK, RESUME_BOOKMARK, DEFAULT_BOOKMARK, SETTINGS_FILE etc. For now saved here, later in separate files)
echo TITLE="$TITLE" >> $HOME/.mplayer/tmp
#touch $HOME/.mplayer/`disc_id $DVD_DEVICE` will create the settings file. Maybe create two files, one with permanent settings like default bookmark, named bookmarks and any other stuff that's settable, and another with the resume bookmark (`disc_id $DVD_DEVICE`.tmp which can be overwritten).
echo DVD_DEVICE="$DVD_DEVICE" >> $HOME/.mplayer/tmp
An example of a (working, except for possible dvdnav confusion of title and titleset) script command (here named st) to switch DVD titles, which uses the above TITLE variable:
Code:
#!/bin/bash
TITLE=`cat $HOME/.mplayer/tmp | grep 'TITLE=' | tail -n1 | cut -d = -f 2`
case $1 in
-h|--help)
cat << EOF
"st" stands for "switch title".
It is intended for use with the dvdplayer script.
Usage:
st +n will switch n titles forward
st -n will switch n titles back
st n will switch to title n
st will do nothing
st <garbage> should also do nothing (I hope) :-)
Call this script with ALT+F2 while mplayer is running.
To add a keyboard shortcut, put something like this in input.conf:
N {dvdnav} run "/path/to/st +1" # Next title
P {dvdnav} run "/path/to/st -1" # Previous title
Unfortunately, the switch_title command will only work in dvdnav mode,
which breaks audio playback on many DVDs
EOF
exit
;;
+[0-9]*)
SWITCH=$(echo "$1" |sed 's/+//g')
NEWTITLE=$(expr ${TITLE} + ${SWITCH})
;;
-[0-9]*)
SWITCH=$(echo "$1" |sed 's/-//g')
NEWTITLE=$(expr ${TITLE} - ${SWITCH})
;;
[0-9]*)
NEWTITLE="$1"
;;
*)
exit
;;
esac
if [ "$1" ]; then
echo "switch_title ${NEWTITLE}" > $HOME/.mplayer/fifo
echo TITLE="${NEWTITLE}" >> $HOME/.mplayer/tmp
fi
A completely useless script to repeat the current chapter - but it shows a way to implement resume:
Code:
#!/bin/bash
echo 'get_property chapter' > $HOME/.mplayer/fifo
#echo 'get_property path' > $HOME/.mplayer/fifo
#echo 'get_property stream_pos' > $HOME/.mplayer/fifo
sleep 3
echo 'quit' > $HOME/.mplayer/fifo
CHAPTER=`cat $HOME/.mplayer/tmp | grep ANS_chapter | tail -n1 | cut -d \= -f 2` #create a function!
#echo $CHAPTER
INPUT=`cat $HOME/.mplayer/tmp | grep 'DVD_DEVICE=' | tail -n1 | cut -d \= -f 2`
#echo $INPUT
TITLE=`cat $HOME/.mplayer/tmp | grep 'TITLE=' | tail -n1 | cut -d \= -f 2`
#echo $TITLE
mplayer -loop 0 -dvd-device ${INPUT} dvdnav://${TITLE} -chapter $(expr ${CHAPTER} + 1)-$(expr ${CHAPTER} + 1) -fs #this would have to be implemented in the dvdplayer script (except for the loop). Title and chapter would be taken from the `disc_id $DVD_DEVICE`.tmp file
I want to know what other people think of this approach to scripting (Maybe I am asking too much; if the developers just keep on taking away necessary functionality like scriptable variables I am doomed). And I don't want to use playlists; I am trying to emulate the Mac's DVD Player, not iTunes. So I am looking for an alternative to playlists that makes more sense for a DVD collection, like automatically created settings files (in my home folder, so I don't need write access to the media files. I share several external disks with the Mac so permissions are sometimes messed up, and I don't want to pour sudo over them all the time).
I am quite sure that what I have in mind *can* be done with scripts like these - IF the application behaves, and IF I can be sure mplayer development will support me in this in the future.