LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-29-2013, 04:53 AM   #1
nokangaroo
Member
 
Registered: Nov 2009
Posts: 141

Rep: Reputation: 25
Scripting mplayer - is it worth my while to go on?


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.

Last edited by nokangaroo; 05-29-2013 at 11:33 AM.
 
Old 06-01-2013, 03:17 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3608Reputation: 3608Reputation: 3608Reputation: 3608Reputation: 3608Reputation: 3608Reputation: 3608Reputation: 3608Reputation: 3608Reputation: 3608Reputation: 3608
Quote:
Originally Posted by nokangaroo View Post
I want to know what other people think of this approach to scripting
Scripting means glueing tools together. So I'd say if it works for you then that's cool.


Quote:
Originally Posted by nokangaroo View Post
(..) IF I can be sure mplayer development will support me in this in the future.
Simply put: if they're not aware of what you need and why you need it then they really can't be faulted for breaking changing things.
 
Old 06-03-2013, 06:55 AM   #3
nokangaroo
Member
 
Registered: Nov 2009
Posts: 141

Original Poster
Rep: Reputation: 25
You mean I should post this on the mplayer mailing list? I suppose I had better do so.

Edit: Sent a mail to mplayer-users@mplayerhq.hu. Now I'm praying that I configured thunderbird correctly (Never figured that this would be so hard, just getting rid of HTML and rewrapping the text)

Last edited by nokangaroo; 06-03-2013 at 02:11 PM.
 
Old 01-23-2014, 07:12 AM   #4
nokangaroo
Member
 
Registered: Nov 2009
Posts: 141

Original Poster
Rep: Reputation: 25
Edit: Here is an improved version of the dvdplayer script, and an attempt at a resumer script. Without actually saving the state of the DVD engine as the ogle DVD player does, I am afraid this is about as good as it gets

Note the bash -x which tells you everything you need to know
Code:
#!/bin/bash -x
# dvdplayer script using mplayer

# Initializing:
if [ ! -e "$HOME/.mplayer/fifo" ]; then
mkfifo $HOME/.mplayer/fifo
fi
rm -f $HOME/.mplayer/tmp
PROTOCOL='dvdnav://' #maybe add a switch

if [ "$1" ]; then
# Drag an iso file or VIDEO_TS folder to the terminal (takes only one
# argument; the $* is for handling filenames with spaces):
DVD_DEVICE="$(echo "$*" | sed "s/^'\|'$//g")"
# BTW Has nobody ever noticed that the stupid mandatory quoting that
# all GNU/Linux terminal applications impose on us makes life really hard
# for us? The only terminal application with the correct behaviour (using
# NO quotes, escaping spaces with backslashes if necessary) is the Mac OS X
# Terminal.app which is proprietary.
else
#will find external drive if present:
DVD_DEVICE="$(cat /etc/mtab | grep udf | awk '{print $1}')"
fi

# in the following, disc_id is a program from libdvdread-0.9.7
# compiled as an executable (./configure --disable-shared --disable-static =>
# make => do not install, copy files manually to /usr/local/bin).
# Sadly mplayer does not output enough information even at the highest 
# message level, so we have to get the information we need this way

# Where the bookmarks go:
BMDIR="$HOME/.mplayer/bookmarks"
if [ ! -d $BMDIR ]; then
mkdir -p $BMDIR
fi

# VIDEO_TS folders have a disc id (at least when created with dvdauthor),
# so $(disc_id "${DVD_DEVICE}") should not be empty (Remember, this is a DVD
# player only). The disc id may or may not be the same as the disc id of the
# iso file created from it. This has nothing to do with filesystem UUID.
# Inventing extensions for the bookmark and resume files.
# Later we might invent corresponding mimetypes:
touch ${BMDIR}/$(disc_id "${DVD_DEVICE}").mpbmk
BOOKMARKFILE="${BMDIR}/$(disc_id "${DVD_DEVICE}")".mpbmk
touch ${BMDIR}/$(disc_id "${DVD_DEVICE}").resume
RESUMEFILE="${BMDIR}/$(disc_id "${DVD_DEVICE}")".resume

# Functions:
set_var () {
echo "$1"="$2" >> $HOME/.mplayer/tmp
}

# mplayer commands (slave mode is not necessary but useful for testing).
# The ampersand may be necessary for some scripts:
(mplayer $PROTOCOL -dvd-device "$DVD_DEVICE" -nocache -slave -quiet -fs -mouse-movements -input file=$HOME/.mplayer/fifo >> $HOME/.mplayer/tmp) & 

