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 
33 class FfmpegWriter :
38 {
39 public:
40 
42  fmt(nullptr),
43  oc(nullptr),
44  audio_st(nullptr),
45  video_st(nullptr),
46  audio_pts(0.0),
47  video_pts(0.0),
48  picture(nullptr),
49  tmp_picture(nullptr),
50  video_outbuf(nullptr),
51  frame_count(0),
52  video_outbuf_size(0),
53  ready(false),
54  delayed(false)
55  {
56  system_resource = NULL;
57  }
58 
59  bool open(yarp::os::Searchable & config) override;
60 
61  bool close() override;
62 
64 
66  yarp::sig::Sound& sound) override;
67 
68 
69  bool hasAudio() override { return true; }
70 
71  bool hasVideo() override { return true; }
72 
73 private:
74  void *system_resource;
75 
76  AVOutputFormat *fmt;
77  AVFormatContext *oc;
78  AVStream *audio_st, *video_st;
79  double audio_pts, video_pts;
80  std::string filename;
81  yarp::os::Property savedConfig;
82  AVFrame *picture, *tmp_picture;
83  uint8_t *video_outbuf;
84  int frame_count, video_outbuf_size;
85  bool ready;
86  bool delayed;
87 
88  virtual bool delayedOpen(yarp::os::Searchable & config);
89 
90  bool isOk() {
91  if (delayed) {
92  delayed = false;
93  ready = delayedOpen(savedConfig);
94  if (delayed) { ready = false; }
95  }
96  return ready;
97  }
98 
99  void open_video(AVFormatContext *oc, AVStream *st);
100 
101  void write_video_frame(AVFormatContext *oc, AVStream *st,
103 
104  void close_video(AVFormatContext *oc, AVStream *st);
105 };
106 
107 #endif
yarp::os::Searchable
A base class for nested structures that can be searched.
Definition: Searchable.h:69
FfmpegWriter::putAudioVisual
virtual bool putAudioVisual(yarp::sig::ImageOf< yarp::sig::PixelRgb > &image, yarp::sig::Sound &sound) override
Write an image and sound.
Definition: FfmpegWriter.cpp:735
yarp::dev::DeviceDriver
Interface implemented by all device drivers.
Definition: DeviceDriver.h:38
yarp::sig::ImageOf< yarp::sig::PixelRgb >
yarp::dev::IFrameWriterImage
Read a YARP-format image to a device.
Definition: FrameGrabberInterfaces.h:343
AudioVisualInterfaces.h
FfmpegWriter::hasAudio
bool hasAudio() override
Definition: FfmpegWriter.h:69
FfmpegWriter::hasVideo
bool hasVideo() override
Definition: FfmpegWriter.h:71
yarp::dev::IFrameWriterAudioVisual
Write a YARP-format image and sound to a device.
Definition: IFrameWriterAudioVisual.h:27
yarp::dev::IAudioVisualStream
Definition: IAudioVisualStream.h:27
FfmpegWriter::close
bool close() override
Close the DeviceDriver.
Definition: FfmpegWriter.cpp:671
avpreamble.h
yarp::sig::Sound
Class for storing sounds.
Definition: Sound.h:28
FfmpegWriter::putImage
bool putImage(yarp::sig::ImageOf< yarp::sig::PixelRgb > &image) override
Write an image to the device.
Definition: FfmpegWriter.cpp:702
FfmpegWriter
ffmpeg_writer: Uses ffmpeg to write images/sounds to movie files (AVI, MOV, ...).
Definition: FfmpegWriter.h:38
FfmpegWriter::open
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
Definition: FfmpegWriter.cpp:554
yarp::os::Property
A class for storing options and configuration information.
Definition: Property.h:37
FfmpegWriter::FfmpegWriter
FfmpegWriter()
Definition: FfmpegWriter.h:41
DeviceDriver.h