uvgVPCCenc 1.1.0
uvgVPCCenc is an open-source real-time V-PCC encoder library written in C++ from scratch.
Loading...
Searching...
No Matches
encoderFFmpeg.hpp
Go to the documentation of this file.
1/*****************************************************************************
2 * This file is part of uvgVPCCenc V-PCC encoder.
3 *
4 * Copyright (c) 2024-present, Tampere University, ITU/ISO/IEC, project contributors
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without modification,
8 * are permitted provided that the following conditions are met:
9 *
10 * * Redistributions of source code must retain the above copyright notice, this
11 * list of conditions and the following disclaimer.
12 *
13 * * Redistributions in binary form must reproduce the above copyright notice, this
14 * list of conditions and the following disclaimer in the documentation and/or
15 * other materials provided with the distribution.
16 *
17 * * Neither the name of the Tampere University or ITU/ISO/IEC nor the names of its
18 * contributors may be used to endorse or promote products derived from
19 * this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
25 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND ON
28 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 * INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
31 ****************************************************************************/
32
33#pragma once
34
36
37
38extern "C" {
39#include <libavcodec/avcodec.h>
40}
41
42#include "uvgvpcc/uvgvpcc.hpp"
44
45#include <map>
46
47using namespace uvgvpcc_enc;
48
50public:
52 const ENCODER_TYPE& encoderType,
53 const std::string&codecName, // ex: "libx265"
54 const std::string& deviceType,
55 const std::string& codecOptions, // Set general options, ex: "preset=fast:crf=26"
56 const std::string& codecParams // Set codec specific params, ex: "x265-params=log-level=0:crf=26:qp=22"
57 ) : Abstract2DMapEncoder(encoderType), codecName_(codecName), deviceType_(deviceType) {
58 char delimiter = ':';
59 size_t start = 0;
60 size_t end = 0;
61
62 // Check if the general options, that are specified by the codec, are separated by colons (:)
63 if (codecOptions != "")
64 {
65 end = codecOptions.find(delimiter);
66 while (end != std::string::npos) {
67 std::string temp = codecOptions.substr(start, end - start);
68 size_t end_temp = temp.find('=');
69 std::string key = temp.substr(0, end_temp);
70 std::string value = temp.substr(end_temp+1, temp.length() - end_temp);
71 codecOptions_[key] = value;
72 start = end + 1;
73 end = codecOptions.find(delimiter, start);
74 }
75 std::string temp = codecOptions.substr(start);
76 size_t end_temp = temp.find('=', 0);
77 codecOptions_[temp.substr(0, end_temp)] = temp.substr(end_temp+1, temp.length() - end_temp);
78 }
79
80 if (codecParams == "")
81 {
82 codecParamsEnabler_ = "";
83 codecParamsValues_ = "";
84 return;
85 }
86
87 // Get the param enabler for the codec, ex: "x265-params" or "kvazaar-params"
88 start = 0;
89 delimiter = '=';
90 end = codecParams.find(delimiter);
91 codecParamsEnabler_ = codecParams.substr(start, end - start);
92
93 // Get the param values for the codec, ex: "log-level=0:crf=26:qp=22". Two possible separators: comma (,) or colon (:)
94 /*
95 Commas (,) separators are required by some specific codecs (e.g., libkvazaar); however, they conflict with the --uvgvpc setting
96 that uses commas(,) to separate global parameters.
97
98 Thus, to work around this issue, we use plus (+) as separators in the --uvgvpc setting and then convert them to commas (,).
99
100 Example: preset=fast+threads=40+period=1+psnr=0+info=0+qp=22 --> preset=fast,threads=40,period=1,psnr=0,info=0,qp=22
101 */
102 if (codecParams.find('+', end+1) != std::string::npos)
103 {
104 delimiter = '+';
105 start = end + 1;
106 end = codecParams.find(delimiter, start);
107 std::string params_temp = "";
108 while (end != std::string::npos) {
109 params_temp += codecParams.substr(start, end - start)+ ",";
110 start = end + 1;
111 end = codecParams.find(delimiter, start);
112 }
113 params_temp += codecParams.substr(start, codecParams.length() - start);
114 //printf("params_temp: %s\n", params_temp.c_str());
115 codecParamsValues_ = params_temp;
116 } else { // Else the params are separated by colons (:) as other codecs
117 codecParamsValues_ = codecParams.substr(end+1, codecParams.length() - end);
118 }
119 };
120 static void initializeLogCallback();
121 void encodeGOFMaps(const std::shared_ptr<uvgvpcc_enc::GOF>& gof) override;
122
123private:
124 const std::string codecName_;
125 const std::string deviceType_;
126 std::string codecParamsEnabler_;
127 std::string codecParamsValues_;
128 std::map<std::string, std::string> codecOptions_;
129};
130
131
ENCODER_TYPE
Definition abstract2DMapEncoder.hpp:39
Definition abstract2DMapEncoder.hpp:42
Definition encoderFFmpeg.hpp:49
EncoderFFmpeg(const ENCODER_TYPE &encoderType, const std::string &codecName, const std::string &deviceType, const std::string &codecOptions, const std::string &codecParams)
Definition encoderFFmpeg.hpp:51
static void initializeLogCallback()
Definition encoderFFmpeg.cpp:86
void encodeGOFMaps(const std::shared_ptr< uvgvpcc_enc::GOF > &gof) override
Definition encoderFFmpeg.cpp:372
Definition log.hpp:48