11

Is there a good GUI-application (for example an mplayer GUI or something like banshee) for linux which allows to make and edit playlists (for video files) with different starting and stopping times for each video on the list?

Added:

At the moment I make manually files which contain something like that:

video.avi -ss 2440 -endpos 210
#some comment

video2.mp4 -ss 112 -endpos 2112

Then I have a wrapper script for: mplayer -fs $(grep -v "^ #" $1)

Furthermore I have written some emacs functions which simplify the editing of such files a little bit. (Like converting starting and end time from hh:mm:ss format to seconds and endtime to relative position (endtime - starttime) as required by -endpos (I can post the macros if someone is interested). However, that's still too uncomfortable. So my question is if there is a nice GUI for doing this (for example which allows you to mark in a video timeline the start and end times for the playlist and so on).

4
  • @user5289: If you're only interested in answers for Ubuntu (you didn't mention a distribution in your question), you can choose what site to ask on. If you prefer Ask Ubuntu, use the flag button on your question and request it to be migrated. Commented Mar 8, 2011 at 18:37
  • 1
    @user5289 Is all you want.. to be able to play the video in a GUI (because 'mplayer' is certainly not a GUI)? ... or do you want to be able to set the time positions in a GUI (also)? .. because you can just use Smplayer to use your existing "timed commands" .. I've written a script to do just that.. I'll post the script as and answer.. someone may find it interesing.. I certainly found your method interesting.. and I've just adapted it to Smplayer..
    – Peter.O
    Commented Mar 25, 2011 at 11:38
  • @fred.bear, yes the point is, that I want to be able to set the time positions in a GUI, edit the whole playlist in a GUI in some comfortable way. (Playing in a GUI is not important)
    – student
    Commented Mar 26, 2011 at 9:11
  • @user5289: It is quite possible to set the time positions in a GUI... I do it with Smplayer.... I've added the new timestamps script to my original answer which showed only a play-it-in-Smplayer script
    – Peter.O
    Commented May 13, 2011 at 9:59

4 Answers 4

3

Maybe I'm getting the question wrong, since English is not my first language, but wouldn't it be better if you edited the video with a tool like Kino instead of making a playlist like that?

You can adjust the starting and stopping times as you want, and I don't think it would be that difficult.

1
  • 3
    Yes, I know how to cut videos using Kino or something like that. The question is really about playlists, not about making new videos. Making such playlists would be very fast, flexible and consuming no additional disk space.
    – student
    Commented Mar 23, 2011 at 16:19
