Page 1 of 1

omxplayer in loop problem

Posted: Thu Mar 07, 2013 2:35 am
by brianhj
I have a bunch of videos here:
/media/blah/

I'm trying to loop through them randomly in bash. Right now I have it choosing a random video each time one finishes:

Code: Select all

while true
do
  files=(/media/blah/*.mkv)
  omxplayer -o hdmi  "${files[RANDOM % ${#files[@]}]}"
done
And that works.. but

What I'd rather have is a list of all the videos in random order, play the whole list once, then shuffle the list again. That way there is a much smaller chance of seeing a video twice in a relatively short period of time.

Code: Select all

#play.sh
ls /media/blah/ | sort -R > /home/pi/playlist
for ((c=1; c<=172; c++))
do
  read line
  omxplayer -o hdmi /media/blah/"$line"
done < /home/pi/playlist
I know my script is inefficient and I know I should use ls and loops like this in a bash script but I just want something quick and dirty that works.

I'm looping through 170 or so videos, not programming a mars rover.

Anyway, the loop works except for this:

Code: Select all

pi@raspberrypi ~ $ ./play.sh
file : /media/blah/1.mkv result 0 format matroska,webm audio streams 1 video streams 1 chapters 0 subtitle                                                                                                                          s 0 length 1302
Video codec omx-h264 width 1280 height 720 profile 100 fps 23.976025
Audio codec ac3 channels 8 samplerate 48000 bitspersample 16
Subtitle count: 0, state: off, index: 1, delay: 0
/usr/bin/omxplayer: line 12:  2605 Segmentation fault      LD_LIBRARY_PATH=$OMXPLAYER_LIBS:$LD_LIBRARY_PATH $OMXPLAYER_BIN "$@"
Why would the first work but not the second? I've updated using apt-get update and upgrade. I've downloaded the 0.2.5 deb package from omxplayer's website. Nothing has helped so far. And I'm using a for loop because I want to skip the last newline in the file. (I've tried using commands to remove the new line but in the end I just decided to skip it.)

Re: omxplayer in loop problem

Posted: Sun Mar 10, 2013 3:09 pm
by DBryant
Your #! is incorrect at the top of your script, it should read

Code: Select all

#!/bin/bash
The following code, in your style, will loop and print the flv filenames it finds

Code: Select all

#!/bin/bash
FILES=/home/dave/Videos/*.flv
ls ${FILES} | sort -R > /home/dave/playlist
count=0
while read line
do
  printf "%3d> %s\n" "$count" "$line"
  count=$((count+1))
done < /home/dave/playlist
The following will do the same but without the need for an intermediary file

Code: Select all

#!/bin/bash
count=0
IFS='
'
for f in $(ls ${FILES} | sort -R)
do
  printf "%3d> %s\n" "$count" "$f"
  count=$((count+1))
done

Re: omxplayer in loop problem

Posted: Sun Mar 10, 2013 5:51 pm
by brianhj
That's not what the problem is... :cry:

I can loop through the file names fine. The problem is omxplayer doesn't like it... from it's output I can I am sending the correct file path, but I get a segmentation fault. In the first loop I showed it plays fine. Again, why does it work in the first loop but not in the second loop?

Re: omxplayer in loop problem

Posted: Sun Mar 10, 2013 7:00 pm
by DBryant
That's a matter of opinion, since your script fails to be constructed correctly!
You also have a counter which makes assumptions about the content of the file which are corrected in the loops I posted.
This loop, which runs omxplayer, executes correctly

Code: Select all

#!/bin/bash
FILES=~/video/*mp4
count=0
IFS='
'
for f in $(ls ${FILES} | sort -R)
do
  printf "%3d> %s\n" "$count" "$f"
  omxplayer -o hdmi "$f"
  count=$((count+1))
done
Your mileage may vary.

Re: omxplayer in loop problem

Posted: Sun Mar 10, 2013 7:40 pm
by brianhj
Ok, my apologies, you did put that script in your first reply, I will try that when I get home. Thank you :)

Re: omxplayer in loop problem

Posted: Sun Mar 10, 2013 7:43 pm
by brianhj
How about this:

Code: Select all

#!/bin/bash
count=0
IFS='
'
while true
do
  for f in $(ls ${FILES} | sort -R)
  do
    printf "%3d> %s\n" "$count" "$f"
    count=$((count+1))
  done
done
Because I'd like it to loop endlessly, but also create a new random playlist each iteration in the while loop. Thanks again :)