[FFmpeg-devel] [PATCH] avdevice/decklink: new options 'list_pixelformats' and 'pixelformat_code' to allow pixelformat selection by code
Gildas Fargeas
fargeas.gildas at gmail.com
Mon Sep 4 12:47:30 EEST 2017
Thanks for the feedback. Here are the changes:
- renamed pixelformat_option in raw_format
- restored bm_v210 options (if set, it overrides the raw_format option)
- removed list_pixelformats and only mention supported raw codes in help.
- restore previous handling of output
Regarding the special handling of ARGB; the DeckLink API declares the ARGB enum with a value of 32 which cannot be casted to the string ARGB.
(refer to DeckLinkAPIModes.h:132 v10.9.5)
It is not ideal but that seemed to be an appropriate way to map the value. Let me know if you have something better in mind.
Signed-off-by: Gildas Fargeas <fargeas.gildas at gmail.com>
---
libavdevice/decklink_common.cpp | 17 ++++++++++++++++-
libavdevice/decklink_common.h | 1 +
libavdevice/decklink_common_c.h | 1 +
libavdevice/decklink_dec.cpp | 40 ++++++++++++++++++++++++++++++++--------
libavdevice/decklink_dec_c.c | 1 +
5 files changed, 51 insertions(+), 9 deletions(-)
diff --git a/libavdevice/decklink_common.cpp b/libavdevice/decklink_common.cpp
index cbb591ce64..d0a80c1897 100644
--- a/libavdevice/decklink_common.cpp
+++ b/libavdevice/decklink_common.cpp
@@ -203,6 +203,21 @@ int ff_decklink_set_format(AVFormatContext *avctx,
if (cctx->format_code)
memcpy(format_buf, cctx->format_code, FFMIN(strlen(cctx->format_code), sizeof(format_buf)));
BMDDisplayMode target_mode = (BMDDisplayMode)AV_RB32(format_buf);
+
+ char pixel_buf[] = " ";
+ ctx->bmd_pixel= bmdFormat8BitYUV;
+ if (!strcmp(cctx->raw_format, "ARGB")) {
+ /* DeckLink API value (32) for this one cannot be casted back into the string ARGB. */
+ ctx->bmd_pixel = bmdFormat8BitARGB;
+ } else {
+ memcpy(pixel_buf, cctx->raw_format, FFMIN(strlen(cctx->raw_format), sizeof(pixel_buf)));
+ ctx->bmd_pixel = (BMDPixelFormat)AV_RB32(pixel_buf);
+ }
+
+ if (cctx->v210) {
+ ctx->bmd_pixel = bmdFormat10BitYUV;
+ }
+
AVRational target_tb = av_make_q(tb_num, tb_den);
ctx->bmd_mode = bmdModeUnknown;
while ((ctx->bmd_mode == bmdModeUnknown) && itermode->Next(&mode) == S_OK) {
@@ -241,7 +256,7 @@ int ff_decklink_set_format(AVFormatContext *avctx,
if (ctx->bmd_mode == bmdModeUnknown)
return -1;
if (direction == DIRECTION_IN) {
- if (ctx->dli->DoesSupportVideoMode(ctx->bmd_mode, bmdFormat8BitYUV,
+ if (ctx->dli->DoesSupportVideoMode(ctx->bmd_mode, ctx->bmd_pixel,
bmdVideoOutputFlagDefault,
&support, NULL) != S_OK)
return -1;
diff --git a/libavdevice/decklink_common.h b/libavdevice/decklink_common.h
index 749eb0f8b8..770888a00b 100644
--- a/libavdevice/decklink_common.h
+++ b/libavdevice/decklink_common.h
@@ -56,6 +56,7 @@ struct decklink_ctx {
BMDTimeValue bmd_tb_den;
BMDTimeValue bmd_tb_num;
BMDDisplayMode bmd_mode;
+ BMDPixelFormat bmd_pixel;
BMDVideoConnection video_input;
BMDAudioConnection audio_input;
int bmd_width;
diff --git a/libavdevice/decklink_common_c.h b/libavdevice/decklink_common_c.h
index e263480474..a1eb225fbd 100644
--- a/libavdevice/decklink_common_c.h
+++ b/libavdevice/decklink_common_c.h
@@ -49,6 +49,7 @@ struct decklink_cctx {
int video_input;
int draw_bars;
char *format_code;
+ char *raw_format;
int64_t queue_size;
};
diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp
index c271ff3639..df12d41050 100644
--- a/libavdevice/decklink_dec.cpp
+++ b/libavdevice/decklink_dec.cpp
@@ -680,8 +680,8 @@ av_cold int ff_decklink_read_header(AVFormatContext *avctx)
if (mode_num > 0 || cctx->format_code) {
if (ff_decklink_set_format(avctx, DIRECTION_IN, mode_num) < 0) {
- av_log(avctx, AV_LOG_ERROR, "Could not set mode number %d or format code %s for %s\n",
- mode_num, (cctx->format_code) ? cctx->format_code : "(unset)", fname);
+ av_log(avctx, AV_LOG_ERROR, "Could not set mode number %d, format code %s or pixel format %s for %s\n",
+ mode_num, (cctx->format_code) ? cctx->format_code : "(unset)", cctx->raw_format, fname);
ret = AVERROR(EIO);
goto error;
}
@@ -723,15 +723,39 @@ av_cold int ff_decklink_read_header(AVFormatContext *avctx)
st->time_base.num = ctx->bmd_tb_num;
av_stream_set_r_frame_rate(st, av_make_q(st->time_base.den, st->time_base.num));
- if (cctx->v210) {
+ switch(ctx->bmd_pixel) {
+ case bmdFormat8BitYUV:
+ st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO;
+ st->codecpar->format = AV_PIX_FMT_UYVY422;
+ st->codecpar->bit_rate = av_rescale(ctx->bmd_width * ctx->bmd_height * 16, st->time_base.den, st->time_base.num);
+ break;
+ case bmdFormat10BitYUV:
st->codecpar->codec_id = AV_CODEC_ID_V210;
st->codecpar->codec_tag = MKTAG('V', '2', '1', '0');
+ st->codecpar->bits_per_coded_sample = 10;
st->codecpar->bit_rate = av_rescale(ctx->bmd_width * ctx->bmd_height * 64, st->time_base.den, st->time_base.num * 3);
- } else {
+
+ break;
+ case bmdFormat8BitARGB:
st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO;
- st->codecpar->format = AV_PIX_FMT_UYVY422;
- st->codecpar->codec_tag = MKTAG('U', 'Y', 'V', 'Y');
- st->codecpar->bit_rate = av_rescale(ctx->bmd_width * ctx->bmd_height * 16, st->time_base.den, st->time_base.num);
+ st->codecpar->codec_tag = avcodec_pix_fmt_to_codec_tag((enum AVPixelFormat)st->codecpar->format);
+ st->codecpar->format = AV_PIX_FMT_ARGB;
+ break;
+ case bmdFormat8BitBGRA:
+ st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO;
+ st->codecpar->codec_tag = avcodec_pix_fmt_to_codec_tag((enum AVPixelFormat)st->codecpar->format);
+ st->codecpar->format = AV_PIX_FMT_BGRA;
+ break;
+ case bmdFormat10BitRGB:
+ st->codecpar->codec_id = AV_CODEC_ID_R210;
+ st->codecpar->format = AV_PIX_FMT_RGB48LE;
+ st->codecpar->codec_tag = MKTAG('R', '2', '1', '0');
+ st->codecpar->bits_per_coded_sample = 10;
+ break;
+ default:
+ av_log(avctx, AV_LOG_ERROR, "Raw Format %s not supported\n", cctx->raw_format);
+ ret = AVERROR(EINVAL);
+ goto error;
}
switch (ctx->bmd_field_dominance) {
@@ -776,7 +800,7 @@ av_cold int ff_decklink_read_header(AVFormatContext *avctx)
}
result = ctx->dli->EnableVideoInput(ctx->bmd_mode,
- cctx->v210 ? bmdFormat10BitYUV : bmdFormat8BitYUV,
+ ctx->bmd_pixel,
bmdVideoInputFlagDefault);
if (result != S_OK) {
diff --git a/libavdevice/decklink_dec_c.c b/libavdevice/decklink_dec_c.c
index e2118a619c..881f52b4ae 100644
--- a/libavdevice/decklink_dec_c.c
+++ b/libavdevice/decklink_dec_c.c
@@ -34,6 +34,7 @@ static const AVOption options[] = {
{ "list_formats", "list supported formats" , OFFSET(list_formats), AV_OPT_TYPE_INT , { .i64 = 0 }, 0, 1, DEC },
{ "format_code", "set format by fourcc" , OFFSET(format_code), AV_OPT_TYPE_STRING, { .str = NULL}, 0, 0, DEC },
{ "bm_v210", "v210 10 bit per channel" , OFFSET(v210), AV_OPT_TYPE_INT , { .i64 = 0 }, 0, 1, DEC },
+ { "raw_format", "set raw_format (2vuy, v210, ARGB, BGRA, r210)" , OFFSET(raw_format), AV_OPT_TYPE_STRING, { .str = "2vuy"}, 0, 0, DEC },
{ "teletext_lines", "teletext lines bitmask", OFFSET(teletext_lines), AV_OPT_TYPE_INT64, { .i64 = 0 }, 0, 0x7ffffffffLL, DEC, "teletext_lines"},
{ "standard", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0x7fff9fffeLL}, 0, 0, DEC, "teletext_lines"},
{ "all", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0x7ffffffffLL}, 0, 0, DEC, "teletext_lines"},
--
2.11.0
More information about the ffmpeg-devel
mailing list