51#define M_PI 3.1415926535897931
54#define STREAM_FRAME_RATE 25
55#define STREAM_PIX_FMT AV_PIX_FMT_YUV420P
56#define STREAM_PIX_WORK AV_PIX_FMT_RGB24
101 c->sample_rate = 44100;
129 tincr2 = 2 *
M_PI * 110.0 /
c->sample_rate /
c->sample_rate;
136 if (
c->frame_size <= 1) {
138 switch(
st->codec->codec_id) {
158 "FRAME SIZE is %d / samples size is %d\n",
187 frame->nb_samples =
c->frame_size;
188 frame->format =
c->sample_fmt;
189 frame->channel_layout =
c->channel_layout;
199 "Could not allocate %d bytes for samples buffer",
229 if (
tmp.side_data_elems > 0) {
230 for (
int i = 0;
i <
tmp.side_data_elems;
i++) {
234 tmp.side_data_elems = 0;
241 pkt.stream_index=
st->index;
267 for (
int i=0;
i<avail;
i++) {
291 if (
tmp.side_data_elems > 0) {
292 for (
int i = 0;
i <
tmp.side_data_elems;
i++) {
296 tmp.side_data_elems = 0;
309 pkt.stream_index=
st->index;
353 c->bit_rate = 400000;
362 c->time_base.num = 1;
376 if (!
strcmp(oc->oformat->name,
"mp4") || !
strcmp(oc->oformat->name,
"mov") || !
strcmp(oc->oformat->name,
"3gp")) {
424 video_outbuf =
nullptr;
431 video_outbuf_size = 200000;
443 tmp_picture =
nullptr;
457 for(y=0;y<height;y++) {
458 for(x=0;x<width;x++) {
459 int base = y*(width*3);
460 pict->data[0][base + x*3] = img.safePixel(x,y).r;
461 pict->data[0][base +x*3+1] = img.safePixel(x,y).g;
462 pict->data[0][base +x*3+2] = img.safePixel(x,y).b;
480 c->width,
c->height);
489 tmp.data = video_outbuf;
490 tmp.size = video_outbuf_size;
492 if (
tmp.side_data_elems > 0) {
493 for (
int i = 0;
i <
tmp.side_data_elems;
i++) {
497 tmp.side_data_elems = 0;
505 if (
c->coded_frame->key_frame) {
508 pkt.stream_index=
st->index;
509 pkt.data= video_outbuf;
557 "ffmpeg libavcodec version number %d.%d.%d",
566 return delayedOpen(config);
574 "width of image (must be even)").asInt32();
576 "height of image (must be even)").asInt32();
578 "baseline images per second").asInt32();
582 bool audio = config.
check(
"audio",
"should audio be included");
585 "audio samples per second").asInt32();
587 "audio samples per second").asInt32();
590 filename = config.
check(
"out",
Value(
"movie.avi"),
591 "name of movie to write").asString();
607 yCInfo(
FFMPEGWRITER,
"Could not deduce output format from file extension: using MPEG.");
620 snprintf(oc->filename,
sizeof(oc->filename),
"%s", filename.c_str());
634 if (audio_st!=
nullptr) {
637 c->channels = channels;
653 open_video(oc, video_st);
673 if (!isOk()) {
return false; }
677 close_video(oc, video_st);
687 for(
unsigned int i = 0;
i < oc->nb_streams;
i++) {
710 if (!isOk()) {
return false; }
725 if (!(audio_st || video_st)) {
730 if (!video_st || (video_st && audio_st && audio_pts < video_pts)) {
733 write_video_frame(oc, video_st, image);
750 if (!isOk()) {
return false; }
753 write_video_frame(oc, video_st, image);
static AVStream * add_video_stream(AVFormatContext *oc, AVCodecID codec_id, int w, int h, int framerate)
static AVFrame * alloc_picture(int pix_fmt, int width, int height)
static AVStream * add_audio_stream(AVFormatContext *oc, AVCodecID codec_id)
static void write_audio_frame(AVFormatContext *oc, AVStream *st)
static void close_audio(AVFormatContext *oc, AVStream *st)
static void get_audio_frame(int16_t *samples, int frame_size, int nb_channels)
static void make_audio_frame(AVCodecContext *c, AVFrame *&frame, void *&samples)
int audio_input_frame_size
static void fill_rgb_image(AVFrame *pict, int frame_index, int width, int height, ImageOf< PixelRgb > &img)
static void open_audio(AVFormatContext *oc, AVStream *st)
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
bool putImage(yarp::sig::ImageOf< yarp::sig::PixelRgb > &image) override
Write an image to the device.
bool close() override
Close the DeviceDriver.
virtual bool putAudioVisual(yarp::sig::ImageOf< yarp::sig::PixelRgb > &image, yarp::sig::Sound &sound) override
Write an image and sound.
A mini-server for performing network communication in the background.
void fromString(const std::string &txt, bool wipe=true)
Interprets a string as a list of properties.
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
A base class for nested structures that can be searched.
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual std::string toString() const =0
Return a standard text representation of the content of the object.
A single value (typically within a Bottle).
size_t width() const
Gets width of image in pixels.
size_t height() const
Gets height of image in pixels.
Class for storing sounds See Audio in YARP for additional documentation on YARP audio.
size_t getChannels() const
Get the number of channels of the sound.
int getFrequency() const
Get the frequency of the sound (i.e.
audio_sample get(size_t sample, size_t channel=0) const
size_t getSamples() const
Get the number of samples contained in the sound.
int stable_img_convert(AVPicture *dst, int dst_pix_fmt, const AVPicture *src, int src_pix_fmt, int src_width, int src_height)
#define yCInfo(component,...)
#define yCError(component,...)
#define yCTrace(component,...)
#define yCWarning(component,...)
#define YARP_LOG_COMPONENT(name,...)
#define yCFatal(component,...)
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.
constexpr char framerate[]