UPDATE-2: After submitting the following script, it dawned on me that another way to set up time positions (in a GUI) is to use a Subtitles Editor (eg. gnome-subtitles
). You can just click to mark start and end positions of "phantom subtitles"; actually you can put your file-path and comments in as the "subtitle"... Some formats aren't suitable (eg. using frame numbers).. 'ViPlay Subtitle File', Power DivX, and 'Adobe Encore DVD' look good.
UPDATE-1; a new script... This script won't give you integrated playlist ability, but it will allow you to select and save and modify beginning and ending times within Smplayer, without the need to type anything.
This info is saved in a config file, the file-paths of which can be "played" individually, or in grouped in a sequence, via another script (similar to my 'play' script, or like your Emacs scripts)..
It works by utilizing Smplayer's Seek
dialog... xmacro
manipulates the dialog (I've found that it needs sleep .3
between xmacro commands)... The times are stored in HH:MM:SS format in a file in ~/.config/smplayer
... The 1st line is the Start-time, the 2nd line is the End-time, and the 3rd line is there for specifying a root directory... This 3rd line is used as an optional path indicator by the folow-up script which modifies an smplayer config setting by priming it with -ss
and -endpos
... The timestamps config file is named the same as the media file, with a .smplay
suffix...
So this isn't everything you want, but it may help to set up the times without any typing...
Here is the 'get timestamps' script:
#!/bin/bash
# Bind this script to a key-combination of your choice..
# It currently responds only to an Smplayer window.
id=$(xdotool getactivewindow)
title="$(xwininfo -id "$id" |
sed -n "2s/^xwininfo: Window id: \(0x[[:xdigit:]]\+\) \x22\(.*\)\x22$/\2/p")"
if [[ $title =~ ^.*\ -\ SMPlayer$ ]] ; then
smplayer_d="$HOME/.config/smplayer"
clip_d="$smplayer_d/clips"
[[ ! -d "$clip_d" ]] && mkdir -p "$clip_d"
bname="${title% - SMPlayer}"
clip_f="$clip_d/$bname.smplay" # Same name as video, with '.smplay' suffix
if [[ ! -f "$clip_f" \
|| "$(<"$clip_f" wc -l)" != "3" ]]
then # Prime with three defaults
# FROM TO ROOT-dir
echo -e "0:00:00\n0:00:00\n" >"$clip_f"
fi
# Get timestamp, in seconds, of current stream position (from the current window)
# using the "Smplayer - seek" dialog, via Ctrl+j
sleep .3; echo -n "KeyStrPress Control_L KeyStrPress j KeyStrRelease j KeyStrRelease Control_L" | xmacroplay -d 10 :0.0 &>/dev/null
sleep .3; echo -n " KeyStrPress Home KeyStrRelease Home " | xmacroplay -d 10 :0.0 &>/dev/null
sleep .3; echo -n "KeyStrPress Shift_L KeyStrPress End KeyStrRelease End KeyStrRelease Shift_L " | xmacroplay -d 10 :0.0 &>/dev/null
sleep .3; echo -n "KeyStrPress Control_L KeyStrPress c KeyStrRelease c KeyStrRelease Control_L" | xmacroplay -d 10 :0.0 &>/dev/null
sleep .3; echo -n " KeyStrPress Escape KeyStrRelease Escape " | xmacroplay -d 10 :0.0 &>/dev/null
seekHMS="$(xsel -o -b)"
# Now set config times to defaults (in case of malformed times)
ssHMS="0:00:00"
endposHMS="0:00:00"
# Now get config data from config file
eval "$( sed -ne "1s/^\([0-9]\+\):\([0-5][0-9]\):\([0-5][0-9]\)$/ ssHMS=\"&\"/p" \
-e "2s/^\([0-9]\+\):\([0-5][0-9]\):\([0-5][0-9]\)$/endposHMS=\"&\"/p" \
-e "3s/.*/ root_d=\"&\"/p" "$clip_f" )"
# Present dialog to set specifick items.
REPLY=$(zenity \
--list --height=310 --width=375 \
--title="Set Clip Start / End Time" \
--text=" Select Clip Start / End for time: $seekHMS\n\
or choose another option\n\
\tthen click OK" \
--column="Position" --column=" " --column="Current Setting " \
"Clip Start" " " "$ssHMS" \
"Clip End" " " "$endposHMS" \
"UNSET Start" " " " " \
"UNSET End" " " " " \
"* Open directory" " of" "config files *"
);
[[ "$REPLY" == "Clip Start" ]] && sed -i -e "1 s/.*/$seekHMS/" "$clip_f"
[[ "$REPLY" == "Clip End" ]] && sed -i -e "2 s/.*/$seekHMS/" "$clip_f"
[[ "$REPLY" == "UNSET Start" ]] && sed -i -e "1 s/.*/0:00:00/" "$clip_f"
[[ "$REPLY" == "UNSET End" ]] && sed -i -e "2 s/.*/0:00:00/" "$clip_f"
[[ "$REPLY" == "* Open directory" ]] && nautilus "$clip_d"
fi
The following script is my original 'play" scrpt. It is independent of the avove Timestamp script, but it wouldn't take much to get them to work together...
It will 'drive 'Smplayer, which uses mplayer internally.. it is,at least, a normal GUI, but your playlist would need to be in your text editor .. and you obviously know about that method already :)
I tried this a couple of years ago, but I'd forgotten all about it as I don't often need such a thing, but it is good to keep "bookmarks".. I'm glad you've resurrected the idea.. Here is the script... which really only does the same as you have been doing, but to Smplayer (an mplayer GUi)
#
# Summary:
# Play one video (only) in 'smplayer', passing -ss and -endpos values to 'mplayer'
# It uses 'locate' to get the path of the video (by just its basename)
#
# eg:
# $1 $2 $3 $4
# basename -ss -endpos root
# "Titus - The Gorilla King.mp4" 240 30 "$HOME" # A fascinating documentary of the long reign of a silver-back gorialla
#
[[ "$2" == "" ]] && set "$1" 0 "$3" "$4"
[[ "$3" == "" ]] && set "$1" "$2" 36000 "$4" # 36000 is arbitary (24 hours)
[[ "$4" == "" ]] && root="$HOME" || root="$4"
file=( "$(locate -er "^$root/\(.*/\)*\+$1$")" )
# 1) Tweak 'smplayer.ini' to run 'mplayer' with the specified -ss and -endpos times
# 2) Run 'smplayer' to play one video only. The time settings will hold afer exit,
# so the script waits (backgrounded) for smplayer to exit
# 3) When 'smplayer' exits, set values to extreme limits: -ss 0 -endpos 3600
# or(?): TODO remove the settings enitrely,
# but that requires a different regex
a=0 z=36000
#
# -ss <time> (also see -sb)
# -ss 56 # Seeks to 56 seconds.
# -ss 01:10:00 #Seeks to 1 hour 10 min.
#
# -endpos <[[hh:]mm:]ss[.ms]|size[b|kb|mb]> (also see -ss and -sb)
# Stop at given time or byte position.
# NOTE: Byte position is enabled only for MEncoder and will not be accurate, as it can only stop at a frame boundary.
# When used in conjunction with -ss option, -endpos time will shift forward by seconds specified with -ss.
# -endpos 56 # Stop at 56 seconds.
# -endpos 01:10:00 # Stop at 1 hour 10 minutes.
# -ss 10 -endpos 56 # Stop at 1 minute 6 seconds.
# -endpos 100mb # Encode only 100 MB.
#
# -ss 0 -endpos 36000
# \1 \2 \3 \4 \5 \6 \7 \8
sed -i -e "s/^\(mplayer_additional_options.*\)\( \|=\)\(-ss \+\)\([^ ]\+\)\( .*\)\(-endpos \+\)\([0-9:mb]\+\)\(.*\)/\1\2\3${2}\5\6${3}\8/" $HOME/.config/smplayer/smplayer.ini
(smplayer "$file"
sed -i -e "s/^\(mplayer_additional_options.*\)\( \|=\)\(-ss \+\)\([^ ]\+\)\( .*\)\(-endpos \+\)\([0-9:mb]\+\)\(.*\)/\1\2\3${a}\5\6${z}\8/" $HOME/.config/smplayer/smplayer.ini
)
exit
flag
button on your question and request it to be migrated.timestamps
script to my original answer which showed only aplay-it-in-Smplayer
script