uvgVPCCenc 1.2.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 (subject to the limitations in the disclaimer below) 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 Tampere University, 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 * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
26 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 * INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND ON
29 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 * INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
32 ****************************************************************************/
33
34#pragma once
35
37
38
39extern "C" {
40#include <libavcodec/avcodec.h>
41}
42
43#include "utils/types.hpp"
45
46#include <map>
47
48using namespace uvgvpcc_enc;
49
51public:
53 const ENCODER_TYPE& encoderType,
54 const std::string&codecName, // ex: "libx265"
55 const std::string& deviceType,
56 const std::string& codecOptions, // Set general options, ex: "preset=fast:crf=26"
57 const std::string& codecParams // Set codec specific params, ex: "x265-params=log-level=0:crf=26:qp=22"
58 ) : Abstract2DMapEncoder(encoderType), codecName_(codecName), deviceType_(deviceType) {
59 char delimiter = ':';
60 size_t start = 0;
61 size_t end = 0;
62
63 // Check if the general options, that are specified by the codec, are separated by colons (:)
64 if (codecOptions != "")
65 {
66 end = codecOptions.find(delimiter);
67 while (end != std::string::npos) {
68 std::string temp = codecOptions.substr(start, end - start);
69 size_t end_temp = temp.find('=');
70 std::string key = temp.substr(0, end_temp);
71 std::string value = temp.substr(end_temp+1, temp.length() - end_temp);
72 codecOptions_[key] = value;
73 start = end + 1;
74 end = codecOptions.find(delimiter, start);
75 }
76 std::string temp = codecOptions.substr(start);
77 size_t end_temp = temp.find('=', 0);
78 codecOptions_[temp.substr(0, end_temp)] = temp.substr(end_temp+1, temp.length() - end_temp);
79 }
80
81 if (codecParams == "")
82 {
83 codecParamsEnabler_ = "";
84 codecParamsValues_ = "";
85 return;
86 }
87
88 // Get the param enabler for the codec, ex: "x265-params" or "kvazaar-params"
89 start = 0;
90 delimiter = '=';
91 end = codecParams.find(delimiter);
92 codecParamsEnabler_ = codecParams.substr(start, end - start);
93
94 // Get the param values for the codec, ex: "log-level=0:crf=26:qp=22". Two possible separators: comma (,) or colon (:)
95 /*
96 Commas (,) separators are required by some specific codecs (e.g., libkvazaar); however, they conflict with the --uvgvpc setting
97 that uses commas(,) to separate global parameters.
98
99 Thus, to work around this issue, we use plus (+) as separators in the --uvgvpc setting and then convert them to commas (,).
100
101 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
102 */
103 if (codecParams.find('+', end+1) != std::string::npos)
104 {
105 delimiter = '+';
106 start = end + 1;
107 end = codecParams.find(delimiter, start);
108 std::string params_temp = "";
109 while (end != std::string::npos) {
110 params_temp += codecParams.substr(start, end - start)+ ",";
111 start = end + 1;
112 end = codecParams.find(delimiter, start);
113 }
114 params_temp += codecParams.substr(start, codecParams.length() - start);
115 //printf("params_temp: %s\n", params_temp.c_str());
116 codecParamsValues_ = params_temp;
117 } else { // Else the params are separated by colons (:) as other codecs
118 codecParamsValues_ = codecParams.substr(end+1, codecParams.length() - end);
119 }
120 };
121 static void initializeLogCallback();
122 void encodeGOFMaps(const std::shared_ptr<uvgvpcc_enc::GOF>& gof) override;
123
124private:
125 const std::string codecName_;
126 const std::string deviceType_;
127 std::string codecParamsEnabler_;
128 std::string codecParamsValues_;
129 std::map<std::string, std::string> codecOptions_;
130};
131
132
ENCODER_TYPE
Definition abstract2DMapEncoder.hpp:40
Definition abstract2DMapEncoder.hpp:43
Definition encoderFFmpeg.hpp:50
EncoderFFmpeg(const ENCODER_TYPE &encoderType, const std::string &codecName, const std::string &deviceType, const std::string &codecOptions, const std::string &codecParams)
Definition encoderFFmpeg.hpp:52
static void initializeLogCallback()
Definition encoderFFmpeg.cpp:86
void encodeGOFMaps(const std::shared_ptr< uvgvpcc_enc::GOF > &gof) override
Definition encoderFFmpeg.cpp:347
Definition uvgvpccenc.hpp:49