piepolitb
Posts: 4
Joined: Fri Feb 20, 2015 10:43 am

script for omxplayer with subtitles

Fri Feb 20, 2015 11:01 am

hello guys,
I'm a new happy owner of a pi b+ with raspbian installed. Also I'm quite a newbie to the raspberry pi world...

first of all, here is the situation: I have tons of movies over streamed over my wifi, collected in organized folders containing the following files with the following formatted names:
1. file-name.mp4 - the video file
2. file-name_ITA.srt - italian subtitle (if any)
3. file-name_ENG.srt - english subtitles (if any)
I'm able to have everything working fine with omxplayer

Code: Select all

omxplayer -o hdmi -r file-name.mp4 --subtitles file-name_XXX.srt
BUT because I'm little lazy and I don't want to play the video by terminal line command, I would like to write down a little script to open the video file on double click to put in /usr/local/bin and then in the "open with" property. I would like this script to:
1. play the double-clicked file with omxplayer
2. check for existing subtitles in the folder
3. ask me which subtitles I want to be set up
4.enjoy the movie

any suggestions?
thanks
Giuseppe

piepolitb
Posts: 4
Joined: Fri Feb 20, 2015 10:43 am

Re: script for omxplayer with subtitles

Sat Feb 21, 2015 9:29 pm

nobody?

User avatar
expandables
Posts: 654
Joined: Fri Jun 27, 2014 7:34 pm
Location: Neverland with Michael Jackson

Re: script for omxplayer with subtitles

Sun Feb 22, 2015 2:06 am

piepolitb wrote:nobody?
Why not install a gui like emulationstation and have a section that plays video files.
But you will have to do your script yourself Mr. Lazy. :lol: :mrgreen: OR try vlc player http://www.raspberrypi.org/forums/viewt ... 99#p629999
Or download scamp from the store. http://store.raspberrypi.com/projects/scamp
By thinking like an engineer you can create a raspberry pi.
Michael Jackson enthusiast.
I got the PI model B, B+ and PI 2 model B.
When will I get the A? I don't know.

User avatar
kusti8
Posts: 3439
Joined: Sat Dec 21, 2013 5:29 pm
Location: USA

Re: script for omxplayer with subtitles

Sun Feb 22, 2015 2:53 am

piepolitb wrote:hello guys,
I'm a new happy owner of a pi b+ with raspbian installed. Also I'm quite a newbie to the raspberry pi world...

first of all, here is the situation: I have tons of movies over streamed over my wifi, collected in organized folders containing the following files with the following formatted names:
1. file-name.mp4 - the video file
2. file-name_ITA.srt - italian subtitle (if any)
3. file-name_ENG.srt - english subtitles (if any)
I'm able to have everything working fine with omxplayer

Code: Select all

omxplayer -o hdmi -r file-name.mp4 --subtitles file-name_XXX.srt
BUT because I'm little lazy and I don't want to play the video by terminal line command, I would like to write down a little script to open the video file on double click to put in /usr/local/bin and then in the "open with" property. I would like this script to:
1. play the double-clicked file with omxplayer
2. check for existing subtitles in the folder
3. ask me which subtitles I want to be set up
4.enjoy the movie

any suggestions?
thanks
Giuseppe

Code: Select all

import subprocess
import glob
import os

file = raw_input("What is the file name (with extension): ")
directory = raw_input("What is the directory: ")
if directory!= "":
    os.chdir(directory)
subtitles = []
sub_file = []
for subtitle in glob.glob("*.srt"):
    subtitles.append(subtitle[-3:])
    sub_file.append(subtitle)

choice = raw_input("Which subtitle do you want:" + subtitles)
got=""
for s_file in sub_file:
    if s_file[-3:] == choice:
        got=sub_file
        break
if got!="":
    subprocess.open("omxplayer -o hdmi -r " + file + " --subtitles " + sub_file, shell=True)
Last edited by kusti8 on Sun Feb 22, 2015 9:58 pm, edited 4 times in total.
There are 10 types of people: those who understand binary and those who don't.

User avatar
expandables
Posts: 654
Joined: Fri Jun 27, 2014 7:34 pm
Location: Neverland with Michael Jackson

Re: script for omxplayer with subtitles

Sun Feb 22, 2015 4:58 am

Looks like you are all set :mrgreen:
By thinking like an engineer you can create a raspberry pi.
Michael Jackson enthusiast.
I got the PI model B, B+ and PI 2 model B.
When will I get the A? I don't know.

Return to “Raspberry Pi OS”