Go (from outside) to a given point of a video

I know how to go to a given point of a pdf or of a epub, from outside. For example I can go to a bookmark in a html page very easy (http://your-path/your-file.php#your-bookmark) or, in a pdf, to a page: file://your-path/your-pdf#pag=34, or in an epub file to a given point (with Calibre): file:///your-path-here/your-epub-filename.epub?open_at=epubcfi(/10/2/4/2/132/18/1:65).
But there is a way to go - from outside (from a terminal or from an html page) - to a given point (a chapter or at least a given time) of a video file, such a mkv file?
It depends from the application you use to open it, I guess (VLC or something else). I asked it to a VLC forum time ago, but nobody answered.
Can someone tell me something?

I’m not sure this is possible when opening the video in an application. That would depend upon the application itself, whether it is able to take information from a URL to define the point of playback start. Then there is the great unknown, what OS the client is running, what applications they have installed, what application is their default for that file type. Given this, it seems unlikely to me.
If you are opening and playing the video within the browser, it may be a different matter. A browser can interpret URLs and any arguments passed within it.
I’m aware that with Youtube, when sharing or embedding a video, you can define a start point using a t parameter in the URL: ?t=255
I would imagine something similar would be possible when hosting the videos yourself, though it is not something I have tried.
Looking at the spec for the HTML <video> element, I don’t see any attribute for defining a start point. But I would imagine it would be possible to use an argument in the URL, like Youtube does, and have javascript take that and set the playhead where you want it.
Again, I have not done this, but I suspect it is possible.

2 Likes

Thank you. What I was searching was indeed a way to get a video (in a given point) not within a browser, but within the app (VLC or the like).
I am afraid that this is a problem without solution, so far, as you said.

Here I have found some interesting tips.
Indeed this code works:
vlc file:///my-path/my-video.mp4 --start-time=90

1 Like

ops … I can open the video file from terminal, but so far not from a browser

VLC has its own web interface: https://wiki.videolan.org/Control_VLC_via_a_browser/

2 Likes

I don’t know if I understand correctly, but what I prefer is opening a video file with standalone VLC app (not within a browser, but only from a browser).

The best solution I can think of is to use a custom URI scheme with your own protocol.

As you may already know, there are special protocols like mailto:// or tel:// which allow you to run external applications from the browser. You can use the same concept. Register vlc://protocol and attach vlc command to it. Parameters may be passed via URI, for example, vlc://my-video.mp4/90.

An article to help you get started:

1 Like

I have followed these instructions, but it doesn’t work: even if vlc is opened, I get an error message in vlc: VLC is unable to open the MRL.
Here is my code:

<a href="vlc:///mnt/my-path/my-video.mp4 --start-time=210">video title</a>

Nothing change with vlc:// instead of vlc:///, neither change if I omit --start-time=210

What command have you attached to the vlc:// protocol?

1 Like

Here you are:

#!/usr/bin/env xdg-open
[Desktop Entry]
Name=vlc
Exec=/usr/bin/vlc %u
Type=Application
Terminal=false
MimeType=x-scheme-handler/vlc;

And in VLC today I see this message:

idummy error: unknown command `/mypath/myvideo.mkv --start-time=210'

Okay, now I see the problem.

XDG replaces %u with the full URL including protocol, so

/usr/bin/vlc %u

translates to

/usr/bin/vlc vlc://path/to/file

and vlc cannot understand this scheme.

I’ve solved this with an additional bash file and some replacements. I created vlc.sh file in my home directory and made it executable:

touch /home/veo/vlc.sh
chmod +x /home/veo/vlc.sh

Then I put these lines into that file:

#!/bin/bash
URL=$1
URL_WITHOUT_PROTOCOL=${URL/vlc:\//""}
URL_WITH_CORRECT_ARG=${URL_WITHOUT_PROTOCOL/\?/" --"}
vlc $URL_WITH_CORRECT_ARG

Now, if we run it like this:

/home/veo/vlc.sh vlc://home/veo/video.mp4?start-time=10

it takes first argument from the command line (which contains full URL), replaces vlc:/ with an empty string, then replaces ? sign with " --". As the result, our URL becomes to:

/home/veo/video.mp4 --start-time=10

and this is the line we want to pass to vlc.

The last step to do is to call vlc.sh instead of vlc in the desktop entry:

[Desktop Entry]
Name=vlc
Exec=/home/veo/vlc.sh %u
Type=Application
Terminal=false
MimeType=x-scheme-handler/vlc;

Now it works as expected :grinning:

1 Like

ops… I didn’t manage to get it work.

I created the vlc.sh with this code

#!/bin/bash
URL=$1
URL_WITHOUT_PROTOCOL=${URL/vlc:\//""}
URL_WITH_CORRECT_ARG=${URL_WITHOUT_PROTOCOL/\?/" --"}
vlc $URL_WITH_CORRECT_ARG

made it executable (graphically though: via Dolphin)
and changed vlc.desktop as you had said

[Desktop Entry]
Name=vlc
Exec=/home/duns/vlc.sh %u
Type=Application
Terminal=false
MimeType=x-scheme-handler/vlc;

But the result is that a) I have to delete every space in video file names (what is a bit annoying), b) and after that, if I click on the link, whose code is

<a href="vlc://my-path/my-video-without-spaces.mkv%20--start-time=210">video name</a>

vlc instantly appears and disappears.
Nothing changes if I replace %20--start-time with ?.
Where I’m wrong?

It won’t work with escaped URLs, replace %20 with ?

1 Like

Unfortunately, nothing to do with this code, replacing %20 with ?:

<a href="vlc://my-path/my-video-without-spaces.mkv?--start-time=210">video name</a>

Besides now vlc cannot open a video with spaces in his name (that is 90% of my video :neutral_face:).

because this way seems not to work, what about call a bash script from the browser, so that vlc be executed outside the browser?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.