YARP
Yet Another Robot Platform
FfmpegWriter.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 FfmpegWriter_INC
8#define FfmpegWriter_INC
9
10#include "avpreamble.h"
11
12extern "C" {
13#include <libavcodec/avcodec.h>
14#include <libavformat/avformat.h>
15}
16
17/*
18 * Uses ffmpeg to write images to movie files.
19 */
20
24
35{
36public:
37
39 fmt(nullptr),
40 oc(nullptr),
41 audio_st(nullptr),
42 video_st(nullptr),
43 audio_pts(0.0),
44 video_pts(0.0),
45 picture(nullptr),
46 tmp_picture(nullptr),
47 video_outbuf(nullptr),
48 frame_count(0),
49 video_outbuf_size(0),
50 ready(false),
51 delayed(false)
52 {
53 system_resource = NULL;
54 }
55
56 bool open(yarp::os::Searchable & config) override;
57
58 bool close() override;
59
61
63 yarp::sig::Sound& sound) override;
64
65
66 bool hasAudio() override { return true; }
67
68 bool hasVideo() override { return true; }
69
70private:
71 void *system_resource;
72
73 AVOutputFormat *fmt;
74 AVFormatContext *oc;
75 AVStream *audio_st, *video_st;
76 double audio_pts, video_pts;
77 std::string filename;
78 yarp::os::Property savedConfig;
79 AVFrame *picture, *tmp_picture;
80 uint8_t *video_outbuf;
81 int frame_count, video_outbuf_size;
82 bool ready;
83 bool delayed;
84
85 virtual bool delayedOpen(yarp::os::Searchable & config);
86
87 bool isOk() {
88 if (delayed) {
89 delayed = false;
90 ready = delayedOpen(savedConfig);
91 if (delayed) { ready = false; }
92 }
93 return ready;
94 }
95
96 void open_video(AVFormatContext *oc, AVStream *st);
97
98 void write_video_frame(AVFormatContext *oc, AVStream *st,
100
101 void close_video(AVFormatContext *oc, AVStream *st);
102};
103
104#endif
ffmpeg_writer: Uses ffmpeg to write images/sounds to movie files (AVI, MOV, ...).
Definition: FfmpegWriter.h:35
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
bool hasAudio() override
Definition: FfmpegWriter.h:66
bool putImage(yarp::sig::ImageOf< yarp::sig::PixelRgb > &image) override
Write an image to the device.
bool close() override
Close the DeviceDriver.
bool hasVideo() override
Definition: FfmpegWriter.h:68
virtual bool putAudioVisual(yarp::sig::ImageOf< yarp::sig::PixelRgb > &image, yarp::sig::Sound &sound) override
Write an image and sound.
Interface implemented by all device drivers.
Definition: DeviceDriver.h:30
Write a YARP-format image and sound to a device.
Read a YARP-format image to a device.
A class for storing options and configuration information.
Definition: Property.h:33
A base class for nested structures that can be searched.
Definition: Searchable.h:63
Class for storing sounds See Audio in YARP for additional documentation on YARP audio.
Definition: Sound.h:25