diff mbox

[FFmpeg-devel] Add A53 closed captions to mpeg picture header.

Message ID CACSqvJ=Osg1+Tw7dwJmOm6QM7yGxwxwd0MbzEfhpRnJii3gNVg@mail.gmail.com
State Superseded
Headers show

Commit Message

John P Poet March 21, 2017, 5:08 p.m. UTC
If AV_FRAME_DATA_A53_CC "user data" is available, encode it into the mpeg
picture header.

This follows the spec in section 6.2.3 of
http://atsc.org/wp-content/uploads/2015/03/a_53-Part-4-2009.pdf

I am working on gstreamer side, to inject the information into the ffmpeg
side data, and have it generally working.

It would also be trivial to add "AV_FRAME_DATA_A53_BAR", but I don't
currently have a way to test that.

John
diff mbox

Patch

From 6c835804b4eaacc27272667d197b63eb76f8d41c Mon Sep 17 00:00:00 2001
From: John Poet <jppoet@digital-nirvana.com>
Date: Tue, 21 Mar 2017 10:02:10 -0600
Subject: [PATCH] Add A53 closed captions to mpeg picture header.

If AV_FRAME_DATA_A53_CC "user data" is available, encode it into the mpeg
picture header.
---
 libavcodec/mpeg12enc.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c
index f45598a..b33e8be 100644
--- a/libavcodec/mpeg12enc.c
+++ b/libavcodec/mpeg12enc.c
@@ -543,6 +543,23 @@  void ff_mpeg1_encode_picture_header(MpegEncContext *s, int picture_number)
         }
     }
 
+    side_data = av_frame_get_side_data(s->current_picture_ptr->f,
+                                       AV_FRAME_DATA_A53_CC);
+    if (side_data) {
+        avpriv_align_put_bits(&s->pb);
+        put_header(s, USER_START_CODE);
+        put_bits(&s->pb, 8, 'G');   //  ATSC_user_data
+        put_bits(&s->pb, 8, 'A');
+        put_bits(&s->pb, 8, '9');
+        put_bits(&s->pb, 8, '4');
+
+        put_bits(&s->pb, 8, 0x03);  // MPEG_cc_data
+
+        for(int idx = 0; idx < side_data->size; ++idx) {
+          put_bits(&s->pb, 8, side_data->data[idx]);
+        }
+    }
+
     s->mb_y = 0;
     ff_mpeg1_encode_slice_header(s);
 }
-- 
2.1.4