YARP  2.3.72
Yet Another Robot Platform
FfmpegWriter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006 RobotCub Consortium
3  * Authors: Paul Fitzpatrick
4  * CopyPolicy: Released under the terms of the LGPLv2.1 or later, see LGPL.TXT
5  *
6  */
7 
8 
9 #ifndef FfmpegWriter_INC
10 #define FfmpegWriter_INC
11 
12 #include "avpreamble.h"
13 
14 extern "C" {
15 #include <avcodec.h>
16 #include <avformat.h>
17 }
18 
19 /*
20  * Uses ffmpeg to write images to movie files.
21  *
22  */
23 
24 namespace yarp {
25  namespace dev {
26  class FfmpegWriter;
27  }
28 }
29 
31 #include <yarp/dev/DeviceDriver.h>
32 
41  public DeviceDriver,
42  public IAudioVisualStream
43 {
44 public:
45 
47  fmt(nullptr),
48  oc(nullptr),
49  audio_st(nullptr),
50  video_st(nullptr),
51  audio_pts(0.0),
52  video_pts(0.0),
53  picture(nullptr),
54  tmp_picture(nullptr),
55  video_outbuf(nullptr),
56  frame_count(0),
58  ready(false),
59  delayed(false)
60  {
61  system_resource = NULL;
62  }
63 
64  virtual bool open(yarp::os::Searchable & config) override;
65 
66  virtual bool close() override;
67 
69 
71  yarp::sig::Sound& sound) override;
72 
73 
74  virtual bool hasAudio() override { return true; }
75 
76  virtual bool hasVideo() override { return true; }
77 
78 private:
80 
81  AVOutputFormat *fmt;
82  AVFormatContext *oc;
83  AVStream *audio_st, *video_st;
87  AVFrame *picture, *tmp_picture;
88  uint8_t *video_outbuf;
90  bool ready;
91  bool delayed;
92 
93  virtual bool delayedOpen(yarp::os::Searchable & config);
94 
95  bool isOk() {
96  if (delayed) {
97  delayed = false;
98  ready = delayedOpen(savedConfig);
99  if (delayed) { ready = false; }
100  }
101  return ready;
102  }
103 
104  void open_video(AVFormatContext *oc, AVStream *st);
105 
106  void write_video_frame(AVFormatContext *oc, AVStream *st,
108 
109  void close_video(AVFormatContext *oc, AVStream *st);
110 };
111 
112 
122 #endif
void write_video_frame(AVFormatContext *oc, AVStream *st, yarp::sig::ImageOf< yarp::sig::PixelRgb > &img)
AVFormatContext * oc
Definition: FfmpegWriter.h:82
virtual bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
Interface implemented by all device drivers.
Definition: DeviceDriver.h:34
virtual bool putImage(yarp::sig::ImageOf< yarp::sig::PixelRgb > &image) override
Write an image to the device.
yarp::os::ConstString filename
Definition: FfmpegWriter.h:85
Write a YARP-format image and sound to a device.
virtual bool hasAudio() override
Definition: FfmpegWriter.h:74
virtual bool delayedOpen(yarp::os::Searchable &config)
delete image
Definition: IplImage.cpp:897
yarp::os::Property savedConfig
Definition: FfmpegWriter.h:86
A class for storing options and configuration information.
Definition: Property.h:32
A base class for nested structures that can be searched.
Definition: Searchable.h:56
Class for storing sounds.
Definition: Sound.h:25
The main, catch-all namespace for YARP.
A string with almost the same api as std::string.
Definition: ConstString.h:44
void open_video(AVFormatContext *oc, AVStream *st)
Uses ffmpeg to write images/sounds to movie files (AVI, MOV, ...).
Definition: FfmpegWriter.h:39
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:81
void close_video(AVFormatContext *oc, AVStream *st)
Read a YARP-format image to a device.
virtual bool hasVideo() override
Definition: FfmpegWriter.h:76