sleep 1

# 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
dvdnav://)
TITLE=$(cat $HOME/.mplayer/tmp | grep "DVDNAV, " | tail -n 1 | sed 's/[^[:digit:]]//g')
;;
dvd://)
TITLE=$(cat $HOME/.mplayer/tmp | grep ID_DVD_CURRENT_TITLE | tail -n 1 | cut -d = -f 2)
;;
esac

# Creating custom variables (exporting them won't work):
set_var TITLE $TITLE #only this will change during playback
set_var DVD_DEVICE $DVD_DEVICE
set_var BOOKMARKFILE $BOOKMARKFILE
set_var RESUMEFILE $RESUMEFILE
set_var PROTOCOL $PROTOCOL

Here is the resumer script (it's a work in progress, so the help section is mainly a wish list. And it's horrible!)
Code:
#!/bin/bash -x
# Bookmark script for use with the dvdplayer script.

# Functions:
get_resume () {
for i in "$@"; do
eval "$i"=`cat $RESUMEFILE | grep "$i" | cut -d = -f 2`
done
}

set_resume () {
for j in "$@"; do
eval echo "$j"=\$"$j" >> "$RESUMEFILE"
done
}

get_var () {
for k in "$@"; do
eval "$k"=`cat $HOME/.mplayer/tmp | grep "$k" | tail -n 1 | cut -d = -f 2`
done
}

set_var () {
eval echo "$1"=\$"$1" >> ${HOME}/.mplayer/tmp
}

set_bookmark () {
echo "$1"="$2" >> "$BOOKMARKFILE"
}

mp_command () {
echo "$*" > $HOME/.mplayer/fifo
}

#TERMINAL=$COLORTERM

case $1 in
-h|--help)
cat << EOF
"`basename $0`" is a bookmarking and resuming script for mplayer. It is intended for use with the dvdplayer script. Call it with Alt+F2 while mplayer (started with the dvdplayer script) is running or assign a shortcut to it.

Usage:
`basename $0` without arguments will create a resume bookmark and close mplayer. The previous resume bookmark will be overwritten.

`basename $0` -l will open a terminal window and list your bookmarks in a select menu; choose one by number.

`basename $0` -c will open a terminal window and prompt for the name of a new bookmark to be created at the current position. If the name is "Start", it will be used as default startup bookmark. An existing bookmark with the chosen name will be overwritten.

`basename $0` -d will open a terminal window and list your bookmarks in a select menu; choose one to delete. Can also be done by opening $BOOKMARKFILE in an editor, of course.

`basename $0` -r will start playback from the resume bookmark, if present.

EOF
exit
;;
-l|--list)
#TODO
;;
-c|--create)
#TODO
;;
-d|--delete)
#TODO
;;
-r|--resume)
get_var PROTOCOL DVD_DEVICE RESUMEFILE && \
get_resume TITLE ANS_time_pos && \
#restarting mplayer is ***REALLY*** idiotic
mp_command quit && \
(mplayer $PROTOCOL$TITLE -dvd-device "${DVD_DEVICE}" -nocache -slave -quiet --hr-seek=always -fs -mouse-movements -input file=$HOME/.mplayer/fifo &) && \
sleep 1 && \
(mp_command seek $ANS_time_pos 2)
;;
*)
(mp_command get_property time_pos) && \
sleep 1 && \
get_var TITLE ANS_time_pos RESUMEFILE && \
sleep 1 && \
rm -f $RESUMEFILE && \
set_resume TITLE ANS_time_pos && \

#TODO: save audio and subtitle track as well

mp_command quit
;;
esac

A script to enter slave mode commands in fullscreen:
Code:
#!/bin/bash
echo "$*" > $HOME/.mplayer/fifo
 
  


Reply

Tags
multimedia, ubuntu


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
MPlayer GUI (gmplayer - NOT gnome-mplayer) single instance fix... poweredbydodge Linux - Desktop 5 04-12-2011 03:34 PM
LXer: SMPlayer and GNOME Mplayer - Two Incredibly Good Mplayer Based Media Players For Ubuntu LXer Syndicated Linux News 0 07-13-2010 02:10 AM
Mplayer build: configure finds ALSA, but mplayer doesn't galle Linux - Software 5 10-13-2007 06:14 PM
In Kubuntu I have compiled MPlayer and it works fine, MPlayer Plug-in is not working kickass331 Linux - Newbie 10 08-11-2006 09:12 PM
ns sripting bangoram Linux - Software 2 07-22-2006 01:40 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration