YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
FfmpegGrabber Class Reference

ffmpeg_grabber: An image frame grabber device using ffmpeg to capture images from AVI files. More...

#include <ffmpeg/FfmpegGrabber.h>

+ Inheritance diagram for FfmpegGrabber:

Public Member Functions

 FfmpegGrabber ()
 
bool open (yarp::os::Searchable &config) override
 Open the DeviceDriver.
 
bool close () override
 Close the DeviceDriver.
 
bool getImage (yarp::sig::ImageOf< yarp::sig::PixelRgb > &image) override
 Get an image from the frame grabber.
 
bool getSound (yarp::sig::Sound &sound, size_t min_number_of_samples, size_t max_number_of_samples, double max_samples_timeout_s) override
 Get a sound from a device.
 
int height () const override
 Return the height of each frame.
 
int width () const override
 Return the width of each frame.
 
virtual bool getAudioVisual (yarp::sig::ImageOf< yarp::sig::PixelRgb > &image, yarp::sig::Sound &sound) override
 Get an image and sound.
 
bool hasAudio () override
 
bool hasVideo () override
 
bool startRecording () override
 Start the recording.
 
bool stopRecording () override
 Stop the recording.
 
bool isRecording (bool &recording_enabled) override
 Check if the recording has been enabled (e.g.
 
bool getRecordingAudioBufferMaxSize (yarp::sig::AudioBufferSize &) override
 
bool getRecordingAudioBufferCurrentSize (yarp::sig::AudioBufferSize &) override
 
bool resetRecordingAudioBuffer () override
 
bool setHWGain (double gain) override
 Sets the hardware gain of the grabbing device (if supported by the hardware)
 
bool setSWGain (double gain) override
 Sets a software gain for the grabbed audio.
 
- Public Member Functions inherited from yarp::dev::IFrameGrabberOf< yarp::sig::ImageOf< yarp::sig::PixelRgb > >
virtual bool getImageCrop (cropType_id_t cropType, yarp::sig::VectorOf< std::pair< int, int > > vertices, yarp::sig::ImageOf< yarp::sig::PixelRgb > &image)
 Get a crop of the image from the frame grabber.
 
- Public Member Functions inherited from yarp::dev::IFrameGrabberImageBase
virtual ~IFrameGrabberImageBase ()
 Destructor.
 
- Public Member Functions inherited from yarp::dev::IAudioGrabberSound
virtual ~IAudioGrabberSound ()
 Destructor.
 
- Public Member Functions inherited from yarp::dev::IAudioVisualGrabber
virtual ~IAudioVisualGrabber ()
 Destructor.
 
- Public Member Functions inherited from yarp::dev::IAudioVisualStream
virtual ~IAudioVisualStream ()
 Destructor.
 
virtual bool hasRawVideo ()
 
- Public Member Functions inherited from yarp::dev::DeviceDriver
 DeviceDriver ()
 
 DeviceDriver (const DeviceDriver &other)=delete
 
 DeviceDriver (DeviceDriver &&other) noexcept=delete
 
DeviceDriveroperator= (const DeviceDriver &other)=delete
 
DeviceDriveroperator= (DeviceDriver &&other) noexcept=delete
 
virtual ~DeviceDriver ()
 
virtual std::string id () const
 Return the id assigned to the PolyDriver.
 
virtual void setId (const std::string &id)
 Set the id for this device.
 
template<class T >
bool view (T *&x)
 Get an interface to the device driver.
 
virtual DeviceDrivergetImplementation ()
 Some drivers are bureaucrats, pointing at others.
 
- Public Member Functions inherited from FfmpegGrabber_ParamsParser
 FfmpegGrabber_ParamsParser ()
 
 ~FfmpegGrabber_ParamsParser () override=default
 
bool parseParams (const yarp::os::Searchable &config) override
 Parse the DeviceDriver parameters.
 
std::string getDeviceClassName () const override
 Get the name of the DeviceDriver class.
 
std::string getDeviceName () const override
 Get the name of the device (i.e.
 
std::string getDocumentationOfDeviceParams () const override
 Get the documentation of the DeviceDriver's parameters.
 
std::vector< std::string > getListOfParams () const override
 Return a list of all params used by the device.
 
- Public Member Functions inherited from yarp::dev::IDeviceDriverParams
virtual ~IDeviceDriverParams ()
 

Protected Member Functions

bool openFirewire (yarp::os::Searchable &config, AVFormatContext **ppFormatCtx)
 
bool openV4L (yarp::os::Searchable &config, AVFormatContext **ppFormatCtx, AVFormatContext **ppFormatCtx2)
 
bool openFile (AVFormatContext **ppFormatCtx, const char *fname)
 

Protected Attributes

void * system_resource = nullptr
 
AVDictionary * formatParamsVideo = nullptr
 
AVDictionary * formatParamsAudio = nullptr
 
AVFormatContext * pFormatCtx = nullptr
 
AVFormatContext * pFormatCtx2 = nullptr
 
AVFormatContext * pAudioFormatCtx = nullptr
 
AVPacket packet
 
bool active
 
double startTime
 
bool _hasAudio = false
 
bool _hasVideo = false
 
bool needRateControl
 
bool imageSync
 
std::string m_uri
 Uri of the images a grabber produces.
 
int m_w = 0
 Width of the images a grabber produces.
 
int m_h = 0
 Height of the images a grabber produces.
 
int m_channels = 0
 
int m_rate = 0
 
void * m_capture = nullptr
 Opaque ffmpeg structure for image capture.
 

Additional Inherited Members

- Public Attributes inherited from FfmpegGrabber_ParamsParser
const std::string m_device_classname = {"FfmpegGrabber"}
 
const std::string m_device_name = {"ffmpeg_grabber"}
 
bool m_parser_is_strict = false
 
const parser_version_type m_parser_version = {}
 
const std::string m_source_defaultValue = {"default.avi"}
 
const std::string m_loop_defaultValue = {"true"}
 
const std::string m_sync_defaultValue = {"image"}
 
const std::string m_nodelay_defaultValue = {"false"}
 
const std::string m_pace_defaultValue = {"1.0"}
 
const std::string m_v4l_defaultValue = {"false"}
 
const std::string m_v4l1_defaultValue = {"false"}
 
const std::string m_v4l2_defaultValue = {"false"}
 
const std::string m_ieee1394_defaultValue = {"false"}
 
const std::string m_v4ldevice_defaultValue = {"/dev/video0"}
 
const std::string m_audio_defaultValue = {"/dev/dsp"}
 
const std::string m_audio_rate_defaultValue = {"44100"}
 
const std::string m_channels_defaultValue = {"1"}
 
const std::string m_time_base_num_defaultValue = {"1"}
 
const std::string m_time_base_den_defaultValue = {"29"}
 
const std::string m_channel_defaultValue = {"0"}
 
const std::string m_standard_defaultValue = {""}
 
const std::string m_width_defaultValue = {"640"}
 
const std::string m_height_defaultValue = {"480"}
 
const std::string m_devname_defaultValue = {"/dev/dv1394"}
 
std::string m_source = {"default.avi"}
 
bool m_loop = {true}
 
std::string m_sync = {"image"}
 
bool m_nodelay = {false}
 
double m_pace = {1.0}
 
bool m_v4l = {false}
 
bool m_v4l1 = {false}
 
bool m_v4l2 = {false}
 
bool m_ieee1394 = {false}
 
std::string m_v4ldevice = {"/dev/video0"}
 
std::string m_audio = {"/dev/dsp"}
 
int m_audio_rate = {44100}
 
int m_channels = {1}
 
int m_time_base_num = {1}
 
int m_time_base_den = {29}
 
int m_channel = {0}
 
std::string m_standard = {}
 
int m_width = {640}
 
int m_height = {480}
 
std::string m_devname = {"/dev/dv1394"}
 

Detailed Description

ffmpeg_grabber: An image frame grabber device using ffmpeg to capture images from AVI files.

Parameters required by this device are shown in class: FfmpegGrabber_ParamsParser

Definition at line 38 of file FfmpegGrabber.h.

Constructor & Destructor Documentation

◆ FfmpegGrabber()

FfmpegGrabber::FfmpegGrabber ( )
inline

Definition at line 48 of file FfmpegGrabber.h.

Member Function Documentation

◆ close()

bool FfmpegGrabber::close ( )
overridevirtual

Close the DeviceDriver.

Returns
true/false on success/failure.

Reimplemented from yarp::dev::DeviceDriver.

Definition at line 569 of file FfmpegGrabber.cpp.

◆ getAudioVisual()

bool FfmpegGrabber::getAudioVisual ( yarp::sig::ImageOf< yarp::sig::PixelRgb > &  image,
yarp::sig::Sound sound 
)
overridevirtual

Get an image and sound.

Parameters
imagethe image to be filled
soundthe sound to be filled
Returns
true/false upon success/failure

Implements yarp::dev::IAudioVisualGrabber.

Definition at line 619 of file FfmpegGrabber.cpp.

◆ getImage()

bool FfmpegGrabber::getImage ( yarp::sig::ImageOf< yarp::sig::PixelRgb > &  image)
overridevirtual

Get an image from the frame grabber.

Parameters
imagethe image to be filled
Returns
true/false upon success/failure

Implements yarp::dev::IFrameGrabberOf< yarp::sig::ImageOf< yarp::sig::PixelRgb > >.

Definition at line 600 of file FfmpegGrabber.cpp.

◆ getRecordingAudioBufferCurrentSize()

bool FfmpegGrabber::getRecordingAudioBufferCurrentSize ( yarp::sig::AudioBufferSize )
inlineoverridevirtual

Implements yarp::dev::IAudioGrabberSound.

Definition at line 97 of file FfmpegGrabber.h.

◆ getRecordingAudioBufferMaxSize()

bool FfmpegGrabber::getRecordingAudioBufferMaxSize ( yarp::sig::AudioBufferSize )
inlineoverridevirtual

Implements yarp::dev::IAudioGrabberSound.

Definition at line 93 of file FfmpegGrabber.h.

◆ getSound()

bool FfmpegGrabber::getSound ( yarp::sig::Sound sound,
size_t  min_number_of_samples,
size_t  max_number_of_samples,
double  max_samples_timeout_s 
)
overridevirtual

Get a sound from a device.

Examples: getSound(s, 0, 100, 0.1); returns a sound whose size can vary between 0 and 100, with a maximum blocking time of 0.1 getSound(s, 100, 100, 0.0); returns a sound with exact size of 100. It may block forever (more specifically, until sound size is at least 100). getSound(s, 100, 100000, 0.0); returns a sound with a minimum size of 0, while trying to transfer all the internal buffer. It may block forever (more specifically, until sound size is at least 100).

Parameters
soundthe sound to be filled
min_number_of_samples.The function will block until the driver is able to collect at least min_number_of_samples. If set to zero, the function may return empty sounds.
max_number_of_samples.The function will block until the driver is either able to collect max_number_of_samples or the timeout expires.
max_samples_timeout_s.The timeout (in seconds) to retrieve max_number_of_samples.
Returns
true upon success, false for an invalid set of parameters, such as max_number_of_samples<min_number_of_samples, etc.

Implements yarp::dev::IAudioGrabberSound.

Definition at line 609 of file FfmpegGrabber.cpp.

◆ hasAudio()

bool FfmpegGrabber::hasAudio ( )
inlineoverridevirtual

Implements yarp::dev::IAudioVisualStream.

Definition at line 73 of file FfmpegGrabber.h.

◆ hasVideo()

bool FfmpegGrabber::hasVideo ( )
inlineoverridevirtual

Implements yarp::dev::IAudioVisualStream.

Definition at line 77 of file FfmpegGrabber.h.

◆ height()

int FfmpegGrabber::height ( ) const
inlineoverridevirtual

Return the height of each frame.

Returns
image height

Implements yarp::dev::IFrameGrabberImageBase.

Definition at line 65 of file FfmpegGrabber.h.

◆ isRecording()

bool FfmpegGrabber::isRecording ( bool &  recording_enabled)
inlineoverridevirtual

Check if the recording has been enabled (e.g.

via startRecording()/stopRecording())

Parameters
recording_enabledthe status of the device
Returns
true/false upon success/failure

Implements yarp::dev::IAudioGrabberSound.

Definition at line 89 of file FfmpegGrabber.h.

◆ open()

bool FfmpegGrabber::open ( yarp::os::Searchable config)
overridevirtual

Open the DeviceDriver.

Parameters
configis a list of parameters for the device. Which parameters are effective for your device can vary. See device invocation examples. If there is no example for your device, you can run the "yarpdev" program with the verbose flag set to probe what parameters the device is checking. If that fails too, you'll need to read the source code (please nag one of the yarp developers to add documentation for your device).
Returns
true/false upon success/failure

Reimplemented from yarp::dev::DeviceDriver.

Definition at line 435 of file FfmpegGrabber.cpp.

◆ openFile()

bool FfmpegGrabber::openFile ( AVFormatContext **  ppFormatCtx,
const char fname 
)
protected

Definition at line 427 of file FfmpegGrabber.cpp.

◆ openFirewire()

bool FfmpegGrabber::openFirewire ( yarp::os::Searchable config,
AVFormatContext **  ppFormatCtx 
)
protected

Definition at line 414 of file FfmpegGrabber.cpp.

◆ openV4L()

bool FfmpegGrabber::openV4L ( yarp::os::Searchable config,
AVFormatContext **  ppFormatCtx,
AVFormatContext **  ppFormatCtx2 
)
protected

Definition at line 326 of file FfmpegGrabber.cpp.

◆ resetRecordingAudioBuffer()

bool FfmpegGrabber::resetRecordingAudioBuffer ( )
inlineoverridevirtual

Implements yarp::dev::IAudioGrabberSound.

Definition at line 101 of file FfmpegGrabber.h.

◆ setHWGain()

bool FfmpegGrabber::setHWGain ( double  gain)
inlineoverridevirtual

Sets the hardware gain of the grabbing device (if supported by the hardware)

Parameters
gainthe audio gain (1.0 is the default value)
Returns
true/false upon success/failure

Implements yarp::dev::IAudioGrabberSound.

Definition at line 105 of file FfmpegGrabber.h.

◆ setSWGain()

bool FfmpegGrabber::setSWGain ( double  gain)
inlineoverridevirtual

Sets a software gain for the grabbed audio.

Parameters
gainthe audio gain (1.0 is the default value)
Returns
true/false upon success/failure

Implements yarp::dev::IAudioGrabberSound.

Definition at line 109 of file FfmpegGrabber.h.

◆ startRecording()

bool FfmpegGrabber::startRecording ( )
inlineoverridevirtual

Start the recording.

Returns
true/false upon success/failure

Implements yarp::dev::IAudioGrabberSound.

Definition at line 81 of file FfmpegGrabber.h.

◆ stopRecording()

bool FfmpegGrabber::stopRecording ( )
inlineoverridevirtual

Stop the recording.

Returns
true/false upon success/failure

Implements yarp::dev::IAudioGrabberSound.

Definition at line 85 of file FfmpegGrabber.h.

◆ width()

int FfmpegGrabber::width ( ) const
inlineoverridevirtual

Return the width of each frame.

Returns
image width

Implements yarp::dev::IFrameGrabberImageBase.

Definition at line 67 of file FfmpegGrabber.h.

Member Data Documentation

◆ _hasAudio

bool FfmpegGrabber::_hasAudio = false
protected

Definition at line 124 of file FfmpegGrabber.h.

◆ _hasVideo

bool FfmpegGrabber::_hasVideo = false
protected

Definition at line 125 of file FfmpegGrabber.h.

◆ active

bool FfmpegGrabber::active
protected

Definition at line 122 of file FfmpegGrabber.h.

◆ formatParamsAudio

AVDictionary* FfmpegGrabber::formatParamsAudio = nullptr
protected

Definition at line 117 of file FfmpegGrabber.h.

◆ formatParamsVideo

AVDictionary* FfmpegGrabber::formatParamsVideo = nullptr
protected

Definition at line 116 of file FfmpegGrabber.h.

◆ imageSync

bool FfmpegGrabber::imageSync
protected

Definition at line 127 of file FfmpegGrabber.h.

◆ m_capture

void* FfmpegGrabber::m_capture = nullptr
protected

Opaque ffmpeg structure for image capture.

Definition at line 141 of file FfmpegGrabber.h.

◆ m_channels

int FfmpegGrabber::m_channels = 0
protected

Definition at line 137 of file FfmpegGrabber.h.

◆ m_h

int FfmpegGrabber::m_h = 0
protected

Height of the images a grabber produces.

Definition at line 135 of file FfmpegGrabber.h.

◆ m_rate

int FfmpegGrabber::m_rate = 0
protected

Definition at line 138 of file FfmpegGrabber.h.

◆ m_uri

std::string FfmpegGrabber::m_uri
protected

Uri of the images a grabber produces.

Definition at line 130 of file FfmpegGrabber.h.

◆ m_w

int FfmpegGrabber::m_w = 0
protected

Width of the images a grabber produces.

Definition at line 133 of file FfmpegGrabber.h.

◆ needRateControl

bool FfmpegGrabber::needRateControl
protected

Definition at line 126 of file FfmpegGrabber.h.

◆ packet

AVPacket FfmpegGrabber::packet
protected

Definition at line 121 of file FfmpegGrabber.h.

◆ pAudioFormatCtx

AVFormatContext* FfmpegGrabber::pAudioFormatCtx = nullptr
protected

Definition at line 120 of file FfmpegGrabber.h.

◆ pFormatCtx

AVFormatContext* FfmpegGrabber::pFormatCtx = nullptr
protected

Definition at line 118 of file FfmpegGrabber.h.

◆ pFormatCtx2

AVFormatContext* FfmpegGrabber::pFormatCtx2 = nullptr
protected

Definition at line 119 of file FfmpegGrabber.h.

◆ startTime

double FfmpegGrabber::startTime
protected

Definition at line 123 of file FfmpegGrabber.h.

◆ system_resource

void* FfmpegGrabber::system_resource = nullptr
protected

Definition at line 114 of file FfmpegGrabber.h.


The documentation for this class was generated from the following files: