Module for taking still images from RTSP video streams and USB webcams, using FFmpeg.
On Linux, install the packages ffmpeg
and v4l-utils
:
$ sudo apt-get install ffmpeg v4l-utils
List connected USB cameras:
$ v4l2-ctl --list-devices
UVC Camera (046d:0825) (usb-0000:00:1d.7-1):
/dev/video0
/dev/video1
/dev/media0
The following example captures an image from an attached USB webcam at
/dev/video0
and adds a timestamp in ISO 8601 format to it using
GraphicMagick:
character(len=*), parameter :: IMAGE_PATH = '/tmp/image.jpg'
integer :: rc
type(camera_type) :: camera
camera = camera_type(input='/dev/video0', device=CAMERA_DEVICE_V4L)
rc = dm_camera_capture(camera, IMAGE_PATH)
if (dm_is_error(rc)) call dm_error_out(rc)
rc = dm_gm_add_text_box(IMAGE_PATH, text=dm_time_now())
if (dm_is_error(rc)) call dm_error_out(rc)
Change the camera type to capture an RTSP stream instead:
camera = camera_type(input='rtsp://10.10.10.15:8554/camera1', device=CAMERA_DEVICE_RTSP)
The attribute input
must be set to the stream URL.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
integer, | public, | parameter | :: | CAMERA_DEVICE_NONE | = | 0 |
No device selected. |
integer, | public, | parameter | :: | CAMERA_DEVICE_RTSP | = | 1 |
RTSP stream. |
integer, | public, | parameter | :: | CAMERA_DEVICE_V4L | = | 2 |
USB webcam via Video4Linux2. |
integer, | public, | parameter | :: | CAMERA_DEVICE_LAST | = | 2 |
Never use this. |
integer, | public, | parameter | :: | CAMERA_DEVICE_NAME_LEN | = | 4 | |
character(len=*), | public, | parameter | :: | CAMERA_DEVICE_NAMES(CAMERA_DEVICE_NONE:CAMERA_DEVICE_LAST) | = | [character(len=CAMERA_DEVICE_NAME_LEN)::'none', 'rtsp', 'v4l'] |
Camera device names. |
Camera settings type.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
character(len=FILE_PATH_LEN), | public | :: | input | = | ' ' |
Input device path ( |
|
integer, | public | :: | device | = | CAMERA_DEVICE_NONE |
Input device. |
|
integer, | public | :: | width | = | 0 |
Camera stream width in pixels (optional). |
|
integer, | public | :: | height | = | 0 |
Camera stream height in pixels (optional). |
Captures a single frame from a V4L device or RTSP stream with
FFmpeg, and optionally adds a timestamp with GraphicsMagick. If the
input is an RTSP stream, the URL must start with rtsp://
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(camera_type), | intent(in) | :: | camera |
Camera type. |
||
character(len=*), | intent(in) | :: | output |
Output file. |
||
character(len=:), | intent(out), | optional, | allocatable | :: | command |
Executed command. |
Returns device enumerator from name. On error, the result is
CAMERA_DEVICE_NONE
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | name |
Device name. |
Returns .true.
if device enumerator is valid. The device
CAMERA_DEVICE_NONE
is invalid.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | device |
Camera device enumerator. |