YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
FfmpegGrabber.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef FfmpegGrabber_INC
8#define FfmpegGrabber_INC
9
10#include "avpreamble.h"
11
12extern "C" {
13#include <libavcodec/avcodec.h>
14#include <libavformat/avformat.h>
15}
16
17/*
18 * A YARP frame grabber device driver using ffmpeg to implement
19 * image capture from AVI files.
20 */
21
26
27#include "ffmpeg_api.h"
29
45{
46public:
47
49 active(false),
50 startTime(0),
51 needRateControl(false),
52 imageSync(false)
53 {
54 memset(&packet,0,sizeof(packet));
55 }
56
57 bool open(yarp::os::Searchable & config) override;
58
59 bool close() override;
60
62
63 bool getSound(yarp::sig::Sound& sound, size_t min_number_of_samples, size_t max_number_of_samples, double max_samples_timeout_s) override;
64
65 int height() const override { return m_h; }
66
67 int width() const override { return m_w; }
68
70 yarp::sig::Sound& sound) override;
71
72
73 bool hasAudio() override {
74 return _hasAudio;
75 }
76
77 bool hasVideo() override {
78 return _hasVideo;
79 }
80
81 bool startRecording() override {
82 return true;
83 }
84
85 bool stopRecording() override {
86 return true;
87 }
88
89 bool isRecording(bool& recording_enabled) override {
90 return false;
91 }
92
94 return false;
95 }
96
98 return false;
99 }
100
102 return false;
103 }
104
105 bool setHWGain(double gain) override {
106 return false;
107 }
108
109 bool setSWGain(double gain) override {
110 return false;
111 }
112
113protected:
114 void *system_resource = nullptr;
115
116 AVDictionary* formatParamsVideo = nullptr;
117 AVDictionary* formatParamsAudio = nullptr;
118 AVFormatContext *pFormatCtx = nullptr;
119 AVFormatContext *pFormatCtx2 = nullptr;
120 AVFormatContext *pAudioFormatCtx = nullptr;
121 AVPacket packet;
122 bool active;
123 double startTime;
124 bool _hasAudio = false;
125 bool _hasVideo = false;
128
130 std::string m_uri;
131
133 int m_w = 0;
135 int m_h = 0;
136
137 int m_channels = 0;
138 int m_rate = 0;
139
141 void * m_capture = nullptr;
142
144 AVFormatContext **ppFormatCtx);
145
146 bool openV4L(yarp::os::Searchable & config,
147 AVFormatContext **ppFormatCtx,
148 AVFormatContext **ppFormatCtx2);
149
150 bool openFile(AVFormatContext **ppFormatCtx,
151 const char *fname);
152};
153
154#endif
This class is the parameters parser for class FfmpegGrabber.
ffmpeg_grabber: An image frame grabber device using ffmpeg to capture images from AVI files.
bool openV4L(yarp::os::Searchable &config, AVFormatContext **ppFormatCtx, AVFormatContext **ppFormatCtx2)
bool hasAudio() override
int m_w
Width of the images a grabber produces.
bool getRecordingAudioBufferCurrentSize(yarp::sig::AudioBufferSize &) override
bool openFile(AVFormatContext **ppFormatCtx, const char *fname)
bool hasVideo() override
int m_h
Height of the images a grabber produces.
bool getRecordingAudioBufferMaxSize(yarp::sig::AudioBufferSize &) override
void * system_resource
bool openFirewire(yarp::os::Searchable &config, AVFormatContext **ppFormatCtx)
bool setSWGain(double gain) override
Sets a software gain for the grabbed audio.
bool setHWGain(double gain) override
Sets the hardware gain of the grabbing device (if supported by the hardware)
int height() const override
Return the height of each frame.
AVFormatContext * pAudioFormatCtx
bool resetRecordingAudioBuffer() override
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.
bool getImage(yarp::sig::ImageOf< yarp::sig::PixelRgb > &image) override
Get an image from the frame grabber.
bool stopRecording() override
Stop the recording.
int width() const override
Return the width of each frame.
bool startRecording() override
Start the recording.
bool isRecording(bool &recording_enabled) override
Check if the recording has been enabled (e.g.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
AVDictionary * formatParamsAudio
AVFormatContext * pFormatCtx2
std::string m_uri
Uri of the images a grabber produces.
virtual bool getAudioVisual(yarp::sig::ImageOf< yarp::sig::PixelRgb > &image, yarp::sig::Sound &sound) override
Get an image and sound.
AVFormatContext * pFormatCtx
AVDictionary * formatParamsVideo
void * m_capture
Opaque ffmpeg structure for image capture.
bool close() override
Close the DeviceDriver.
Interface implemented by all device drivers.
Read a YARP-format sound block from a device.
Read a YARP-format image and sound from a device.
A base class for nested structures that can be searched.
Definition Searchable.h:31
Typed image class.
Definition Image.h:605
Class for storing sounds See Audio in YARP for additional documentation on YARP audio.
Definition Sound.h:25