LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-09-2020, 01:59 PM   #1
linustalman
LQ Guru
 
Registered: Mar 2010
Location: Ireland
Distribution: Debian 12 Bookworm
Posts: 5,714

Rep: Reputation: 479Reputation: 479Reputation: 479Reputation: 479Reputation: 479
Question Looking for code to play random video at random playback point.


Hi.

I'm looking for a command to play a random video from a particular folder and play the file at a random point, e.g. 63m16s in to a film, etc.

Thanks.
 
Old 07-09-2020, 03:11 PM   #2
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,137
Blog Entries: 6

Rep: Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826
I would think that about any media player where you can launch it with a index time will do that.

Example random number from 30 - 90
Code:
ran=$((30 + RANDOM % 60))

mplayer -ss "$ran" file.mp4
Choose a sudorandom file
Code:
f=(file1.mp4 file2.mp4 file3.mp4 file4.mp4 file5.mp4 
        file6.mp4 file7.mp4 file8.mp4 file9.mp4 file10.mp4)

for i in {1..20}; do
    select_f=${f[$RANDOM % ${#f[@]} ]}
    echo "$select_f"
    sleep .5
done

Last edited by teckk; 07-09-2020 at 03:12 PM.
 
1 members found this post helpful.
Old 07-10-2020, 01:52 PM   #3
linustalman
LQ Guru
 
Registered: Mar 2010
Location: Ireland
Distribution: Debian 12 Bookworm
Posts: 5,714

Original Poster
Rep: Reputation: 479Reputation: 479Reputation: 479Reputation: 479Reputation: 479
Lightbulb

I know of this command to play a random video from a folder:

Code:
mplayer -fs -quiet -shuffle {*,*/*}
I wonder if it's possible to append more code to also play a video at a random place in its run time?
 
Old 07-10-2020, 02:30 PM   #4
individual
Member
 
Registered: Jul 2018
Posts: 315
Blog Entries: 1

Rep: Reputation: 233Reputation: 233Reputation: 233
If you aren't currently using a particular video player, you could use mpv and some shell/Perl magic.
Code:
mpv --start="$(( RANDOM % 100 ))%" "$(perl -e '@d=<*>; print $d[rand(@d)]')"
A cleaner version:
Code:
#!/usr/bin/env perl

my @files = <*>;
my $start_percent = rand(100) . '%';

`mpv --start=$start_percent $files[rand(@files)]`
 
1 members found this post helpful.
Old 07-11-2020, 01:46 AM   #5
linustalman
LQ Guru
 
Registered: Mar 2010
Location: Ireland
Distribution: Debian 12 Bookworm
Posts: 5,714

Original Poster
Rep: Reputation: 479Reputation: 479Reputation: 479Reputation: 479Reputation: 479
Thumbs up

Quote:
Originally Posted by individual View Post
If you aren't currently using a particular video player, you could use mpv and some shell/Perl magic.
Code:
mpv --start="$(( RANDOM % 100 ))%" "$(perl -e '@d=<*>; print $d[rand(@d)]')"
A cleaner version:
Code:
#!/usr/bin/env perl

my @files = <*>;
my $start_percent = rand(100) . '%';

`mpv --start=$start_percent $files[rand(@files)]`
That one liner is perfect! Thanks, individual.
 
Old 07-11-2020, 04:03 AM   #6
linustalman
LQ Guru
 
Registered: Mar 2010
Location: Ireland
Distribution: Debian 12 Bookworm
Posts: 5,714

Original Poster
Rep: Reputation: 479Reputation: 479Reputation: 479Reputation: 479Reputation: 479
Quote:
Originally Posted by individual View Post
If you aren't currently using a particular video player, you could use mpv and some shell/Perl magic.
Code:
mpv --start="$(( RANDOM % 100 ))%" "$(perl -e '@d=<*>; print $d[rand(@d)]')"
A cleaner version:
Code:
#!/usr/bin/env perl

my @files = <*>;
my $start_percent = rand(100) . '%';

`mpv --start=$start_percent $files[rand(@files)]`
I tried the longer code and put it in a .pl file but it didn't work.

How can I add the one line command to an alias? I'm unsure due to the quotes already in the code.

Also, would it be possible to have the one line code run recursively?

Last edited by linustalman; 07-12-2020 at 04:04 AM.
 
Old 07-11-2020, 06:14 PM   #7
individual
Member
 
Registered: Jul 2018
Posts: 315
Blog Entries: 1

Rep: Reputation: 233Reputation: 233Reputation: 233
Quote:
Originally Posted by linustalman View Post
I tried the longer code and put a .pl file but it did not work.

How can I add the one line command to an alias? I'm unsure due to the quotes already in the code.

Also, would it be possible to have the one line code run recursively?
It might be better to use a shell function instead of an alias.
Code:
randomFile() {
   ONE_LINER_GOES_HERE
}
I assume by recursively you mean you want to play a file that is several directories down? It would take a little more code, and probably not be a one-liner. If you need it, I can write something.
 
1 members found this post helpful.
Old 07-12-2020, 04:05 AM   #8
linustalman
LQ Guru
 
Registered: Mar 2010
Location: Ireland
Distribution: Debian 12 Bookworm
Posts: 5,714

Original Poster
Rep: Reputation: 479Reputation: 479Reputation: 479Reputation: 479Reputation: 479
Thumbs up

Quote:
Originally Posted by individual View Post
It might be better to use a shell function instead of an alias.
Code:
randomFile() {
   ONE_LINER_GOES_HERE
}
I assume by recursively you mean you want to play a file that is several directories down? It would take a little more code, and probably not be a one-liner. If you need it, I can write something.
That function is ideal. I will settle with the non-recursive setup. Thank you very much, individual. I appreciate it.
 
  


Reply

Tags
playback, random, video



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Looking for solution to play a video or video playlist on a timer cpthowdy Linux - General 6 10-19-2014 01:03 PM
Many video format (such as video/x-ms-asf and video/x-ms-wvx ) does not play? jmettova Debian 1 05-05-2009 11:22 AM
no sound playback or video playback..on ubuntu 8.10 thelastquincy Linux - Newbie 3 04-20-2009 11:14 PM
Video Playback-speeded up audio & video howone SUSE / openSUSE 1 10-20-2005 01:24 AM
blue line at the top of TV playback, DIVX playback spiderworm Linux - Software 0 01-31-2005 02:33 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:22 AM.

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