[FFmpeg-devel] [PATCH] libx264: copy A53 closed captions from source
Anshul
anshul.ffmpeg at gmail.com
Sat Sep 26 12:46:37 CEST 2015
On 09/26/2015 03:57 PM, DeHackEd wrote:
> On 09/26/2015 05:26 AM, Anshul wrote:
>>
>> On 09/26/2015 05:46 AM, DeHackEd wrote:
>>> Assumes 'GA94' format (ATSC standard)
>>>
>>> Signed-off-by: DHE <git at dehacked.net>
>>> ---
>>> doc/encoders.texi | 5 +++++
>>> libavcodec/libx264.c | 37 +++++++++++++++++++++++++++++++++++++
>>> 2 files changed, 42 insertions(+)
>>>
>>> diff --git a/doc/encoders.texi b/doc/encoders.texi
>>> index 3550bcc..bb16dea 100644
>>> --- a/doc/encoders.texi
>>> +++ b/doc/encoders.texi
>>> @@ -2069,6 +2069,11 @@ For example to specify libx264 encoding options with @command{ffmpeg}:
>>> ffmpeg -i foo.mpg -vcodec libx264 -x264opts keyint=123:min-keyint=20 -an out.mkv
>>> @end example
>>>
>>> + at item a53cc
>>> +Import closed captions (which must be ATSC compatible format) into output.
>>> +Only the mpeg2 and h264 decoders provide these. Default is 0 (off).
>>> +
>>> +
>>> @item x264-params (N.A.)
>>> Override the x264 configuration using a :-separated list of key=value
>>> parameters.
>>> diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
>>> index 58fcfb0..4227bcc 100644
>>> --- a/libavcodec/libx264.c
>>> +++ b/libavcodec/libx264.c
>>> @@ -83,6 +83,7 @@ typedef struct X264Context {
>>> int avcintra_class;
>>> int motion_est;
>>> int forced_idr;
>>> + int a53_cc;
>>> char *x264_params;
>>> } X264Context;
>>>
>>> @@ -256,6 +257,7 @@ static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame,
>>> int nnal, i, ret;
>>> x264_picture_t pic_out = {0};
>>> int pict_type;
>>> + AVFrameSideData *side_data;
>>>
>>> x264_picture_init( &x4->pic );
>>> x4->pic.img.i_csp = x4->params.i_csp;
>>> @@ -278,6 +280,40 @@ static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame,
>>> X264_TYPE_AUTO;
>>>
>>> reconfig_encoder(ctx, frame);
>>> +
>>> + if (x4->a53_cc) {
>>> + side_data = av_frame_get_side_data(frame, AV_FRAME_DATA_A53_CC);
>>> + if (side_data) {
>>> + x4->pic.extra_sei.num_payloads = 1;
>>> + x4->pic.extra_sei.payloads = av_mallocz(sizeof(x4->pic.extra_sei.payloads[0]));
>>> + x4->pic.extra_sei.sei_free = av_free;
>>> +
>>> + x4->pic.extra_sei.payloads[0].payload_size = side_data->size + 11;
>>> + x4->pic.extra_sei.payloads[0].payload = av_mallocz(x4->pic.extra_sei.payloads[0].payload_size);
>>> + x4->pic.extra_sei.payloads[0].payload_type = 4;
>>> + memcpy(x4->pic.extra_sei.payloads[0].payload + 10, side_data->data, side_data->size);
>>> + x4->pic.extra_sei.payloads[0].payload[0] = 181;
>>> + x4->pic.extra_sei.payloads[0].payload[1] = 0;
>>> + x4->pic.extra_sei.payloads[0].payload[2] = 49;
>>> +
>>> + /**
>>> + * 'GA94' is standard in North America for ATSC, but hard coding
>>> + * this style may not be the right thing to do -- other formats
>>> + * do exist. This information is not available in the side_data
>>> + * so we are going with this right now.
>>> + */
>> I think GA94 is correct for this situation, since in our x264 decoder we don't consider any other standard
>> for extracting closed caption.
>>
>> I don't know if we have any logic which differentiate between ATSC, ISDB or DVB we parse all transport stream
>> in same manner. if someone know where we differentiate atsc and dvb in FFmpeg please point me there.
>>
>> Note: This logic will also fail when x264 is muxed in formats like gxf where closed caption are kept in vbi instead
>> of GA94.
>>
>> Overall LGTM.
>>
>> I don't know how to apply encrypted mails using git, and when I save your email in Thunderbird, git am is unable to apply.
>> if you can send the same patch as attachment or command to convert encrypted .eml file to normal patch I would test this
>> too.
> I think the easiest solution is to grab the patch from the github repo I use:
> https://github.com/DeHackEd/FFmpeg/commit/16b4c7fc2311d672e99f.patch
anshul at linux-z9q9:~/Project/Multimedia/FFmpeg> git apply
16b4c7fc2311d672e99f.patch
16b4c7fc2311d672e99f.patch:54: trailing whitespace.
16b4c7fc2311d672e99f.patch:75: trailing whitespace.
*/
16b4c7fc2311d672e99f.patch:81: trailing whitespace.
x4->pic.extra_sei.payloads[0].payload[8] =
warning: 3 lines add whitespace errors.
anshul at linux-z9q9:~/Project/Multimedia/FFmpeg>
Though I have fixed it at my end to test, but my advice that you fix it
too and send another patch.
More information about the ffmpeg-devel
mailing list