History

lavd/decklink_dec: add support for teletext

It uses the libzvbi slicer, therefore teletext capture requires libzvbi.

Marton Balint committed 10 years ago

Commit 995c7a61 parent 98e94df6 files · +116 −1Browse files

Unified · Split

6 files
  1. doc/indevs.texi +10 −0
  2. libavdevice/decklink_common.h +2 −0
  3. libavdevice/decklink_common_c.h +1 −0
  4. libavdevice/decklink_dec.cpp +99 −0
  5. libavdevice/decklink_dec_c.c +3 −0
  6. libavdevice/version.h +1 −1
doc/indevs.texi+10−0
@@ -236,6 +236,16 @@ Defaults to @option{false}. · 235 unmodified lines
236If set to @samp{1}, video is captured in 10 bit v210 instead236If set to @samp{1}, video is captured in 10 bit v210 instead
237of uyvy422. Not all Blackmagic devices support this option.237of uyvy422. Not all Blackmagic devices support this option.
238 238
239@item teletext_lines
240If set to nonzero, an additional teletext stream will be captured from the
241vertical ancillary data. This option is a bitmask of the VBI lines checked,
242specifically lines 6 to 22, and lines 318 to 335. Line 6 is the LSB in the mask.
243Selected lines which do not contain teletext information will be ignored. You
244can use the special @option{all} constant to select all possible lines, or
245@option{standard} to skip lines 6, 318 and 319, which are not compatible with all
246receivers. Capturing teletext only works for SD PAL sources in 8 bit mode.
247To use this option, ffmpeg needs to be compiled with @code{--enable-libzvbi}.
248
239@end table249@end table
240 250
241@subsection Examples251@subsection Examples
libavdevice/decklink_common.h+2−0
@@ -67,10 +67,12 @@ struct decklink_ctx { · 66 unmodified lines
67 unsigned int dropped;67 unsigned int dropped;
68 AVStream *audio_st;68 AVStream *audio_st;
69 AVStream *video_st;69 AVStream *video_st;
70 AVStream *teletext_st;
70 71
71 /* Options */72 /* Options */
72 int list_devices;73 int list_devices;
73 int list_formats;74 int list_formats;
75 int64_t teletext_lines;
74 double preroll;76 double preroll;
75 77
76 int frames_preroll;78 int frames_preroll;
libavdevice/decklink_common_c.h+1−0
@@ -27,6 +27,7 @@ struct decklink_cctx { · 26 unmodified lines
27 /* Options */27 /* Options */
28 int list_devices;28 int list_devices;
29 int list_formats;29 int list_formats;
30 int64_t teletext_lines;
30 double preroll;31 double preroll;
31 int v210;32 int v210;
32};33};
libavdevice/decklink_dec.cpp+99−0
@@ -25,14 +25,47 @@ · 24 unmodified lines
25#include <semaphore.h>25#include <semaphore.h>
26 26
27extern "C" {27extern "C" {
28#include "config.h"
28#include "libavformat/avformat.h"29#include "libavformat/avformat.h"
29#include "libavformat/internal.h"30#include "libavformat/internal.h"
30#include "libavutil/imgutils.h"31#include "libavutil/imgutils.h"
32#if CONFIG_LIBZVBI
33#include <libzvbi.h>
34#endif
31}35}
32 36
33#include "decklink_common.h"37#include "decklink_common.h"
34#include "decklink_dec.h"38#include "decklink_dec.h"
35 39
40#if CONFIG_LIBZVBI
41static uint8_t calc_parity_and_line_offset(int line)
42{
43 uint8_t ret = (line < 313) << 5;
44 if (line >= 7 && line <= 22)
45 ret += line;
46 if (line >= 320 && line <= 335)
47 ret += (line - 313);
48 return ret;
49}
50
51int teletext_data_unit_from_vbi_data(int line, uint8_t *src, uint8_t *tgt)
52{
53 vbi_bit_slicer slicer;
54
55 vbi_bit_slicer_init(&slicer, 720, 13500000, 6937500, 6937500, 0x00aaaae4, 0xffff, 18, 6, 42 * 8, VBI_MODULATION_NRZ_MSB, VBI_PIXFMT_UYVY);
56
57 if (vbi_bit_slice(&slicer, src, tgt + 4) == FALSE)
58 return -1;
59
60 tgt[0] = 0x02; // data_unit_id
61 tgt[1] = 0x2c; // data_unit_length
62 tgt[2] = calc_parity_and_line_offset(line); // field_parity, line_offset
63 tgt[3] = 0xe4; // framing code
64
65 return 0;
66}
67#endif
68
36static void avpacket_queue_init(AVFormatContext *avctx, AVPacketQueue *q)69static void avpacket_queue_init(AVFormatContext *avctx, AVPacketQueue *q)
37{70{
38 memset(q, 0, sizeof(AVPacketQueue));71 memset(q, 0, sizeof(AVPacketQueue));
@@ -277,6 +310,50 @@ HRESULT decklink_input_callback::VideoInputFrameArrived( · 238 unmodified lines
277 pkt.size = videoFrame->GetRowBytes() *310 pkt.size = videoFrame->GetRowBytes() *
278 videoFrame->GetHeight();311 videoFrame->GetHeight();
279 //fprintf(stderr,"Video Frame size %d ts %d\n", pkt.size, pkt.pts);312 //fprintf(stderr,"Video Frame size %d ts %d\n", pkt.size, pkt.pts);
313
314#if CONFIG_LIBZVBI
315 if (!no_video && ctx->teletext_lines && videoFrame->GetPixelFormat() == bmdFormat8BitYUV && videoFrame->GetWidth() == 720) {
316 IDeckLinkVideoFrameAncillary *vanc;
317 AVPacket txt_pkt;
318 uint8_t txt_buf0[1611]; // max 35 * 46 bytes decoded teletext lines + 1 byte data_identifier
319 uint8_t *txt_buf = txt_buf0;
320
321 if (videoFrame->GetAncillaryData(&vanc) == S_OK) {
322 int i;
323 int64_t line_mask = 1;
324 txt_buf[0] = 0x10; // data_identifier - EBU_data
325 txt_buf++;
326 for (i = 6; i < 336; i++, line_mask <<= 1) {
327 uint8_t *buf;
328 if ((ctx->teletext_lines & line_mask) && vanc->GetBufferForVerticalBlankingLine(i, (void**)&buf) == S_OK) {
329 if (teletext_data_unit_from_vbi_data(i, buf, txt_buf) >= 0)
330 txt_buf += 46;
331 }
332 if (i == 22)
333 i = 317;
334 }
335 vanc->Release();
336 if (txt_buf - txt_buf0 > 1) {
337 int stuffing_units = (4 - ((45 + txt_buf - txt_buf0) / 46) % 4) % 4;
338 while (stuffing_units--) {
339 memset(txt_buf, 0xff, 46);
340 txt_buf[1] = 0x2c; // data_unit_length
341 txt_buf += 46;
342 }
343 av_init_packet(&txt_pkt);
344 txt_pkt.pts = pkt.pts;
345 txt_pkt.dts = pkt.dts;
346 txt_pkt.stream_index = ctx->teletext_st->index;
347 txt_pkt.data = txt_buf0;
348 txt_pkt.size = txt_buf - txt_buf0;
349 if (avpacket_queue_put(&ctx->queue, &txt_pkt) < 0) {
350 ++ctx->dropped;
351 }
352 }
353 }
354 }
355#endif
356
280 c->frame_number++;357 c->frame_number++;
281 if (avpacket_queue_put(&ctx->queue, &pkt) < 0) {358 if (avpacket_queue_put(&ctx->queue, &pkt) < 0) {
282 ++ctx->dropped;359 ++ctx->dropped;
@@ -378,9 +455,17 @@ av_cold int ff_decklink_read_header(AVFormatContext *avctx) · 95 unmodified lines
378 return AVERROR(ENOMEM);455 return AVERROR(ENOMEM);
379 ctx->list_devices = cctx->list_devices;456 ctx->list_devices = cctx->list_devices;
380 ctx->list_formats = cctx->list_formats;457 ctx->list_formats = cctx->list_formats;
458 ctx->teletext_lines = cctx->teletext_lines;
381 ctx->preroll = cctx->preroll;459 ctx->preroll = cctx->preroll;
382 cctx->ctx = ctx;460 cctx->ctx = ctx;
383 461
462#if !CONFIG_LIBZVBI
463 if (ctx->teletext_lines) {
464 av_log(avctx, AV_LOG_ERROR, "Libzvbi support is needed for capturing teletext, please recompile FFmpeg.\n");
465 return AVERROR(ENOSYS);
466 }
467#endif
468
384 iter = CreateDeckLinkIteratorInstance();469 iter = CreateDeckLinkIteratorInstance();
385 if (!iter) {470 if (!iter) {
386 av_log(avctx, AV_LOG_ERROR, "Could not create DeckLink iterator\n");471 av_log(avctx, AV_LOG_ERROR, "Could not create DeckLink iterator\n");
@@ -488,6 +573,20 @@ av_cold int ff_decklink_read_header(AVFormatContext *avctx) · 101 unmodified lines
488 573
489 ctx->video_st=st;574 ctx->video_st=st;
490 575
576 if (ctx->teletext_lines) {
577 st = avformat_new_stream(avctx, NULL);
578 if (!st) {
579 av_log(avctx, AV_LOG_ERROR, "Cannot add stream\n");
580 goto error;
581 }
582 st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;
583 st->codec->time_base.den = ctx->bmd_tb_den;
584 st->codec->time_base.num = ctx->bmd_tb_num;
585 st->codec->codec_id = AV_CODEC_ID_DVB_TELETEXT;
586 avpriv_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */
587 ctx->teletext_st = st;
588 }
589
491 result = ctx->dli->EnableAudioInput(bmdAudioSampleRate48kHz, bmdAudioSampleType16bitInteger, 2);590 result = ctx->dli->EnableAudioInput(bmdAudioSampleRate48kHz, bmdAudioSampleType16bitInteger, 2);
492 591
493 if (result != S_OK) {592 if (result != S_OK) {
libavdevice/decklink_dec_c.c+3−0
@@ -32,6 +32,9 @@ static const AVOption options[] = { · 31 unmodified lines
32 { "list_devices", "list available devices" , OFFSET(list_devices), AV_OPT_TYPE_INT , { .i64 = 0 }, 0, 1, DEC },32 { "list_devices", "list available devices" , OFFSET(list_devices), AV_OPT_TYPE_INT , { .i64 = 0 }, 0, 1, DEC },
33 { "list_formats", "list supported formats" , OFFSET(list_formats), AV_OPT_TYPE_INT , { .i64 = 0 }, 0, 1, DEC },33 { "list_formats", "list supported formats" , OFFSET(list_formats), AV_OPT_TYPE_INT , { .i64 = 0 }, 0, 1, DEC },
34 { "bm_v210", "v210 10 bit per channel" , OFFSET(v210), AV_OPT_TYPE_INT , { .i64 = 0 }, 0, 1, DEC },34 { "bm_v210", "v210 10 bit per channel" , OFFSET(v210), AV_OPT_TYPE_INT , { .i64 = 0 }, 0, 1, DEC },
35 { "teletext_lines", "teletext lines bitmask", OFFSET(teletext_lines), AV_OPT_TYPE_INT64, { .i64 = 0 }, 0, 0x7ffffffffLL, DEC, "teletext_lines"},
36 { "standard", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0x7fff9fffeLL}, 0, 0, DEC, "teletext_lines"},
37 { "all", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0x7ffffffffLL}, 0, 0, DEC, "teletext_lines"},
35 { NULL },38 { NULL },
36};39};
37 40
libavdevice/version.h+1−1
@@ -29,7 +29,7 @@ · 28 unmodified lines
29 29
30#define LIBAVDEVICE_VERSION_MAJOR 5730#define LIBAVDEVICE_VERSION_MAJOR 57
31#define LIBAVDEVICE_VERSION_MINOR 031#define LIBAVDEVICE_VERSION_MINOR 0
32#define LIBAVDEVICE_VERSION_MICRO 10032#define LIBAVDEVICE_VERSION_MICRO 101
33 33
34#define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \34#define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \
35 LIBAVDEVICE_VERSION_MINOR, \35 LIBAVDEVICE_VERSION_MINOR, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t