Advertisement
Guest User

Untitled

a guest
Sep 26th, 2015
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.68 KB | None | 0 0
  1.  
  2.  
  3. Assumes 'GA94' format (ATSC standard)
  4.  
  5. Signed-off-by: DHE <git@dehacked.net>
  6. ---
  7. doc/encoders.texi | 5 +++++
  8. libavcodec/libx264.c | 37 +++++++++++++++++++++++++++++++++++++
  9. 2 files changed, 42 insertions(+)
  10.  
  11. diff --git a/doc/encoders.texi b/doc/encoders.texi
  12. index 3550bcc..bb16dea 100644
  13. --- a/doc/encoders.texi
  14. +++ b/doc/encoders.texi
  15. @@ -2069,6 +2069,11 @@ For example to specify libx264 encoding options with @command{ffmpeg}:
  16. ffmpeg -i foo.mpg -vcodec libx264 -x264opts keyint=123:min-keyint=20 -an out.mkv
  17. @end example
  18.  
  19. +@item a53cc
  20. +Import closed captions (which must be ATSC compatible format) into output.
  21. +Only the mpeg2 and h264 decoders provide these. Default is 0 (off).
  22. +
  23. +
  24. @item x264-params (N.A.)
  25. Override the x264 configuration using a :-separated list of key=value
  26. parameters.
  27. diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
  28. index 58fcfb0..4227bcc 100644
  29. --- a/libavcodec/libx264.c
  30. +++ b/libavcodec/libx264.c
  31. @@ -83,6 +83,7 @@ typedef struct X264Context {
  32. int avcintra_class;
  33. int motion_est;
  34. int forced_idr;
  35. + int a53_cc;
  36. char *x264_params;
  37. } X264Context;
  38.  
  39. @@ -256,6 +257,7 @@ static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame,
  40. int nnal, i, ret;
  41. x264_picture_t pic_out = {0};
  42. int pict_type;
  43. + AVFrameSideData *side_data;
  44.  
  45. x264_picture_init( &x4->pic );
  46. x4->pic.img.i_csp = x4->params.i_csp;
  47. @@ -278,6 +280,40 @@ static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame,
  48. X264_TYPE_AUTO;
  49.  
  50. reconfig_encoder(ctx, frame);
  51. +
  52. + if (x4->a53_cc) {
  53. + side_data = av_frame_get_side_data(frame, AV_FRAME_DATA_A53_CC);
  54. + if (side_data) {
  55. + x4->pic.extra_sei.num_payloads = 1;
  56. + x4->pic.extra_sei.payloads = av_mallocz(sizeof(x4->pic.extra_sei.payloads[0]));
  57. + x4->pic.extra_sei.sei_free = av_free;
  58. +
  59. + x4->pic.extra_sei.payloads[0].payload_size = side_data->size + 11;
  60. + x4->pic.extra_sei.payloads[0].payload = av_mallocz(x4->pic.extra_sei.payloads[0].payload_size);
  61. + x4->pic.extra_sei.payloads[0].payload_type = 4;
  62. + memcpy(x4->pic.extra_sei.payloads[0].payload + 10, side_data->data, side_data->size);
  63. + x4->pic.extra_sei.payloads[0].payload[0] = 181;
  64. + x4->pic.extra_sei.payloads[0].payload[1] = 0;
  65. + x4->pic.extra_sei.payloads[0].payload[2] = 49;
  66. +
  67. + /**
  68. + * 'GA94' is standard in North America for ATSC, but hard coding
  69. + * this style may not be the right thing to do -- other formats
  70. + * do exist. This information is not available in the side_data
  71. + * so we are going with this right now.
  72. + */
  73. + x4->pic.extra_sei.payloads[0].payload[3] = 'G';
  74. + x4->pic.extra_sei.payloads[0].payload[4] = 'A';
  75. + x4->pic.extra_sei.payloads[0].payload[5] = '9';
  76. + x4->pic.extra_sei.payloads[0].payload[6] = '4';
  77. + x4->pic.extra_sei.payloads[0].payload[7] = 3;
  78. + x4->pic.extra_sei.payloads[0].payload[8] =
  79. + ((side_data->size/3) & 0x1f) | 0x40;
  80. + x4->pic.extra_sei.payloads[0].payload[9] = 0;
  81. + x4->pic.extra_sei.payloads[0].payload[side_data->size+10] = 255;
  82. + }
  83. + }
  84. +
  85. }
  86. do {
  87. if (x264_encoder_encode(x4->enc, &nal, &nnal, frame? &x4->pic: NULL, &pic_out) < 0)
  88. @@ -821,6 +857,7 @@ static const AVOption options[] = {
  89. {"level", "Specify level (as defined by Annex A)", OFFSET(level), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, VE},
  90. {"passlogfile", "Filename for 2 pass stats", OFFSET(stats), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, VE},
  91. {"wpredp", "Weighted prediction for P-frames", OFFSET(wpredp), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, VE},
  92. + {"a53cc", "Use A53 Closed Captions (if available)", OFFSET(a53_cc), AV_OPT_TYPE_INT,
  93. {.i64 = 0}, 0, 1, VE},
  94. {"x264opts", "x264 options", OFFSET(x264opts), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, VE},
  95. { "crf", "Select the quality for constant quality mode", OFFSET(crf), AV_OPT_TYPE_FLOAT,
  96. {.dbl = -1 }, -1, FLT_MAX, VE },
  97. { "crf_max", "In CRF mode, prevents VBV from lowering quality beyond this point.",OFFSET(crf_max),
  98. AV_OPT_TYPE_FLOAT, {.dbl = -1 }, -1, FLT_MAX, VE },
  99. --
  100. 1.8.4.1
  101.  
  102. _______________________________________________
  103. ffmpeg-devel mailing list
  104. ffmpeg-devel@ffmpeg.org
  105. http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement