2014-04-04 23:21:19 -07:00
|
|
|
#pragma once
|
|
|
|
|
2021-11-06 15:57:35 -07:00
|
|
|
#include <libavcodec/avcodec.h>
|
|
|
|
|
2014-04-05 01:13:11 -07:00
|
|
|
static inline int64_t rescale_ts(int64_t val, AVCodecContext *context,
|
2019-06-22 22:13:45 -07:00
|
|
|
AVRational new_base)
|
2014-04-05 01:13:11 -07:00
|
|
|
{
|
|
|
|
return av_rescale_q_rnd(val, context->time_base, new_base,
|
2019-06-22 22:13:45 -07:00
|
|
|
AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX);
|
2014-04-05 01:13:11 -07:00
|
|
|
}
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
static inline enum AVPixelFormat
|
|
|
|
obs_to_ffmpeg_video_format(enum video_format format)
|
2014-04-04 23:21:19 -07:00
|
|
|
{
|
|
|
|
switch (format) {
|
2019-06-22 22:13:45 -07:00
|
|
|
case VIDEO_FORMAT_I444:
|
|
|
|
return AV_PIX_FMT_YUV444P;
|
2022-04-19 10:38:28 -07:00
|
|
|
case VIDEO_FORMAT_I412:
|
|
|
|
return AV_PIX_FMT_YUV444P12LE;
|
2019-06-22 22:13:45 -07:00
|
|
|
case VIDEO_FORMAT_I420:
|
|
|
|
return AV_PIX_FMT_YUV420P;
|
|
|
|
case VIDEO_FORMAT_NV12:
|
|
|
|
return AV_PIX_FMT_NV12;
|
|
|
|
case VIDEO_FORMAT_YUY2:
|
|
|
|
return AV_PIX_FMT_YUYV422;
|
|
|
|
case VIDEO_FORMAT_UYVY:
|
|
|
|
return AV_PIX_FMT_UYVY422;
|
2022-04-19 10:39:22 -07:00
|
|
|
case VIDEO_FORMAT_YVYU:
|
|
|
|
return AV_PIX_FMT_YVYU422;
|
2019-06-22 22:13:45 -07:00
|
|
|
case VIDEO_FORMAT_RGBA:
|
|
|
|
return AV_PIX_FMT_RGBA;
|
|
|
|
case VIDEO_FORMAT_BGRA:
|
|
|
|
return AV_PIX_FMT_BGRA;
|
|
|
|
case VIDEO_FORMAT_BGRX:
|
|
|
|
return AV_PIX_FMT_BGRA;
|
|
|
|
case VIDEO_FORMAT_Y800:
|
|
|
|
return AV_PIX_FMT_GRAY8;
|
|
|
|
case VIDEO_FORMAT_BGR3:
|
|
|
|
return AV_PIX_FMT_BGR24;
|
2019-06-17 22:25:18 -07:00
|
|
|
case VIDEO_FORMAT_I422:
|
|
|
|
return AV_PIX_FMT_YUV422P;
|
2022-04-19 10:38:28 -07:00
|
|
|
case VIDEO_FORMAT_I210:
|
|
|
|
return AV_PIX_FMT_YUV422P10LE;
|
2019-08-11 11:26:32 -07:00
|
|
|
case VIDEO_FORMAT_I40A:
|
|
|
|
return AV_PIX_FMT_YUVA420P;
|
|
|
|
case VIDEO_FORMAT_I42A:
|
|
|
|
return AV_PIX_FMT_YUVA422P;
|
|
|
|
case VIDEO_FORMAT_YUVA:
|
|
|
|
return AV_PIX_FMT_YUVA444P;
|
2022-04-19 10:38:28 -07:00
|
|
|
case VIDEO_FORMAT_YA2L:
|
|
|
|
#if LIBAVUTIL_BUILD >= AV_VERSION_INT(56, 31, 100)
|
|
|
|
return AV_PIX_FMT_YUVA444P12LE;
|
|
|
|
#else
|
|
|
|
return AV_PIX_FMT_NONE;
|
|
|
|
#endif
|
2022-03-16 01:32:03 -07:00
|
|
|
case VIDEO_FORMAT_I010:
|
|
|
|
return AV_PIX_FMT_YUV420P10LE;
|
|
|
|
case VIDEO_FORMAT_P010:
|
|
|
|
return AV_PIX_FMT_P010LE;
|
2019-08-30 22:13:11 -07:00
|
|
|
case VIDEO_FORMAT_NONE:
|
|
|
|
case VIDEO_FORMAT_AYUV:
|
|
|
|
/* not supported by FFmpeg */
|
|
|
|
return AV_PIX_FMT_NONE;
|
2014-04-04 23:21:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return AV_PIX_FMT_NONE;
|
|
|
|
}
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
static inline enum audio_format
|
|
|
|
convert_ffmpeg_sample_format(enum AVSampleFormat format)
|
2014-04-04 23:21:19 -07:00
|
|
|
{
|
|
|
|
switch ((uint32_t)format) {
|
2019-06-22 22:13:45 -07:00
|
|
|
case AV_SAMPLE_FMT_U8:
|
|
|
|
return AUDIO_FORMAT_U8BIT;
|
|
|
|
case AV_SAMPLE_FMT_S16:
|
|
|
|
return AUDIO_FORMAT_16BIT;
|
|
|
|
case AV_SAMPLE_FMT_S32:
|
|
|
|
return AUDIO_FORMAT_32BIT;
|
|
|
|
case AV_SAMPLE_FMT_FLT:
|
|
|
|
return AUDIO_FORMAT_FLOAT;
|
|
|
|
case AV_SAMPLE_FMT_U8P:
|
|
|
|
return AUDIO_FORMAT_U8BIT_PLANAR;
|
|
|
|
case AV_SAMPLE_FMT_S16P:
|
|
|
|
return AUDIO_FORMAT_16BIT_PLANAR;
|
|
|
|
case AV_SAMPLE_FMT_S32P:
|
|
|
|
return AUDIO_FORMAT_32BIT_PLANAR;
|
|
|
|
case AV_SAMPLE_FMT_FLTP:
|
|
|
|
return AUDIO_FORMAT_FLOAT_PLANAR;
|
2014-04-04 23:21:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* shouldn't get here */
|
|
|
|
return AUDIO_FORMAT_16BIT;
|
|
|
|
}
|