YARP
Yet Another Robot Platform
ffmpeg_api.cpp
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 #include "ffmpeg_api.h"
11 
12 
13 int stable_img_convert (AVPicture *dst, int dst_pix_fmt,
14  const AVPicture *src, int src_pix_fmt,
15  int src_width, int src_height) {
16  static struct SwsContext *img_convert_ctx = nullptr;
17  if (img_convert_ctx==nullptr) {
18  //printf("Looking for a context\n");
19  img_convert_ctx = sws_getContext(src_width, src_height,
20  (AVPixelFormat)src_pix_fmt,
21  src_width, src_height,
22  (AVPixelFormat)dst_pix_fmt,
23  SWS_BILINEAR,
24  nullptr, nullptr, nullptr);
25 
26  //printf("Done looking for a context\n");
27  }
28  if (img_convert_ctx!=nullptr) {
29  /*
30  printf("software scale: %ld %ld/%ld %d/%d %d\n",
31  (long int)img_convert_ctx,
32  (long int)(((AVPicture*)src)->data),
33  (long int)(((AVPicture*)dst)->data),
34  ((AVPicture*)src)->linesize[0],
35  ((AVPicture*)dst)->linesize[0],
36  src_height);
37  */
38 
39  sws_scale(img_convert_ctx, ((AVPicture*)src)->data,
40  ((AVPicture*)src)->linesize, 0, src_height,
41  ((AVPicture*)dst)->data, ((AVPicture*)dst)->linesize);
42  //printf("software scale done\n");
43  } else {
44  fprintf(stderr,"image conversion failed\n");
45  return -1;
46  }
47  return 0;
48 }
ffmpeg_api.h
stable_img_convert
int stable_img_convert(AVPicture *dst, int dst_pix_fmt, const AVPicture *src, int src_pix_fmt, int src_width, int src_height)
Definition: ffmpeg_api.cpp:13