YARP
Yet Another Robot Platform
FfmpegWriter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2018 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 
25 namespace yarp {
26  namespace dev {
27  class FfmpegWriter;
28  }
29 }
30 
32 #include <yarp/dev/DeviceDriver.h>
33 
42  public DeviceDriver,
43  public IAudioVisualStream
44 {
45 public:
46 
48  fmt(nullptr),
49  oc(nullptr),
50  audio_st(nullptr),
51  video_st(nullptr),
52  audio_pts(0.0),
53  video_pts(0.0),
54  picture(nullptr),
55  tmp_picture(nullptr),
56  video_outbuf(nullptr),
57  frame_count(0),
59  ready(false),
60  delayed(false)
61  {
62  system_resource = NULL;
63  }
64 
65  virtual bool open(yarp::os::Searchable & config) override;
66 
67  virtual bool close() override;
68 
69  virtual bool putImage(yarp::sig::ImageOf<yarp::sig::PixelRgb> & image) override;
70 
72  yarp::sig::Sound& sound) override;
73 
74 
75  virtual bool hasAudio() override { return true; }
76 
77  virtual bool hasVideo() override { return true; }
78 
79 private:
81 
82  AVOutputFormat *fmt;
83  AVFormatContext *oc;
84  AVStream *audio_st, *video_st;
86  std::string filename;
88  AVFrame *picture, *tmp_picture;
89  uint8_t *video_outbuf;
91  bool ready;
92  bool delayed;
93 
94  virtual bool delayedOpen(yarp::os::Searchable & config);
95 
96  bool isOk() {
97  if (delayed) {
98  delayed = false;
99  ready = delayedOpen(savedConfig);
100  if (delayed) { ready = false; }
101  }
102  return ready;
103  }
104 
105  void open_video(AVFormatContext *oc, AVStream *st);
106 
107  void write_video_frame(AVFormatContext *oc, AVStream *st,
109 
110  void close_video(AVFormatContext *oc, AVStream *st);
111 };
112 
113 
123 #endif
void write_video_frame(AVFormatContext *oc, AVStream *st, yarp::sig::ImageOf< yarp::sig::PixelRgb > &img)
AVFormatContext * oc
Definition: FfmpegWriter.h:83
virtual bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
Interface implemented by all device drivers.
Definition: DeviceDriver.h:37
virtual bool putImage(yarp::sig::ImageOf< yarp::sig::PixelRgb > &image) override
Write an image to the device.
Write a YARP-format image and sound to a device.
virtual bool hasAudio() override
Definition: FfmpegWriter.h:75
virtual bool delayedOpen(yarp::os::Searchable &config)
yarp::os::Property savedConfig
Definition: FfmpegWriter.h:87
A class for storing options and configuration information.
Definition: Property.h:34
A base class for nested structures that can be searched.
Definition: Searchable.h:66
Class for storing sounds.
Definition: Sound.h:28
The main, catch-all namespace for YARP.
Definition: numeric.h:47
void open_video(AVFormatContext *oc, AVStream *st)
Uses ffmpeg to write images/sounds to movie files (AVI, MOV, ...).
Definition: FfmpegWriter.h:40
virtual bool putAudioVisual(yarp::sig::ImageOf< yarp::sig::PixelRgb > &image, yarp::sig::Sound &sound) override
Write an image and sound.
virtual bool close() override
Close the DeviceDriver.
For streams capable of holding different kinds of content, check what they actually have...
AVOutputFormat * fmt
Definition: FfmpegWriter.h:82
void close_video(AVFormatContext *oc, AVStream *st)
Read a YARP-format image to a device.
virtual bool hasVideo() override
Definition: FfmpegWriter.h:77