![]() |
University of Murcia, Spain ![]() |
QVMPlayerReader Class ReferenceClass to read from many video formats and devices, based on the MPlayer application.
More...
|
Public Types | |
enum | OpenOption { Default = 0x0, RealTime = 0x1, Deinterlaced = 0x2, NoLoop = 0x4 } |
enum | TSeekType { SeekCurrent = 0, SeekPercentage = 1, SeekAbsolute = 2 } |
Public Slots | |
void | closeCam () |
void | seekCam (TSeekType type, double pos) |
Moves the camera file to a given position (if applicable; not valid for live cameras, for example). | |
Public Member Functions | |
QVMPlayerReader () | |
~QVMPlayerReader () | |
bool | openCam (const QString &urlstring, OpenOptions opts=Default, unsigned int suggested_cols=0, unsigned int suggested_rows=0) |
Opens a mplayer source given by its URL, in a requested mode and output scale size. | |
bool | grab (QVImage< uChar, 1 > &image) |
Grabs a grayscale frame. | |
bool | grab (QVImage< uChar, 3 > &imageRGB) |
Grabs a RGB frame. | |
bool | grab (QVImage< uChar > &imgY, QVImage< uChar > &imgU, QVImage< uChar > &imgV) |
Grabs a frame in YUV format. | |
const QString | getUrlBase () const |
Returns the current camera name (without path). | |
OpenOptions | getOptions () const |
Returns current camera options. | |
unsigned int | getCols () const |
Returns the number of cols of the buffer. | |
unsigned int | getRows () const |
Returns the number of rows of the buffer. | |
double | getFPS () const |
Returns the camera speed in frames per second. | |
double | getTimeLength () const |
Returns the video file length in seconds. | |
double | getTimePos () const |
Returns the current video position in seconds. | |
unsigned int | getFramesGrabbed () const |
Returns number of frames grabbed. | |
bool | isLiveCamera () const |
Tells if the camera is a live camera. |
This class is based on the MPlayer application. It can read videos from a wide variety of media formats, webcams and digital cameras.
Internally, when used to read from a video source compatible with MPlayer, the QVMPlayerReader object will launch the MPlayer application to open and read from a video source. MPlayer will be configured to redirect its output to a system pipeline (named fifo), from which the QVMPlayerRead class will read video frames.
You will probably never have to directly use this class. Usually, you will directly use a QVMPlayerCameraWorker instead, which internally (and transparently) uses this class. Anyway, it is important for you to know well the URL syntax for especifying a video source:
path-to-file/file-name.{avi, mpg, dv, ...}
/dev/devicename
path-to-directory/filemask.{jpg, png, ...}
Notation: [] means optional, {} means alternative:
file://[path-to-file/]file-name.{avi, mpg, dv, ...}
file:///home/vision/penguin.dv
file://../../home/vision/penguin.dv
{http,rtsp,ftp}://domain-name/path-to-file/file.{avi, mpg, dv, ...}
rtsp://ficheros.7rm.es/7RM/7rm06-01-071430.rm
http://perception.inf.um.es/public_data/videos/misc/penguin.dv
ftp://user:passwd@server.dom/data/video.avi
{dvd,vcd}://{video track}
dvd://2
vcd://1
mf://path-to/filemask.{jpg, png, ...}
mf:///home/user/images/img*.jpg
mf:///./images/img*.png
{v4l,v4l2,analog}://{device file}[?options]
v4l:///dev/video0
analog:///dev/video0
Setting the width and height for the images read from the input device using parameters width and height differs from using r and c parameters of the openCam() method. The former can configure the device to capture images using a higher or lesser resolution, while the latter simply (post-)scale the images as MPlayer reads them from the input device in their original sizes.
These options work for video 4 Linux, video 4 Linux 2 camera, and analog inputs. They can be included appending a ? sign after the URL for the device, and separated with & signs. Some example usages of these URL options follow:
v4l2:///dev/video0?height=480&width=640&brightness=-100&fps=25
/dev/video0?height=480&width=640&brightness=-100&fps=25
analog:///dev/tv?height=240&width=320&channel=42
Definition at line 145 of file qvmplayerreader.h.
Open options for a mplayer camera. Combine them using OR (|).
Definition at line 156 of file qvmplayerreader.h.
Options for a seek through the file.
Definition at line 168 of file qvmplayerreader.h.
QVMPlayerReader::QVMPlayerReader | ( | ) | [inline] |
Constructs a QVMPlayerReader.
Definition at line 150 of file qvmplayerreader.h.
QVMPlayerReader::~QVMPlayerReader | ( | ) | [inline] |
Destroys a QVMPlayerReader.
Definition at line 153 of file qvmplayerreader.h.
bool QVMPlayerReader::openCam | ( | const QString & | urlstring, | |
OpenOptions | opts = Default , |
|||
unsigned int | suggested_cols = 0 , |
|||
unsigned int | suggested_rows = 0 | |||
) |
Opens a mplayer source given by its URL, in a requested mode and output scale size.
Note: Please observe that mplayer could slightly change the suggested size when playing the video (for example, an even number of cols is not allowed, due to YUV422 format restrictions). You can use methods getCols() and getRows() after opening to confirm the correct values.
urlstring | Camera identifying URL string. See Video source identifier URL formats for URL formats. | |
opts | Camera opening options (see QVMPlayerReader::openOption) | |
suggested_cols | Number of requested output cols (0 => default width of video). | |
suggested_rows | Number of requested output rows (0 => default height of video). |
Definition at line 251 of file qvmplayerreader.cpp.
Referenced by QVMPlayerCameraWorker::openCam().
bool QVMPlayerReader::grab | ( | QVImage< uChar, 1 > & | image | ) |
Grabs a grayscale frame.
image | QVImage<uChar,1> that will store grabbed frame. |
Definition at line 434 of file qvmplayerreader.cpp.
Referenced by QVMPlayerCameraWorker::grab().
bool QVMPlayerReader::grab | ( | QVImage< uChar, 3 > & | imageRGB | ) |
Grabs a RGB frame.
imageRGB | QVImage<uChar,3> that will store grabbed frame. |
Definition at line 446 of file qvmplayerreader.cpp.
bool QVMPlayerReader::grab | ( | QVImage< uChar > & | imgY, | |
QVImage< uChar > & | imgU, | |||
QVImage< uChar > & | imgV | |||
) |
Grabs a frame in YUV format.
This function grabs the image in YUV format, storing each channel Y, U and V, in a separate QVImage of one channel (note that YUV format is 422, thus QVImage corresponding to plane Y will be four times larger than those corresponding to planes U and V).
imgY | QVImage<uChar,1> that will store grabbed frame Y channel. | |
imgU | QVImage<uChar,1> that will store grabbed frame U channel (half sized cols and rows). | |
imgV | QVImage<uChar,1> that will store grabbed frame V channel (half sized cols and rows). |
Definition at line 459 of file qvmplayerreader.cpp.
void QVMPlayerReader::closeCam | ( | ) | [slot] |
Closes the camera.
Definition at line 379 of file qvmplayerreader.cpp.
Referenced by QVMPlayerCameraWorker::closeCam(), openCam(), QVMPlayerCameraWorker::~QVMPlayerCameraWorker(), and ~QVMPlayerReader().
void QVMPlayerReader::seekCam | ( | TSeekType | type, | |
double | pos | |||
) | [slot] |
Moves the camera file to a given position (if applicable; not valid for live cameras, for example).
type | Type of seek: SeekCurrent=0, SeekPercentage=1, SeekAbsolute=2. | |
pos |
|
Definition at line 473 of file qvmplayerreader.cpp.
const QString QVMPlayerReader::getUrlBase | ( | ) | const [inline] |
Returns the current camera name (without path).
Definition at line 230 of file qvmplayerreader.h.
OpenOptions QVMPlayerReader::getOptions | ( | ) | const [inline] |
Returns current camera options.
Definition at line 234 of file qvmplayerreader.h.
unsigned int QVMPlayerReader::getCols | ( | ) | const [inline] |
Returns the number of cols of the buffer.
Definition at line 238 of file qvmplayerreader.h.
Referenced by QVMPlayerCameraWorker::openCam().
unsigned int QVMPlayerReader::getRows | ( | ) | const [inline] |
Returns the number of rows of the buffer.
Definition at line 242 of file qvmplayerreader.h.
Referenced by QVMPlayerCameraWorker::openCam().
double QVMPlayerReader::getFPS | ( | ) | const [inline] |
Returns the camera speed in frames per second.
Definition at line 246 of file qvmplayerreader.h.
Referenced by QVMPlayerCameraWorker::openCam().
double QVMPlayerReader::getTimeLength | ( | ) | const [inline] |
Returns the video file length in seconds.
Note: Please observe that mplayer does not tell us the length of the video in seconds until it has read a few frames (commonly two or three). Thus, this function will return 0.0 until a few calls to any grab() function have been made.
Definition at line 255 of file qvmplayerreader.h.
double QVMPlayerReader::getTimePos | ( | ) | const [inline] |
Returns the current video position in seconds.
Definition at line 259 of file qvmplayerreader.h.
unsigned int QVMPlayerReader::getFramesGrabbed | ( | ) | const [inline] |
Returns number of frames grabbed.
Definition at line 263 of file qvmplayerreader.h.
bool QVMPlayerReader::isLiveCamera | ( | ) | const [inline] |
Tells if the camera is a live camera.
Definition at line 267 of file qvmplayerreader.h.
Referenced by QVMPlayerCameraWorker::openCam().