Set precise time on a video using javascript

Hi i'm trying to get a button to set the video time a precise point. The code listed below is what i've made up till now but its not working. i think because it cant get the document.getElementById. Anyone have an idea how to resolve this?

\documentclass{article}

\usepackage[pdftex]{hyperref}
\usepackage[pdftex]{insdljs}
\usepackage{media9}
\begin{insDLJS}{mydljs}{some comment}
function stop(){
var vid = document.getElementById("bunny.mp4");
vid.currentTime=5;
}
\end{insDLJS}

\begin{document}
\includemedia[width=0.6\linewidth,height=0.6\linewidth,activate=pageopen,
passcontext,
transparent,
flashvars={source=bunny.mp4}
]{}{VPlayer.swf}

\begin{Form}
\PushButton[onclick={stop();}]{5 sec}\\
\TextField[name=somefield, width=4em]{Any way to hide e.g. this text?}
\end{Form}
\end{document}ode here

• Your comment should be under here or the answer. First off have you tried to ensure your source file is re-encoded per the suggestion in the answer e.g. have you tried ffmpeg to regenerate a compatible file using similar values for profile fmt etc once you find a match that works then adjust for optimum speed etc – user170109 Mar 6 at 14:48
• I edited the answer to include an example with embedded video file that was re-encoded to allow for seeking. – AlexG Mar 6 at 15:36

JavaScript is not required.

Additional control buttons can be inserted with the \mediabutton command. Look into the media9 manual for examples.

If you cannot seek precisely enough into the video, it may be necessary to re-encode the video with a higher number of key frames.

For example, a key frame at every second, using ffmpeg with options -g ... and -r ... (frame rate) having the same value:

ffmpeg -i video-in.mp4 -c:v libx264 -profile:v high -pix_fmt yuv420p -g 30 -r 30 video-out.mp4


Update: Example on Overleaf with embedded video file example-movie.mp4 from package mwe, re-encoded with a keyframe at every second using above-listed command line.

Example with streamed video:

\documentclass{article}
\usepackage{media9}
\parindent=0pt

\begin{document}

\includemedia[
label=videoexample,
width=16em,height=9em,
activate=pageopen,
passcontext,
transparent,
flashvars={source=https://ia800501.us.archive.org/10/items/BigBuckBunny_310/big_buck_bunny_640_512kb.mp4}
]{}{VPlayer.swf}

\mediabutton[
mediacommand=videoexample:play[(25)],
mediacommand=videoexample:pause
]{\fbox{25~s}}
\mediabutton[
mediacommand=videoexample:play[(50)],
mediacommand=videoexample:pause
]{\fbox{50~s}}
\mediabutton[
mediacommand=videoexample:play[(150)],
mediacommand=videoexample:pause
]{\fbox{150~s}}

\end{document}