Program Listing for File utils.hpp

↰ Return to documentation for file (include/ffmpeg_encoder_decoder/utils.hpp)

// -*-c++-*---------------------------------------------------------------------------------------
// Copyright 2024 Bernd Pfrommer <bernd.pfrommer@gmail.com>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef FFMPEG_ENCODER_DECODER__UTILS_HPP_
#define FFMPEG_ENCODER_DECODER__UTILS_HPP_

#include <map>
#include <opencv2/core.hpp>
#include <string>
#include <vector>

extern "C" {
#include <libavcodec/avcodec.h>
}

namespace ffmpeg_encoder_decoder
{
namespace utils
{
std::string pix(const AVPixelFormat & f);

std::string pix_long(AVPixelFormat const & f);

std::string err(int errnum);

void throw_err(const std::string & msg, int errnum);

void check_for_err(const std::string & msg, int errnum);

enum AVPixelFormat find_hw_config(
  bool * usesHWFrames, enum AVHWDeviceType hwDevType, const AVCodec * codec);

std::vector<enum AVPixelFormat> get_hwframe_transfer_formats(
  AVBufferRef * hwframe_ctx, enum AVHWFrameTransferDirection direction);

std::vector<enum AVPixelFormat> get_encoder_formats(
  const AVCodecContext * context, const AVCodec * avctx);

enum AVPixelFormat get_preferred_pixel_format(
  bool useHWFormat, const std::vector<AVPixelFormat> & fmts);

void find_decoders(
  const std::string & codec, std::vector<std::string> * hw_decoders,
  std::vector<std::string> * sw_decoders);

std::string find_decoders(const std::string & codec);
std::string filter_decoders(const std::string & codec, const std::string & decoders);

std::vector<std::string> get_hwdevice_types();

std::string find_codec(const std::string & encoder);

enum AVHWDeviceType find_hw_device_type(const AVCodec * codec);

enum AVPixelFormat ros_to_av_pix_format(const std::string & ros_pix_fmt);

std::vector<std::string> split_by_char(const std::string & str_list, const char sep);

bool encode_single_channel_as_color(const std::string & encoding, enum AVPixelFormat fmt);

std::vector<std::string> split_decoders(const std::string & decoder_list);

std::vector<std::string> split_encoding(const std::string & encoding);

}  // namespace utils
}  // namespace ffmpeg_encoder_decoder
#endif  // FFMPEG_ENCODER_DECODER__UTILS_HPP_