This also add supports for 4K DeckLink cards because they always output the ancillary data in 10-bit. v2: - only try teletext decoding for 576i PAL mode - some comments as requested by Aaron Levinson
Unified · Split
| @@ -250,8 +250,8 @@ specifically lines 6 to 22, and lines 318 to 335. Line 6 is the LSB in the mask. · 249 unmodified lines | |||
| 250 | Selected lines which do not contain teletext information will be ignored. You | 250 | Selected lines which do not contain teletext information will be ignored. You |
| 251 | can use the special @option{all} constant to select all possible lines, or | 251 | can use the special @option{all} constant to select all possible lines, or |
| 252 | @option{standard} to skip lines 6, 318 and 319, which are not compatible with all | 252 | @option{standard} to skip lines 6, 318 and 319, which are not compatible with all |
| 253 | receivers. Capturing teletext only works for SD PAL sources in 8 bit mode. | 253 | receivers. Capturing teletext only works for SD PAL sources. To use this |
| 254 | To use this option, ffmpeg needs to be compiled with @code{--enable-libzvbi}. | 254 | option, ffmpeg needs to be compiled with @code{--enable-libzvbi}. |
| 255 | 255 | ||
| 256 | @item channels | 256 | @item channels |
| 257 | Defines number of audio channels to capture. Must be @samp{2}, @samp{8} or @samp{16}. | 257 | Defines number of audio channels to capture. Must be @samp{2}, @samp{8} or @samp{16}. |
| @@ -30,6 +30,7 @@ extern "C" { · 29 unmodified lines | |||
| 30 | extern "C" { | 30 | extern "C" { |
| 31 | #include "config.h" | 31 | #include "config.h" |
| 32 | #include "libavformat/avformat.h" | 32 | #include "libavformat/avformat.h" |
| 33 | #include "libavutil/avassert.h" | ||
| 33 | #include "libavutil/avutil.h" | 34 | #include "libavutil/avutil.h" |
| 34 | #include "libavutil/common.h" | 35 | #include "libavutil/common.h" |
| 35 | #include "libavutil/imgutils.h" | 36 | #include "libavutil/imgutils.h" |
| @@ -54,21 +55,43 @@ static uint8_t calc_parity_and_line_offset(int line) · 18 unmodified lines | |||
| 54 | return ret; | 55 | return ret; |
| 55 | } | 56 | } |
| 56 | 57 | ||
| 57 | int teletext_data_unit_from_vbi_data(int line, uint8_t *src, uint8_t *tgt) | 58 | static void fill_data_unit_head(int line, uint8_t *tgt) |
| 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 | |||
| 66 | static uint8_t* teletext_data_unit_from_vbi_data(int line, uint8_t *src, uint8_t *tgt, vbi_pixfmt fmt) | ||
| 58 | { | 67 | { |
| 59 | vbi_bit_slicer slicer; | 68 | vbi_bit_slicer slicer; |
| 60 | 69 | ||
| 61 | vbi_bit_slicer_init(&slicer, 720, 13500000, 6937500, 6937500, 0x00aaaae4, 0xffff, 18, 6, 42 * 8, VBI_MODULATION_NRZ_MSB, VBI_PIXFMT_UYVY); | 70 | vbi_bit_slicer_init(&slicer, 720, 13500000, 6937500, 6937500, 0x00aaaae4, 0xffff, 18, 6, 42 * 8, VBI_MODULATION_NRZ_MSB, fmt); |
| 62 | 71 | ||
| 63 | if (vbi_bit_slice(&slicer, src, tgt + 4) == FALSE) | 72 | if (vbi_bit_slice(&slicer, src, tgt + 4) == FALSE) |
| 64 | return -1; | 73 | return tgt; |
| 65 | 74 | ||
| 66 | tgt[0] = 0x02; // data_unit_id | 75 | fill_data_unit_head(line, tgt); |
| 67 | tgt[1] = 0x2c; // data_unit_length | ||
| 68 | tgt[2] = calc_parity_and_line_offset(line); // field_parity, line_offset | ||
| 69 | tgt[3] = 0xe4; // framing code | ||
| 70 | 76 | ||
| 71 | return 0; | 77 | return tgt + 46; |
| 78 | } | ||
| 79 | |||
| 80 | static uint8_t* teletext_data_unit_from_vbi_data_10bit(int line, uint8_t *src, uint8_t *tgt) | ||
| 81 | { | ||
| 82 | uint8_t y[720]; | ||
| 83 | uint8_t *py = y; | ||
| 84 | uint8_t *pend = y + 720; | ||
| 85 | /* The 10-bit VBI data is packed in V210, but libzvbi only supports 8-bit, | ||
| 86 | * so we extract the 8 MSBs of the luma component, that is enough for | ||
| 87 | * teletext bit slicing. */ | ||
| 88 | while (py < pend) { | ||
| 89 | *py++ = (src[1] >> 4) + ((src[2] & 15) << 4); | ||
| 90 | *py++ = (src[4] >> 2) + ((src[5] & 3 ) << 6); | ||
| 91 | *py++ = (src[6] >> 6) + ((src[7] & 63) << 2); | ||
| 92 | src += 8; | ||
| 93 | } | ||
| 94 | return teletext_data_unit_from_vbi_data(line, y, tgt, VBI_PIXFMT_YUV420); | ||
| 72 | } | 95 | } |
| 73 | #endif | 96 | #endif |
| 74 | 97 | ||
| @@ -359,7 +382,7 @@ HRESULT decklink_input_callback::VideoInputFrameArrived( · 284 unmodified lines | |||
| 359 | //fprintf(stderr,"Video Frame size %d ts %d\n", pkt.size, pkt.pts); | 382 | //fprintf(stderr,"Video Frame size %d ts %d\n", pkt.size, pkt.pts); |
| 360 | 383 | ||
| 361 | #if CONFIG_LIBZVBI | 384 | #if CONFIG_LIBZVBI |
| 362 | if (!no_video && ctx->teletext_lines && videoFrame->GetPixelFormat() == bmdFormat8BitYUV && videoFrame->GetWidth() == 720) { | 385 | if (!no_video && ctx->teletext_lines) { |
| 363 | IDeckLinkVideoFrameAncillary *vanc; | 386 | IDeckLinkVideoFrameAncillary *vanc; |
| 364 | AVPacket txt_pkt; | 387 | AVPacket txt_pkt; |
| 365 | uint8_t txt_buf0[1611]; // max 35 * 46 bytes decoded teletext lines + 1 byte data_identifier | 388 | uint8_t txt_buf0[1611]; // max 35 * 46 bytes decoded teletext lines + 1 byte data_identifier |
| @@ -368,16 +391,22 @@ HRESULT decklink_input_callback::VideoInputFrameArrived( · 2 unmodified lines | |||
| 368 | if (videoFrame->GetAncillaryData(&vanc) == S_OK) { | 391 | if (videoFrame->GetAncillaryData(&vanc) == S_OK) { |
| 369 | int i; | 392 | int i; |
| 370 | int64_t line_mask = 1; | 393 | int64_t line_mask = 1; |
| 394 | BMDPixelFormat vanc_format = vanc->GetPixelFormat(); | ||
| 371 | txt_buf[0] = 0x10; // data_identifier - EBU_data | 395 | txt_buf[0] = 0x10; // data_identifier - EBU_data |
| 372 | txt_buf++; | 396 | txt_buf++; |
| 373 | for (i = 6; i < 336; i++, line_mask <<= 1) { | 397 | if (ctx->bmd_mode == bmdModePAL && (vanc_format == bmdFormat8BitYUV || vanc_format == bmdFormat10BitYUV)) { |
| 374 | uint8_t *buf; | 398 | av_assert0(videoFrame->GetWidth() == 720); |
| 375 | if ((ctx->teletext_lines & line_mask) && vanc->GetBufferForVerticalBlankingLine(i, (void**)&buf) == S_OK) { | 399 | for (i = 6; i < 336; i++, line_mask <<= 1) { |
| 376 | if (teletext_data_unit_from_vbi_data(i, buf, txt_buf) >= 0) | 400 | uint8_t *buf; |
| 377 | txt_buf += 46; | 401 | if ((ctx->teletext_lines & line_mask) && vanc->GetBufferForVerticalBlankingLine(i, (void**)&buf) == S_OK) { |
| 402 | if (vanc_format == bmdFormat8BitYUV) | ||
| 403 | txt_buf = teletext_data_unit_from_vbi_data(i, buf, txt_buf, VBI_PIXFMT_UYVY); | ||
| 404 | else | ||
| 405 | txt_buf = teletext_data_unit_from_vbi_data_10bit(i, buf, txt_buf); | ||
| 406 | } | ||
| 407 | if (i == 22) | ||
| 408 | i = 317; | ||
| 378 | } | 409 | } |
| 379 | if (i == 22) | ||
| 380 | i = 317; | ||
| 381 | } | 410 | } |
| 382 | vanc->Release(); | 411 | vanc->Release(); |
| 383 | if (txt_buf - txt_buf0 > 1) { | 412 | if (txt_buf - txt_buf0 > 1) { |