3

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
6
  • Thanks for the Update. Could you add a step by step instruction how to use the script?
    – student
    Commented May 14, 2011 at 17:20
  • @user5289. It should only require that you have smplayer open with your video, and the script is associated with as shortcut-key (I use xbindkeys, but anything will do).. You can then, at any point in the movie, just press you shortcut-key.. Because it utilizes a macro which is unrelated to smplayer, you should not do anything (keyboard or mouse click) until the 2nd dialog appears. It needs 1-2 seconds to check "Is this the right window? etc" and open smplayer's "seek dialog" from which the macro copies the current time position which is presented in HH:MM:SS.. Do not interrupt this dialog....
    – Peter.O
    Commented May 15, 2011 at 1:27
  • continued... The macro will copy the timestamp to the clipoard and then close the "seek dialog".. A second dialog will then appear (a "zenity" dialog)... It will prompt you to do 1 of 5 things. 1) use the captured timestamp as Start position. 2) use the captured timestamp as End position. 3) Unset Start Positon. 4) Unset End Positon. 5) Open nautilus at the directory which holds the saved "config" file .. The config files are named identically to the Video. (the name is taked from Smplayer's title bar)..
    – Peter.O
    Commented May 15, 2011 at 1:34
  • continued... From there you can use the times as you please in your current scripts... I'm working on a script which integrates with Smplayer; My first smplayer script (shown in my original answer) is a bit naive, and trips up on some options.. Smplayer has an option to keep a history of every file ever played. This can be done in a single file or individual files... The individual file method (the default, I think(?), is the most suitable, but the .ini names are hashed. I'm currently working on mimicing that has algorithm... so stay tuned :)
    – Peter.O
    Commented May 15, 2011 at 1:44
  • continued... You will need to have these apps installed.. xdotool xwininfo xmacro zenity sed (but who hasn't got sed:), and of course smplayer... As I mentioned it my answer.. it is only an 'asssist'.. so far,but thinking about it right now, as I write this, it can be made to graft into the normal smplayer playlist! because the playlist will play in accordance with the save smplayer .ini files (the ones with the hashed filenames).. This is looking beter and better.. but I seriously need a break :).. too much smplayer for a few days.. I've still got to finish off that hashing algorithm
    – Peter.O
    Commented May 15, 2011 at 1:59
2

I've added this second answer, because it works as a normal playlist in SMPlayer, and it's better here for clarity...

I've had it working flawlessly via the playlist...

This method requires a re-compilation of SMPlayer, and a specific file-naming method... Only one function in SMPlayer's source is modified, and 3 headers are added to the same single source file... I have compiled smplayer_0.6.8 for Lucid... Maveric and Meerkat use smplayer_0.6.9.. One line in the later version is different, but that doesn't upset anything... Here is the modified function and headers for smplayer_0.6.8

btw, the zenity dialog in my previous answer is still of use for capturing the start and end times...

REMINDER - The following source segments are for smplayer_0.6.8... The file to modify is: ../smplayer-0.6.9/src/findsubtitles/osparser.cpp... The new segments are the same for '0.6.8' and '0.6.9', but the originals differ by one line (very close to the end; just before the final return hexhash;)


Add this first block of lines immediately below the existing #include headers

// ====================
// fred mod begin block  
#include <QFileInfo>
#include <QRegExp>
#include <QSettings>
#include "paths.h"
// fred mod end block
// ==================

Here is the modified function

QString OSParser::calculateHash(QString filename) {
    QFile file(filename);

    if (!file.exists()) {
        qWarning("OSParser:calculateHash: error hashing file. File doesn't exist.");
        return QString();
    }

    file.open(QIODevice::ReadOnly);
    QDataStream in(&file);
    in.setByteOrder(QDataStream::LittleEndian);
    quint64 size=file.size ();
    quint64 hash=size; 
    quint64 a;
    for(int i = 0; i < 8192; i++) {
        in >> a ; hash += a;
    };
    file.seek(size-65536);
    for(int i = 0; i < 8192; i++) {
        in >> a ; hash += a;
    };

  // =====================================================================
  // fred mod begin block
  //  
  // A mod to enable unique smplayer .ini files to be created for  
  //        content-identical media files whose file-names match
  //        a specific pattern based on two timestamps. 
  //        This is the naming pattern:

  //          
  //           name.[00:11:22].[33.44.55].mkv
  //              
  //        The two time stamps indicate the start and end  points of a 
  //         clip to be played according to  settings in the unique .ini
  //            
  //        The so named files can be, and typically will be, soft (or hard) links.   
  //        The "original" file can also named in this manner, if you like,    
  //        but that would make the "original" start playing as a clip,
  //          NOTE: soft links become invalid when you rename the original file.  
  //
  //  Note: For this system to work, you need to enable the following:
  //        In SMPlayer's GUI, open the Options dialog...
  //        In the  "General" tab... "Media settings"... 
  //          enable: 〼 "Remember settings for all files (audio track, subtitles...)" 
  //                     "Remember time position"   can be 'on' or 'off'; it is optional1
  //                                                but it is disabled for these clips.    
  //                     "Store setings in" must be: "multiple ini files" 
  //
  QFileInfo fi(filename);
  QString name = fi.fileName();
  //
  // ===================================================================
  // This RegExp expects a name-part, 
  //             followed by 2 .[timestamps]  (Begin-time and End-time)
  //             followed by a .extension
  //              
  //              .[ Begin  ].[  End   ]  
  //      eg. name.[00:11:22].[33.44.55].mkv
  //
  //    Note: The delimiter between each numeric value can be any non-numeric character.
  //          The leading dot '.' and square brackets '[]' must be as shown        
  //          HH, MM, and SS must each be 2 valid time-digits    
  //
  QRegExp rx("^.+"                      // NAME
             "\\.\\[([0-9][0-9])[^0-9]" // .[HH.
                   "([0-5][0-9])[^0-9]" //   mm.
                   "([0-5][0-9])\\]"    //   ss]
             "\\.\\[([0-9][0-9])[^0-9]" // .[HH.
                   "([0-5][0-9])[^0-9]" //   mm.
                   "([0-5][0-9])\\]"    //   ss]
             "\\.([^0-9]+)$");          // .EXTN
  //
  QString qstrIni;
  rx.setPatternSyntax(QRegExp::RegExp);
  if(rx.exactMatch(name)) {
      bool ok;
      QString qstrDlm(".");
      QString qstrBegEnd = rx.cap(1) + rx.cap(2) + rx.cap(3)
                         + rx.cap(4) + rx.cap(5) + rx.cap(6);
      hash += qstrBegEnd.toLongLong(&ok,10); // The UNIQUE-FIER
      //
      quint32 quiBegSec=(rx.cap(1).toULong(&ok,10)*3600)
                       +(rx.cap(2).toULong(&ok,10)*  60)
                       +(rx.cap(3).toULong(&ok,10));
      quint32 quiEndSec=(rx.cap(4).toULong(&ok,10)*3600)
                       +(rx.cap(5).toULong(&ok,10)*  60)
                       +(rx.cap(6).toULong(&ok,10));
      quint32 quiDifSec=(quiEndSec-quiBegSec);
      // 
      QString qstrBegIni = "-ss "     + QString::number(quiBegSec);
      QString qstrEndIni = "-endpos " + QString::number(quiDifSec);
              qstrIni    = qstrBegIni + " " + qstrEndIni;
  }
  // fred mod end block
  // =====================================================================
  // fred NOTE: the following 2 lines are a single line in smplayer-0.6.9

    QString hexhash("");
    hexhash.setNum(hash,16);

  // =====================================================================
  // fred mod begin block  
    if( !qstrIni.isEmpty() ) {
      // ** The next code line is not ideal, but should be okay so long 
      //    as SMPlayer's options are set to use Multiple .ini files.  
      //       The literal "file_settings" is HARDCODED, as It wasnt' straight
      //       forward to get the value, The rest of the path was easily available 
      //       without any significant mods, which "file_settings" would require.    
      // TODO: Check for Multiple .ini Option being enabled.
      //  
      QString  dir_settings = Paths::configPath() + "/file_settings";
      QString fqfn_settings = dir_settings + "/" + hexhash[0] + "/" + hexhash + ".ini";

      QSettings set(fqfn_settings, QSettings::IniFormat);
      set.beginGroup("file_settings");
      set.setValue(  "starting_time", "0" );
      set.setValue(  "mplayer_additional_options", qstrIni );
    }
  // fred mod end block
  // =====================================================================

    return hexhash;
}
1

I failed to find whether these can really be applied to playlists but you may look into Edit Decision Lists (EDLs). Here are some links to get you started:

  1. MPlayer manual about EDL support

  2. MPlayer EDL tutorial

  3. Video editing from the command line LinuxGazette article

  4. The sensible cinema project

If you don't mind the small pauses between the videos you could just run mplayer several times from a script with different EDL files each time. If pauses are a no-no then maybe you should create a new video just like varrtto suggested.

1
  • Thanks, however, using command line, I think using mplayers -ss and -endpos + my emacs macros is the better way to go (see my additions to the original post). What I really want is a nice GUI.
    – student
    Commented Mar 23, 2011 at 16:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .