From patchwork Sun Mar 19 23:16:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Hunstock X-Patchwork-Id: 3022 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.50.79 with SMTP id y76csp1166537vsy; Sun, 19 Mar 2017 16:16:56 -0700 (PDT) X-Received: by 10.28.217.142 with SMTP id q136mr7595880wmg.48.1489965416820; Sun, 19 Mar 2017 16:16:56 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id s18si487469wrs.313.2017.03.19.16.16.56; Sun, 19 Mar 2017 16:16:56 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9E2546882ED; Mon, 20 Mar 2017 01:16:27 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.annaberg6.de (mail.annaberg6.de [89.238.64.82]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 024B76882ED for ; Mon, 20 Mar 2017 01:16:20 +0200 (EET) Received: (qmail 22281 invoked from network); 19 Mar 2017 23:16:38 -0000 Received: from build.erfurt.vpn.annaberg6.de (10.0.8.11) by mail.annaberg6.de with ESMTPS (AES128-SHA encrypted); 19 Mar 2017 23:16:38 -0000 From: Matthias Hunstock To: ffmpeg-devel@ffmpeg.org Date: Mon, 20 Mar 2017 00:16:37 +0100 Message-Id: <1489965397-19419-2-git-send-email-atze@fem.tu-ilmenau.de> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1489965397-19419-1-git-send-email-atze@fem.tu-ilmenau.de> References: <1489673161-18533-1-git-send-email-atze@fem.tu-ilmenau.de> <1489965397-19419-1-git-send-email-atze@fem.tu-ilmenau.de> Subject: [FFmpeg-devel] [PATCH 2/2 v3] decklink: new option 'format_code' to set video format by fourCC X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Matthias Hunstock --- doc/indevs.texi | 14 ++++++++++---- libavdevice/decklink_common.cpp | 17 +++++++++++++---- libavdevice/decklink_common_c.h | 1 + libavdevice/decklink_dec.cpp | 5 +++-- libavdevice/decklink_dec_c.c | 1 + 5 files changed, 28 insertions(+), 10 deletions(-) diff --git a/doc/indevs.texi b/doc/indevs.texi index 27cc3d5..a4c99a9 100644 --- a/doc/indevs.texi +++ b/doc/indevs.texi @@ -233,6 +233,12 @@ Defaults to @option{false}. If set to @option{true}, print a list of supported formats and exit. Defaults to @option{false}. +@item format_code +This sets the input video format to the format given by the FourCC. To see +the supported values of your device(s) use @option{list_formats}. +Note that there is a fourCC @option{'pal '} that can also be used +as @option{pal} (3 letters). + @item bm_v210 If set to @samp{1}, video is captured in 10 bit v210 instead of uyvy422. Not all Blackmagic devices support this option. @@ -296,21 +302,21 @@ ffmpeg -f decklink -list_formats 1 -i 'Intensity Pro' @end example @item -Capture video clip at 1080i50 (format 11): +Capture video clip at 1080i50: @example -ffmpeg -f decklink -i 'Intensity Pro@@11' -acodec copy -vcodec copy output.avi +ffmpeg -format_code Hi50 -f decklink -i 'Intensity Pro' -acodec copy -vcodec copy output.avi @end example @item Capture video clip at 1080i50 10 bit: @example -ffmpeg -bm_v210 1 -f decklink -i 'UltraStudio Mini Recorder@@11' -acodec copy -vcodec copy output.avi +ffmpeg -bm_v210 1 -format_code Hi50 -f decklink -i 'UltraStudio Mini Recorder' -acodec copy -vcodec copy output.avi @end example @item Capture video clip at 1080i50 with 16 audio channels: @example -ffmpeg -channels 16 -f decklink -i 'UltraStudio Mini Recorder@@11' -acodec copy -vcodec copy output.avi +ffmpeg -channels 16 -format_code Hi50 -f decklink -i 'UltraStudio Mini Recorder' -acodec copy -vcodec copy output.avi @end example @end itemize diff --git a/libavdevice/decklink_common.cpp b/libavdevice/decklink_common.cpp index 26c0776..9e862ca 100644 --- a/libavdevice/decklink_common.cpp +++ b/libavdevice/decklink_common.cpp @@ -33,6 +33,7 @@ extern "C" { #include "libavformat/avformat.h" #include "libavformat/internal.h" #include "libavutil/imgutils.h" +#include "libavutil/intreadwrite.h" #include "libavutil/bswap.h" } @@ -158,8 +159,8 @@ int ff_decklink_set_format(AVFormatContext *avctx, int i = 1; HRESULT res; - av_log(avctx, AV_LOG_DEBUG, "Trying to find mode for frame size %dx%d, frame timing %d/%d, field order %d, direction %d, mode number %d\n", - width, height, tb_num, tb_den, field_order, direction, num); + av_log(avctx, AV_LOG_DEBUG, "Trying to find mode for frame size %dx%d, frame timing %d/%d, field order %d, direction %d, mode number %d, format code %s\n", + width, height, tb_num, tb_den, field_order, direction, num, (cctx->format_code) ? cctx->format_code : "(unset)"); if (ctx->duplex_mode) { DECKLINK_BOOL duplex_supported = false; @@ -196,12 +197,18 @@ int ff_decklink_set_format(AVFormatContext *avctx, return AVERROR(EIO); } + BMDDisplayMode target_mode = 0; + char format_buf[] = " "; + if (cctx->format_code) + memcpy(format_buf, cctx->format_code, FFMIN(strlen(cctx->format_code), sizeof(format_buf))); + target_mode = AV_RB32(format_buf); AVRational target_tb = av_make_q(tb_num, tb_den); ctx->bmd_mode = bmdModeUnknown; while ((ctx->bmd_mode == bmdModeUnknown) && itermode->Next(&mode) == S_OK) { BMDTimeValue bmd_tb_num, bmd_tb_den; int bmd_width = mode->GetWidth(); int bmd_height = mode->GetHeight(); + BMDDisplayMode bmd_mode = mode->GetDisplayMode(); BMDFieldDominance bmd_field_dominance = mode->GetFieldDominance(); mode->GetFrameRate(&bmd_tb_num, &bmd_tb_den); @@ -210,8 +217,10 @@ int ff_decklink_set_format(AVFormatContext *avctx, if ((bmd_width == width && bmd_height == height && !av_cmp_q(mode_tb, target_tb) && - field_order_eq(field_order, bmd_field_dominance)) || i == num) { - ctx->bmd_mode = mode->GetDisplayMode(); + field_order_eq(field_order, bmd_field_dominance)) + || i == num + || target_mode == bmd_mode) { + ctx->bmd_mode = bmd_mode; ctx->bmd_width = bmd_width; ctx->bmd_height = bmd_height; ctx->bmd_tb_den = bmd_tb_den; diff --git a/libavdevice/decklink_common_c.h b/libavdevice/decklink_common_c.h index d565631..72c5f9a 100644 --- a/libavdevice/decklink_common_c.h +++ b/libavdevice/decklink_common_c.h @@ -47,6 +47,7 @@ struct decklink_cctx { int audio_input; int video_input; int draw_bars; + char *format_code; }; #endif /* AVDEVICE_DECKLINK_COMMON_C_H */ diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp index 7df841b..ffe65db 100644 --- a/libavdevice/decklink_dec.cpp +++ b/libavdevice/decklink_dec.cpp @@ -539,9 +539,10 @@ av_cold int ff_decklink_read_header(AVFormatContext *avctx) goto error; } - if (mode_num > 0) { + 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 %d for %s\n", mode_num, fname); + 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); ret = AVERROR(EIO); goto error; } diff --git a/libavdevice/decklink_dec_c.c b/libavdevice/decklink_dec_c.c index 31818d2..d4ae4e5 100644 --- a/libavdevice/decklink_dec_c.c +++ b/libavdevice/decklink_dec_c.c @@ -31,6 +31,7 @@ static const AVOption options[] = { { "list_devices", "list available devices" , OFFSET(list_devices), AV_OPT_TYPE_INT , { .i64 = 0 }, 0, 1, DEC }, { "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}, 3, 4, DEC }, { "bm_v210", "v210 10 bit per channel" , OFFSET(v210), AV_OPT_TYPE_INT , { .i64 = 0 }, 0, 1, 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"},