diff mbox

[FFmpeg-devel] lavd: rework interlacing setting on NewTek NDI output

Message ID 1bff8306-b28d-b7b9-22f0-4a5367412159@m1stereo.tv
State New
Headers show

Commit Message

Maksym Veremeyenko Sept. 4, 2017, 2:21 p.m. UTC
Hi,

move interlacing setting of NDI frame to packet sending function and 
take care on field order AV_FIELD_UNKNOWN - take a interlacing settings 
from avframe->interlaced_frame
diff mbox

Patch

diff --git a/libavdevice/libndi_newtek_enc.c b/libavdevice/libndi_newtek_enc.c
index be0b271..9a76450 100644
--- a/libavdevice/libndi_newtek_enc.c
+++ b/libavdevice/libndi_newtek_enc.c
@@ -158,6 +158,7 @@  static int ndi_write_video_packet(AVFormatContext *avctx, AVStream *st, AVPacket
 {
     struct NDIContext *ctx = avctx->priv_data;
     AVFrame *avframe, *tmp = (AVFrame *)pkt->data;
+    AVCodecParameters *c = st->codecpar;
 
     if (tmp->format != AV_PIX_FMT_UYVY422 && tmp->format != AV_PIX_FMT_BGRA &&
         tmp->format != AV_PIX_FMT_BGR0 && tmp->format != AV_PIX_FMT_RGBA &&
@@ -188,6 +189,15 @@  static int ndi_write_video_packet(AVFormatContext *avctx, AVStream *st, AVPacket
     ctx->video->line_stride_in_bytes = avframe->linesize[0];
     ctx->video->p_data = (void *)(avframe->data[0]);
 
+    if (c->field_order == AV_FIELD_UNKNOWN)
+        ctx->video->frame_format_type = tmp->interlaced_frame
+            ? NDIlib_frame_format_type_interleaved
+            : NDIlib_frame_format_type_progressive;
+    else
+        ctx->video->frame_format_type = c->field_order == AV_FIELD_PROGRESSIVE
+            ? NDIlib_frame_format_type_progressive
+            : NDIlib_frame_format_type_interleaved;
+
     av_log(avctx, AV_LOG_DEBUG, "%s: pkt->pts=%"PRId64", timecode=%"PRId64", st->time_base=%d/%d\n",
         __func__, pkt->pts, ctx->video->timecode, st->time_base.num, st->time_base.den);
 
@@ -358,9 +368,6 @@  static int ndi_setup_video(AVFormatContext *avctx, AVStream *st)
     ctx->video->yres = c->height;
     ctx->video->frame_rate_N = st->avg_frame_rate.num;
     ctx->video->frame_rate_D = st->avg_frame_rate.den;
-    ctx->video->frame_format_type = c->field_order == AV_FIELD_PROGRESSIVE
-        ? NDIlib_frame_format_type_progressive
-        : NDIlib_frame_format_type_interleaved;
 
     if (st->sample_aspect_ratio.num) {
         AVRational display_aspect_ratio;