blockh34d
Posts: 57
Joined: Tue Jan 07, 2014 1:49 pm

Simple OMXplayer Setup for multiple files fix keyboard input

Mon Feb 24, 2014 10:20 pm

--- IMPATIENT VERSION: ---
1) Get the attached tar file, doesn't matter where you put it.
2) With it visible in file manager, press F4 to open a terminal window in that folder
3) At terminal run:

Code: Select all

sudo tar -xf  omxplayer-helper-scripts.tar --directory=/usr/share/applications/ --overwrite
sudo apt-get install -f wmctrl
4) Right click a video file, select 'Open With' and find 'omxplayer' or 'omxplayer-SmallWindow' under 'Sound&Video'. Probably click 'always use' option. Play the file so it applies the settings.
---DONE---
Now you should be able to select multiple files, right click to open in fullscreen or windowed, and input (in fullscreen) will be focused correctly

Optional step, open /usr/share/applications/omxplayer_small_script.sh, look for 'OUTPUTWINDOW' and change the values to where you want omxplayer to put the playback window for small display mode.

---FINISH IMPATIENT VERSION----

Hello everyone. I found the default usage of omxplayer to be clunky from X so i made some little scripts help smooth that out a little. I'm new to the raspberry pi and bash scripting so look out, there could be errors. Works for me though, pretty reliably. Here's the gist of it:

Tar file attached contains two bash scripts and two .desktop files to help use omxplayer in X11.
extract file to /usr/share/applications to use. Then right click a video file, click 'open with', find 'omxplayer' or 'omxplayer-smallwindow' in your sound&video apps and optionally select 'always open with...' BTW, even if you don't select 'always...' it will be added to the right click context menu so use both playback methods once for each of .MP4, .MPG, .AVI, and any other video formats you use.

Requires wmctrl

wmctrl is used to focus the playback window so keyboard input correctly reaches omxplayer

Q or Ctrl-C will stop the currently playing video at any time and move to the next file, pressing ctrl-c twice quickly will end the sequence of files selected.

Soon I will probably implement a shuffle function as well.

Please feel free to msg me if something here didn't work right, or if you're a better bash scripter than me and you found room for improvement, I'd like to streamline this process as well as possible for fellow my fellow newbs.
Attachments
omxplayer-helper-scripts.rev2.tar
Extract to /usr/share/applications as root to allow clicking single or multiple video / audio files in X11 and open them in OMXPlayer.
(10 KiB) Downloaded 322 times
Last edited by blockh34d on Tue Feb 25, 2014 1:15 am, edited 3 times in total.

blockh34d
Posts: 57
Joined: Tue Jan 07, 2014 1:49 pm

Contents of attached file of first message

Mon Feb 24, 2014 10:29 pm

Below is the contents of each file in the attached tar above:

omxplayer.desktop

Code: Select all

[Desktop Entry]
Type=Application
Name=OMXPlayer
Categories=AudioVideo;Player;
Exec=lxterminal -t "~ OMXPlayer ~" --geometry=80x10 --command "/usr/share/applications/omxplayer_script.sh %U"
Terminal=false
Icon=/usr/share/icons/nuoveXT2/96x96/categories/applications-multimedia.png
omxplayerSmallWindow.desktop

Code: Select all

[Desktop Entry]
Type=Application
Name=OMXPlayer-SmallWindow
Categories=AudioVideo;Player;
Exec=lxterminal -t "~ OMXPlayer ~" --geometry=80x12 --command "/usr/share/applications/omxplayer_small_script.sh %U"
MultipleArguments=True
Terminal=false
Icon=/usr/share/icons/nuoveXT2/96x96/categories/applications-multimedia.png
omxplayer_script.sh

Code: Select all

#!/bin/bash
#
#  A short bash script to take a list of URI's from x11 windowing system
#  and play them in fullscreen with OMXPlayer.  Additionally, it focuses 
#  the playback window to insure keyboard input reachs OMXPlayer  Be aware,
#  you can still 'silently' alt-tab out of the OMXPlayer window so take 
#  care that you do not.
#
#  Requires:  wmctrl
#  (To install this requirement, run "sudo apt-get install wmctrl", no quotes) 
#
#  Written by Matt Kimball in 2014. Provided freely as is, use at your own risk.
#

echo "                  Full Screen Mode
 ---------------------------------------------------
|  Press Q or Ctrl-C to end current video.          |
|  Press Ctrl-C twice quickly to stop this script   |
 ---------------------------------------------------
"

numfiles=$(echo $#)
curfile=0

echo "[ Playing ($numfiles) files ]"
  for rawfile in $*
    do
      # Increment currently playing file counter
      (( curfile++ ))

      # URL Decode the file:/// URI provided by x11 into a usable filepath
      outfile=$(echo $rawfile | python -c "import sys, urllib as ul; print ul.unquote(sys.stdin.read()).replace(\"file://\",\"\");")
      
      # Store another version without the path prefix
      dispfile=$(basename "$outfile")

      # Set the window title to something meaningful and save it for later
      wintitle="Fullscreen_OMXPlayer"
      echo -en "\033]2;$wintitle\007"

      # Output some status information
      echo "|"
      echo "| File ($curfile of $numfiles): $dispfile"

      # The lines below make sure that the correct window is focused 
      # This makes sure keyboard input gets to OMXPlayer. It's important 
      # that this window have a unique name so that the wmctrl app can 
      # know which window to focus

      echo "| [ Focusing playback window ]"
      wmctrl -r $wintitle -b add,fullscreen
      wmctrl -R -F $wintitle

      echo "+-> Playing: $dispfile"      
      omxplayer --audio_queue 1 --video_queue 5 --threshold 2 -b -o hdmi "$outfile">/dev/null

    done

omxplayer_small_script.sh

Code: Select all

#!/bin/bash
#
#  A short bash script to take a list of URI's from x11 windowing system
#  and play them in a window with OMXPlayer.  No other input management is
#  implemented.  To lock mouse input / keyboard focus, see the fullscreen
#  playback script.
#
#  Written by Matt Kimball in 2014. Provided freely as is, use at your own risk.
#

# Use the line below to specify output window dimensions.
# Format is "X1 Y1 X2 Y2"
OUTPUTWINDOW="1400 60 1840 300"


echo "                 Small Window Mode
 ---------------------------------------------------
|  Press Q or Ctrl-C to end current video.          |
|  Press Ctrl-C twice quickly to stop this script   |
 ---------------------------------------------------
"

numfiles=$(echo $#)
curfile=0

echo "[ Playing ($numfiles) files ]"
  for rawfile in $*
    do
      # Increment currently playing file counter
      (( curfile++ ))

      # URL Decode the file:/// URI provided by x11 into a usable filepath
      outfile=$(echo $rawfile | python -c "import sys, urllib as ul; print ul.unquote(sys.stdin.read()).replace(\"file://\",\"\");")
      
      # Store another version without the path prefix
      dispfile=$(basename "$outfile")

      # Set the window title to something meaningful and save it for later
      wintitle=$(echo "OMXPlayer: $dispfile")
      echo -en "\033]2;$wintitle\007"

      # Output some status information
      echo "|"
      echo "| File ($curfile of $numfiles):"

      echo "+-> Playing: $dispfile"      
      omxplayer --win "$OUTPUTWINDOW" --audio_queue 1 --video_queue 5 --threshold 1 -o hdmi "$outfile">/dev/null

    done

Attachments
omxplayer-helper-scripts.rev2.tar
extract to /usr/share/applications to enable clicking video and audio file(s) from X11 to start OMXPlayer.
(10 KiB) Downloaded 246 times

Return to “Beginners”