Hi,
I would like to write a small application that reads data from
/dev/video0 at a prespecified time and writes it to a binary file. [1]
Is there anything special I need to consider when reading from a Unix
device? I am using SBCL if that matters.
Tamas
[1] Some might say that Lisp is not ideal for this, but the overhead
is small and Lisp is the only general purpose programming language I
know (besides C), so I want to give it a try.
Tamas Papp wrote:
> Hi,
>
> I would like to write a small application that reads data from
> /dev/video0 at a prespecified time and writes it to a binary file. [1]
> Is there anything special I need to consider when reading from a Unix
> device? I am using SBCL if that matters.
>
Have you already read video data from C? The following is not lisp
specific: You will likely need to use quite a number of the
appropriate v4l2 (assuming linux) platform-specific ioctl() calls to
configure the device to get something vaguely sensible from it.
ioctls are a feature of many "/dev file"-based APIs, not just video, but
in the v4l case you almost certainly won't get away with ignoring them:
http://v4l2spec.bytesex.org/spec/r6097.htm
David Golden <············@oceanfree.net> writes:
> Tamas Papp wrote:
>
>> Hi,
>>
>> I would like to write a small application that reads data from
>> /dev/video0 at a prespecified time and writes it to a binary file. [1]
>> Is there anything special I need to consider when reading from a Unix
>> device? I am using SBCL if that matters.
>>
>
> Have you already read video data from C? The following is not lisp
> specific: You will likely need to use quite a number of the
> appropriate v4l2 (assuming linux) platform-specific ioctl() calls to
> configure the device to get something vaguely sensible from it.
>
> ioctls are a feature of many "/dev file"-based APIs, not just video, but
> in the v4l case you almost certainly won't get away with ignoring them:
> http://v4l2spec.bytesex.org/spec/r6097.htm
This is not a v4l device, it sends MPEG streams directly. Eg
cat /dev/video0 > foo.avi
will create perfectly playable AVI files.
I have never read video or any other data from a UNIX device in any
language, so I was wondering if there is anything tricky about reading
data from a device. Essentially, I want to replicate cat in Lisp ;-)
I just don't know what to watch for.
Tamas
Tamas Papp <······@gmail.com> writes:
> This is not a v4l device, it sends MPEG streams directly. Eg
>
> cat /dev/video0 > foo.avi
>
> will create perfectly playable AVI files.
>
> I have never read video or any other data from a UNIX device in any
> language, so I was wondering if there is anything tricky about reading
> data from a device. Essentially, I want to replicate cat in Lisp ;-)
> I just don't know what to watch for.
You can just open it and read from it. The easiest way work with a
Unix binary stream is by using the (UNSIGNED-BYTE 8) stream element
type, e.g.
(defun copy-n-octets (input-file output-file n)
(with-open-file (input-stream input-file
:direction :input
:element-type '(unsigned-byte 8))
(with-open-file (output-stream output-file
:direction :output
:element-type '(unsigned-byte 8))
(dotimes (i n)
(let ((octet (read-byte input-stream nil)))
(if octet
(write-byte octet output-stream )
(return)))))))
READ-BYTE and WRITE-BYTE are simple and easy to use. Using
READ-SEQUENCE and WRITE-SEQUENCE would probably make this very
efficient in most implementations.
Zach
On Mon, 16 Jul 2007 17:17:03 +0200, <······@gmail.com> wrote:
>
> This is not a v4l device, it sends MPEG streams directly. Eg
>
> cat /dev/video0 > foo.avi
>
> will create perfectly playable AVI files.
In addition to what Zach has presented, I think I would look more
carefully at your claim. A playable AVI is not necessarily a complete
AVI copy of the video stream. If you are really sure that there are
not dropouts in the video stream, then indeed a file-copy program
should work. However, maybe shot dropouts are unimportant. I wonder
how you will decide to stop (probably never right?) recording.
Planning on doing some recogition on the video? I had a pre-lisp
project along those lines that maybe I should dust off.
--
There are no average Common Lisp programmers
Reply-To: email is ignored.
--
Posted via a free Usenet account from http://www.teranews.com