Show caller id and pause MythTV on call

As of Version 0.25 MythTV has a very handy Services API (see documentation here), my first go around with the API was to use it to pause my Frontend Machine when a phone call is incoming and display the caller id on screen.

This how I have done it: I own a Snom VoIP Phone so i use the Action URL (incoming call) setting to execute a php script running on the MythTV Backend http://mythtvbackend/caller.php?caller=$caller, $caller is replaced with the caller id by the snom phone. The php script looks like this:

<?php
$caller = $_GET["caller"];

$fd = fopen( "http://192.168.100.30:6547/Frontend/SendAction?Action=PAUSE", "r" );
if (!$fd) {
    echo "Cannot open URL";
} else {
    while(!feof($fd)) {
        $buffer = fgets($fd, 4096);
        echo $buffer;
    }
    fclose( $fd );
}

$message = urlencode("Anruf von $caller");
$fd = fopen( "http://192.168.100.30:6547/Frontend/SendMessage?Message=$message", "r" );
if (!$fd) {
    echo "Cannot open URL";
} else {
    while(!feof($fd)) {
        $buffer = fgets($fd, 4096);
        echo $buffer;
    }
    fclose( $fd );
}
?>

Note that it echoes also the return of the API calls, I did that so that it is possible to debug a bit by calling the script by browser. It should be easy to cook something similar up to use as a asterisk AGI script if you don’t own a snom phone.

Creating image files from a video file in matlab

The question came up from two colleagues separately how to create  single image files from a video using matlab – either every frame or every 2nd, 5th and so on. Background is we have some cameras in the lab that produce only videos and the PIV (Particle Image Velocimetry) Software only accepts picture files.  Unfortunately there are different ways to try that in Matlab (command in opening the video file etc). This turned out to be the only reliable code snippet:

vidfile = "yourvideo.avi";
BaseName='frame_';
vid = mmreader(vidfile);

for k = 1:10:vid.NumberOfFrames
    image = read(vid,k);
    FileName=[BaseName,num2str(k),'.jpg'];
    imwrite (image,FileName);
end

If You take a look at the for loop, You will see we save every 10th picture in this example. And the pictures are saved as frame_10.jpg, frame_20.jpg …