You are not logged in.

#1 2006-11-01 09:43:11

Bob Day
Member
Registered: 2005-11-26
Posts: 43

[perl] adapt kissntel.pl for re-encoding movies on the fly

ok...it became quite a long story...hopefully I made it an understandable story:

What I would like to achieve is adapting a perl script kiss-n-tel.pl ( http://kissntel.skunkworks.net.au/ ) so it can play movie files that are re-encoded at the fly. Kiss-n-tel.pl acts like a server for sending media files to my hardware xvid player. Communication goes over lan.

What kiss-n-tell already can is accepting requests from the xvid player to send parts of a media file (for instance an .avi file). Kiss-n-tell will read the requested part from the media file and send it back to the xvid player to play.

The hardware player always seems to request parts of the media files in the same order:
- First it asks for the headers (this goes in a non-linear fashion, so the requests jumps around through the headers of an avi file).
- Next it asks for subtitles.
- Third it asks for fixed size blocks of video in a linear fashion.

What I tried is to re-encode the movie on the fly like this:
$ mkfifo out.avi
$ mencoder ./in.avi ... -o ./out.avi

in another terminal:
$ cat <out.avi | bfr > playme.avi

via the remote control of the xvid player I choose the playme.avi to play.
I end up with a black screen.

I think I know where it goes wrong (not sure though)... It seems that the xvid player likes to re-read parts of the header from playme.avi (the log of kiss-n-tel tells me this). This isn't possible with a fifo I think, since that what has been send is gone. Question 1: Am I right on this?

I'm thinking about two possible solutions:
1. Fool the xvid player and read out the headers from another video first. Once the xvid player is requesting the actually video, I read out the headers from playme.avi at once, throw it away and start reading out the video in a linear fashion always from offset 0.

2. create a real buffer file that is somehow limited to a certain file size.
It's minimal file size should at least be able to contain the headers + n times the size of the requested vdeo blocks. In this case, once I'm done with the headers, I can always read at an offset 0. Question 2: Will this be possible in theory? I mean, can these buffers be made and is it possible to chop off beginning of a file and add new content to the end of the file? Do you have links on this?

Question 3: do you have better suggestions to achieve my goal?

Here are is a parts of the perl script in kissntel.pl that reads blocks of the video:

    # digest the cmdline requested by the xvid player
    $cmdline =~ /GETs(.*)|s([d]+)s([d]+)/;
    $file   = $1;
    $offset = $2;
    $bytes  = $3;

    # don't reopen everytime we get a GET request.
    # this thread will only every handle 1 file, so we are safe
    if(!$fileopen){
        open(MEDIA, $file) || LOG(1, "unable to open file $file");
        $fileopen=1;
        LOG(2, "file $file opened");
    }
    
    # do the seek as one day kiss may support fast forward and rewind!
    seek(MEDIA, $offset, 0);

    my $bytesread = read(MEDIA, $buff, $bytes);
    sendkiss($buff, NO_LOG);

Offline

Board footer

Powered by FluxBB