YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
ffmpeg_api.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include "ffmpeg_api.h"
8
9
10int stable_img_convert (AVPicture *dst, int dst_pix_fmt,
11 const AVPicture *src, int src_pix_fmt,
12 int src_width, int src_height) {
13 static struct SwsContext *img_convert_ctx = nullptr;
14 if (img_convert_ctx==nullptr) {
15 //printf("Looking for a context\n");
16 img_convert_ctx = sws_getContext(src_width, src_height,
17 (AVPixelFormat)src_pix_fmt,
18 src_width, src_height,
19 (AVPixelFormat)dst_pix_fmt,
20 SWS_BILINEAR,
21 nullptr, nullptr, nullptr);
22
23 //printf("Done looking for a context\n");
24 }
25 if (img_convert_ctx!=nullptr) {
26 /*
27 printf("software scale: %ld %ld/%ld %d/%d %d\n",
28 (long int)img_convert_ctx,
29 (long int)(((AVPicture*)src)->data),
30 (long int)(((AVPicture*)dst)->data),
31 ((AVPicture*)src)->linesize[0],
32 ((AVPicture*)dst)->linesize[0],
33 src_height);
34 */
35
36 sws_scale(img_convert_ctx, ((AVPicture*)src)->data,
37 ((AVPicture*)src)->linesize, 0, src_height,
38 ((AVPicture*)dst)->data, ((AVPicture*)dst)->linesize);
39 //printf("software scale done\n");
40 } else {
41 fprintf(stderr,"image conversion failed\n");
42 return -1;
43 }
44 return 0;
45}
int stable_img_convert(AVPicture *dst, int dst_pix_fmt, const AVPicture *src, int src_pix_fmt, int src_width, int src_height)