YARP
Yet Another Robot Platform
FfmpegWriter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * Copyright (C) 2006-2010 RobotCub Consortium
4  * All rights reserved.
5  *
6  * This software may be modified and distributed under the terms of the
7  * BSD-3-Clause license. See the accompanying LICENSE file for details.
8  */
9 
10 #ifndef FfmpegWriter_INC
11 #define FfmpegWriter_INC
12 
13 #include "avpreamble.h"
14 
15 extern "C" {
16 #include <libavcodec/avcodec.h>
17 #include <libavformat/avformat.h>
18 }
19 
20 /*
21  * Uses ffmpeg to write images to movie files.
22  */
23 
24 
26 #include <yarp/dev/DeviceDriver.h>
27 
34 class FfmpegWriter :
39 {
40 public:
41 
43  fmt(nullptr),
44  oc(nullptr),
45  audio_st(nullptr),
46  video_st(nullptr),
47  audio_pts(0.0),
48  video_pts(0.0),
49  picture(nullptr),
50  tmp_picture(nullptr),
51  video_outbuf(nullptr),
52  frame_count(0),
53  video_outbuf_size(0),
54  ready(false),
55  delayed(false)
56  {
57  system_resource = NULL;
58  }
59 
60  bool open(yarp::os::Searchable & config) override;
61 
62  bool close() override;
63 
65 
67  yarp::sig::Sound& sound) override;
68 
69 
70  bool hasAudio() override { return true; }
71 
72  bool hasVideo() override { return true; }
73 
74 private:
75  void *system_resource;
76 
77  AVOutputFormat *fmt;
78  AVFormatContext *oc;
79  AVStream *audio_st, *video_st;
80  double audio_pts, video_pts;
81  std::string filename;
82  yarp::os::Property savedConfig;
83  AVFrame *picture, *tmp_picture;
84  uint8_t *video_outbuf;
85  int frame_count, video_outbuf_size;
86  bool ready;
87  bool delayed;
88 
89  virtual bool delayedOpen(yarp::os::Searchable & config);
90 
91  bool isOk() {
92  if (delayed) {
93  delayed = false;
94  ready = delayedOpen(savedConfig);
95  if (delayed) { ready = false; }
96  }
97  return ready;
98  }
99 
100  void open_video(AVFormatContext *oc, AVStream *st);
101 
102  void write_video_frame(AVFormatContext *oc, AVStream *st,
104 
105  void close_video(AVFormatContext *oc, AVStream *st);
106 };
107 
108 
118 #endif
Uses ffmpeg to write images/sounds to movie files (AVI, MOV, ...).
Definition: FfmpegWriter.h:39
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
bool hasAudio() override
Definition: FfmpegWriter.h:70
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:72
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:38
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:37
A base class for nested structures that can be searched.
Definition: Searchable.h:69
Class for storing sounds.
Definition: Sound.h:28