morgon has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

is there a way for a perl-script to detect that a video playing in chromium has finished playing?

What I want to do is to record some instructional videos that consist of a video and a synchronized chessboard.

The video is mp4 and I can easily download that, but it only contains talking heads and is useless without context on the chessboard, so my idea is to screen-record the whole thing which is no problem as such except that I need to figure out a way detect the end of the video so I can stop the recording unattended.

I was thinking that maybe WWW::Mechanize::Chrome could help or is there some image-processing module that would allow me to detect that a certain screen-region is no longer changing?

I am not looking for complete code examples, just for a pointer towards something that might work.

Many thanks!

Replies are listed 'Best First'.
Re: detect end of video
by Corion (Patriarch) on Aug 07, 2017 at 06:28 UTC

    You should be able to detect the position/state of the video by polling:

    my( $value, $type ) = $mech->eval_in_page(<<'JS'); var videoElement = find_video_element(); // you need to write that + yourself return videoElement.ended; JS

    Also of interest could be videoElement.currentTime; to maybe better synchronize your playback.

    You could also use more fancy Javascript to send events to a Perl webserver when the playback starts/ends or every five seconds etc.