[FFmpeg-cvslog] avcodec: v4l2_context: remove unnecessary code

2018-01-23 Thread Jorge Ramirez-Ortiz
ffmpeg | branch: master | Jorge Ramirez-Ortiz  | Tue Jan 
23 09:41:29 2018 +0100| [9b1ec248350405e1da64eecad620a8d7a4ee6caa] | committer: 
Jorge Ramirez-Ortiz

avcodec: v4l2_context: remove unnecessary code

Fixes CID 1418358

Signed-off-by: Jorge Ramirez-Ortiz 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9b1ec248350405e1da64eecad620a8d7a4ee6caa
---

 libavcodec/v4l2_context.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/libavcodec/v4l2_context.c b/libavcodec/v4l2_context.c
index e0431b1b3e..efcb0426e4 100644
--- a/libavcodec/v4l2_context.c
+++ b/libavcodec/v4l2_context.c
@@ -446,9 +446,7 @@ static int v4l2_get_raw_format(V4L2Context* ctx, enum 
AVPixelFormat *p)
 
 if (pixfmt != AV_PIX_FMT_NONE) {
 ret = v4l2_try_raw_format(ctx, pixfmt);
-if (ret)
-pixfmt = AV_PIX_FMT_NONE;
-else
+if (!ret)
 return 0;
 }
 

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] avutil/aes_ctr: Add method to set 16-byte IV.

2018-01-23 Thread Jacob Trimble
ffmpeg | branch: master | Jacob Trimble  | 
Mon Jan  8 14:12:43 2018 -0800| [9f07cf7c00f3a87669c27aec947daf0f3d33b01f] | 
committer: Michael Niedermayer

avutil/aes_ctr: Add method to set 16-byte IV.

Signed-off-by: Jacob Trimble 
Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9f07cf7c00f3a87669c27aec947daf0f3d33b01f
---

 doc/APIchanges| 3 +++
 libavutil/aes_ctr.c   | 6 ++
 libavutil/aes_ctr.h   | 7 ++-
 libavutil/tests/aes_ctr.c | 2 +-
 4 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 7699365879..c27f104c95 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil: 2017-10-21
 
 API changes, most recent first:
 
+2018-xx-xx - xxx - lavu 56.9.100 - aes_ctr.h
+  Add method to set the 16-byte IV.
+
 2018-01-xx - xxx - lavf 58.5.100 - avformat.h
   Explicitly make avformat_network_init() and avformat_network_deinit() 
optional.
   If these are not called, network initialization and deinitialization is
diff --git a/libavutil/aes_ctr.c b/libavutil/aes_ctr.c
index e9c568fe0d..0c2e86785f 100644
--- a/libavutil/aes_ctr.c
+++ b/libavutil/aes_ctr.c
@@ -45,6 +45,12 @@ void av_aes_ctr_set_iv(struct AVAESCTR *a, const uint8_t* iv)
 a->block_offset = 0;
 }
 
+void av_aes_ctr_set_full_iv(struct AVAESCTR *a, const uint8_t* iv)
+{
+memcpy(a->counter, iv, sizeof(a->counter));
+a->block_offset = 0;
+}
+
 const uint8_t* av_aes_ctr_get_iv(struct AVAESCTR *a)
 {
 return a->counter;
diff --git a/libavutil/aes_ctr.h b/libavutil/aes_ctr.h
index f596fa6a46..e4aae126a7 100644
--- a/libavutil/aes_ctr.h
+++ b/libavutil/aes_ctr.h
@@ -67,11 +67,16 @@ const uint8_t* av_aes_ctr_get_iv(struct AVAESCTR *a);
 void av_aes_ctr_set_random_iv(struct AVAESCTR *a);
 
 /**
- * Forcefully change the iv
+ * Forcefully change the 8-byte iv
  */
 void av_aes_ctr_set_iv(struct AVAESCTR *a, const uint8_t* iv);
 
 /**
+ * Forcefully change the "full" 16-byte iv, including the counter
+ */
+void av_aes_ctr_set_full_iv(struct AVAESCTR *a, const uint8_t* iv);
+
+/**
  * Increment the top 64 bit of the iv (performed after each frame)
  */
 void av_aes_ctr_increment_iv(struct AVAESCTR *a);
diff --git a/libavutil/tests/aes_ctr.c b/libavutil/tests/aes_ctr.c
index c5ebeda7ac..00fdb05d13 100644
--- a/libavutil/tests/aes_ctr.c
+++ b/libavutil/tests/aes_ctr.c
@@ -45,7 +45,7 @@ int main (void)
 
 av_aes_ctr_set_random_iv(ae);
 iv =   av_aes_ctr_get_iv(ae);
-av_aes_ctr_set_iv(ad, iv);
+av_aes_ctr_set_full_iv(ad, iv);
 
 av_aes_ctr_crypt(ae, tmp, plain, sizeof(tmp));
 av_aes_ctr_crypt(ad, tmp, tmp,   sizeof(tmp));

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] avcodec/hevc_cabac: Move prefix check in coeff_abs_level_remaining_decode() down

2018-01-23 Thread Michael Niedermayer
ffmpeg | branch: master | Michael Niedermayer  | Mon 
Jan 15 23:42:57 2018 +0100| [94d4237a7a294ce80e1e577b38e9c93e8882aff9] | 
committer: Michael Niedermayer

avcodec/hevc_cabac: Move prefix check in coeff_abs_level_remaining_decode() down

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=94d4237a7a294ce80e1e577b38e9c93e8882aff9
---

 libavcodec/hevc_cabac.c | 11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/libavcodec/hevc_cabac.c b/libavcodec/hevc_cabac.c
index 5b5da1165a..743168500c 100644
--- a/libavcodec/hevc_cabac.c
+++ b/libavcodec/hevc_cabac.c
@@ -990,16 +990,19 @@ static av_always_inline int 
coeff_abs_level_remaining_decode(HEVCContext *s, int
 
 while (prefix < CABAC_MAX_BIN && get_cabac_bypass(&s->HEVClc->cc))
 prefix++;
-if (prefix == CABAC_MAX_BIN) {
-av_log(s->avctx, AV_LOG_ERROR, "CABAC_MAX_BIN : %d\n", prefix);
-return 0;
-}
+
 if (prefix < 3) {
 for (i = 0; i < rc_rice_param; i++)
 suffix = (suffix << 1) | get_cabac_bypass(&s->HEVClc->cc);
 last_coeff_abs_level_remaining = (prefix << rc_rice_param) + suffix;
 } else {
 int prefix_minus3 = prefix - 3;
+
+if (prefix == CABAC_MAX_BIN) {
+av_log(s->avctx, AV_LOG_ERROR, "CABAC_MAX_BIN : %d\n", prefix);
+return 0;
+}
+
 for (i = 0; i < prefix_minus3 + rc_rice_param; i++)
 suffix = (suffix << 1) | get_cabac_bypass(&s->HEVClc->cc);
 last_coeff_abs_level_remaining = (((1 << prefix_minus3) + 3 - 1)

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] avcodec/dxtory: Fix bits left checks

2018-01-23 Thread Michael Niedermayer
ffmpeg | branch: master | Michael Niedermayer  | Mon 
Jan 22 14:02:59 2018 +0100| [6e1a167c5564085385488b4f579e9efb987d4bfa] | 
committer: Michael Niedermayer

avcodec/dxtory: Fix bits left checks

Fixes: Timeout
Fixes: 4863/clusterfuzz-testcase-6347354178322432

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=6e1a167c5564085385488b4f579e9efb987d4bfa
---

 libavcodec/dxtory.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/libavcodec/dxtory.c b/libavcodec/dxtory.c
index 6f8652ad49..e736cec8db 100644
--- a/libavcodec/dxtory.c
+++ b/libavcodec/dxtory.c
@@ -326,7 +326,7 @@ static int dx2_decode_slice_5x5(GetBitContext *gb, AVFrame 
*frame,
 int stride   = frame->linesize[0];
 uint8_t *dst = frame->data[0] + stride * line;
 
-for (y = 0; y < left && get_bits_left(gb) > 16; y++) {
+for (y = 0; y < left && get_bits_left(gb) > 6 * width; y++) {
 for (x = 0; x < width; x++) {
 b = decode_sym_565(gb, lru[0], 5);
 g = decode_sym_565(gb, lru[1], is_565 ? 6 : 5);
@@ -392,7 +392,7 @@ static int dx2_decode_slice_rgb(GetBitContext *gb, AVFrame 
*frame,
 int stride   = frame->linesize[0];
 uint8_t *dst = frame->data[0] + stride * line;
 
-for (y = 0; y < left && get_bits_left(gb) > 16; y++) {
+for (y = 0; y < left && get_bits_left(gb) > 6 * width; y++) {
 for (x = 0; x < width; x++) {
 dst[x * 3 + 0] = decode_sym(gb, lru[0]);
 dst[x * 3 + 1] = decode_sym(gb, lru[1]);
@@ -437,7 +437,7 @@ static int dx2_decode_slice_410(GetBitContext *gb, AVFrame 
*frame,
 uint8_t *U  = frame->data[1] + (ustride >> 2) * line;
 uint8_t *V  = frame->data[2] + (vstride >> 2) * line;
 
-for (y = 0; y < left - 3 && get_bits_left(gb) > 16; y += 4) {
+for (y = 0; y < left - 3 && get_bits_left(gb) > 9 * width; y += 4) {
 for (x = 0; x < width; x += 4) {
 for (j = 0; j < 4; j++)
 for (i = 0; i < 4; i++)
@@ -481,7 +481,7 @@ static int dx2_decode_slice_420(GetBitContext *gb, AVFrame 
*frame,
 uint8_t *V  = frame->data[2] + (vstride >> 1) * line;
 
 
-for (y = 0; y < left - 1 && get_bits_left(gb) > 16; y += 2) {
+for (y = 0; y < left - 1 && get_bits_left(gb) > 6 * width; y += 2) {
 for (x = 0; x < width; x += 2) {
 Y[x + 0 + 0 * ystride] = decode_sym(gb, lru[0]);
 Y[x + 1 + 0 * ystride] = decode_sym(gb, lru[0]);
@@ -524,7 +524,7 @@ static int dx2_decode_slice_444(GetBitContext *gb, AVFrame 
*frame,
 uint8_t *U  = frame->data[1] + ustride * line;
 uint8_t *V  = frame->data[2] + vstride * line;
 
-for (y = 0; y < left && get_bits_left(gb) > 16; y++) {
+for (y = 0; y < left && get_bits_left(gb) > 6 * width; y++) {
 for (x = 0; x < width; x++) {
 Y[x] = decode_sym(gb, lru[0]);
 U[x] = decode_sym(gb, lru[1]) ^ 0x80;

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] MAINTAINERS: Add dashenc maintainer

2018-01-23 Thread Karthick Jeyapal
ffmpeg | branch: master | Karthick Jeyapal  | Tue Jan 23 
23:24:35 2018 +0100| [046a9468688a74cf107bfd425ad9e1d7b9d3890b] | committer: 
Michael Niedermayer

MAINTAINERS: Add dashenc maintainer

If somebody else wants to maintain dashenc either now or in future,
I am absolutely fine with giving up this responsibility anytime.
But till then we need a maintainer for dashenc, and I am volunteering for that 
task.

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=046a9468688a74cf107bfd425ad9e1d7b9d3890b
---

 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index d0de26c4f7..ba7a7284eb 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -395,6 +395,7 @@ Muxers/Demuxers:
   cdxl.cPaul B Mahol
   crc.c Michael Niedermayer
   dashdec.c Steven Liu
+  dashenc.c Karthick Jeyapal
   daud.cReimar Doeffinger
   dss.c Oleksij Rempel
   dtsdec.c  foo86

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] avfilter/Makefile: skip compiling vaapi_vpp.h when vaapi is not enabled

2018-01-23 Thread James Almer
ffmpeg | branch: master | James Almer  | Tue Jan 23 23:38:03 
2018 -0300| [f0320afab977edc7b73317c8ef36ff1d60296401] | committer: James Almer

avfilter/Makefile: skip compiling vaapi_vpp.h when vaapi is not enabled

Fixes make checkheaders

Signed-off-by: James Almer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f0320afab977edc7b73317c8ef36ff1d60296401
---

 libavfilter/Makefile | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 34971ce6c1..6a6083618d 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -413,6 +413,7 @@ OBJS-$(CONFIG_SHARED)+= log2_tab.o
 
 SKIPHEADERS-$(CONFIG_QSVVPP) += qsvvpp.h
 SKIPHEADERS-$(CONFIG_OPENCL) += opencl.h
+SKIPHEADERS-$(CONFIG_VAAPI)  += vaapi_vpp.h
 
 TOOLS = graph2dot
 TESTPROGS = drawutils filtfmts formats integral

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] configure: fix vaapi_encode_example dependencies

2018-01-23 Thread James Almer
ffmpeg | branch: master | James Almer  | Tue Jan 23 23:37:33 
2018 -0300| [172564ace9c535e2848edb8d17df926578a458b9] | committer: James Almer

configure: fix vaapi_encode_example dependencies

Signed-off-by: James Almer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=172564ace9c535e2848edb8d17df926578a458b9
---

 configure | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure b/configure
index 24c4f672a3..fcfa7aa442 100755
--- a/configure
+++ b/configure
@@ -3319,7 +3319,7 @@ resampling_audio_example_deps="avutil swresample"
 scaling_video_example_deps="avutil swscale"
 transcode_aac_example_deps="avcodec avformat swresample"
 transcoding_example_deps="avfilter avcodec avformat avutil"
-vaapi_encode_example_deps="avcodec avutil"
+vaapi_encode_example_deps="avcodec avutil h264_vaapi_encoder"
 
 # EXTRALIBS_LIST
 cpu_init_extralibs="pthreads_extralibs"

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] avformat: add option to parse/store ID3 PRIV tags in metadata.

2018-01-23 Thread Richard Shaffer
ffmpeg | branch: master | Richard Shaffer  | Tue Jan 23 
09:39:53 2018 -0800| [8a4cc0a2567fa8418709f75af5539cdf76fefb99] | committer: wm4

avformat: add option to parse/store ID3 PRIV tags in metadata.

Enables getting access to ID3 PRIV tags from the command-line or metadata API
when demuxing. The PRIV owner is stored as the metadata key prepended with
"id3v2_priv.", and the data is stored as the metadata value. As PRIV tags may
contain arbitrary data, non-printable characters, including NULL bytes, are
escaped as \xXX.

Similarly, any metadata tags that begin with "id3v2_priv." are inserted as ID3
PRIV tags into the output (assuming the format supports ID3). \xXX sequences in
the value are un-escaped to their byte value.

Signed-off-by: wm4 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8a4cc0a2567fa8418709f75af5539cdf76fefb99
---

 libavformat/id3v2.c| 48 
 libavformat/id3v2.h| 15 +
 libavformat/id3v2enc.c | 60 ++
 libavformat/utils.c|  2 ++
 libavformat/version.h  |  2 +-
 5 files changed, 126 insertions(+), 1 deletion(-)

diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c
index 6c216ba7a2..b80178d67a 100644
--- a/libavformat/id3v2.c
+++ b/libavformat/id3v2.c
@@ -33,6 +33,7 @@
 #endif
 
 #include "libavutil/avstring.h"
+#include "libavutil/bprint.h"
 #include "libavutil/dict.h"
 #include "libavutil/intreadwrite.h"
 #include "avio_internal.h"
@@ -1224,3 +1225,50 @@ end:
 av_freep(&chapters);
 return ret;
 }
+
+int ff_id3v2_parse_priv_dict(AVDictionary **metadata, ID3v2ExtraMeta 
**extra_meta)
+{
+ID3v2ExtraMeta *cur;
+int dict_flags = AV_DICT_DONT_OVERWRITE | AV_DICT_DONT_STRDUP_KEY | 
AV_DICT_DONT_STRDUP_VAL;
+
+for (cur = *extra_meta; cur; cur = cur->next) {
+if (!strcmp(cur->tag, "PRIV")) {
+ID3v2ExtraMetaPRIV *priv = cur->data;
+AVBPrint bprint;
+char *escaped, *key;
+int i, ret;
+
+if ((key = av_asprintf(ID3v2_PRIV_METADATA_PREFIX "%s", 
priv->owner)) == NULL) {
+return AVERROR(ENOMEM);
+}
+
+av_bprint_init(&bprint, priv->datasize + 1, 
AV_BPRINT_SIZE_UNLIMITED);
+
+for (i = 0; i < priv->datasize; i++) {
+if (priv->data[i] < 32 || priv->data[i] > 126 || priv->data[i] 
== '\\') {
+av_bprintf(&bprint, "\\x%02x", priv->data[i]);
+} else {
+av_bprint_chars(&bprint, priv->data[i], 1);
+}
+}
+
+if ((ret = av_bprint_finalize(&bprint, &escaped)) < 0) {
+av_free(key);
+return ret;
+}
+
+if ((ret = av_dict_set(metadata, key, escaped, dict_flags)) < 0) {
+av_free(key);
+av_free(escaped);
+return ret;
+}
+}
+}
+
+return 0;
+}
+
+int ff_id3v2_parse_priv(AVFormatContext *s, ID3v2ExtraMeta **extra_meta)
+{
+return ff_id3v2_parse_priv_dict(&s->metadata, extra_meta);
+}
diff --git a/libavformat/id3v2.h b/libavformat/id3v2.h
index 5e64ead096..9de0bee374 100644
--- a/libavformat/id3v2.h
+++ b/libavformat/id3v2.h
@@ -39,6 +39,8 @@
 #define ID3v2_FLAG_ENCRYPTION  0x0004
 #define ID3v2_FLAG_COMPRESSION 0x0008
 
+#define ID3v2_PRIV_METADATA_PREFIX "id3v2_priv."
+
 enum ID3v2Encoding {
 ID3v2_ENCODING_ISO8859  = 0,
 ID3v2_ENCODING_UTF16BOM = 1,
@@ -167,6 +169,19 @@ int ff_id3v2_parse_apic(AVFormatContext *s, ID3v2ExtraMeta 
**extra_meta);
  */
 int ff_id3v2_parse_chapters(AVFormatContext *s, ID3v2ExtraMeta **extra_meta);
 
+/**
+ * Parse PRIV tags into a dictionary. The PRIV owner is the metadata key. The
+ * PRIV data is the value, with non-printable characters escaped.
+ */
+int ff_id3v2_parse_priv_dict(AVDictionary **d, ID3v2ExtraMeta **extra_meta);
+
+/**
+ * Add metadata for all PRIV tags in the ID3v2 header. The PRIV owner is the
+ * metadata key. The PRIV data is the value, with non-printable characters
+ * escaped.
+ */
+int ff_id3v2_parse_priv(AVFormatContext *s, ID3v2ExtraMeta **extra_meta);
+
 extern const AVMetadataConv ff_id3v2_34_metadata_conv[];
 extern const AVMetadataConv ff_id3v2_4_metadata_conv[];
 
diff --git a/libavformat/id3v2enc.c b/libavformat/id3v2enc.c
index 14de76ac06..ffe358f019 100644
--- a/libavformat/id3v2enc.c
+++ b/libavformat/id3v2enc.c
@@ -96,6 +96,59 @@ static int id3v2_put_ttag(ID3v2EncContext *id3, AVIOContext 
*avioc, const char *
 return len + ID3v2_HEADER_SIZE;
 }
 
+/**
+ * Write a priv frame with owner and data. 'key' is the owner prepended with
+ * ID3v2_PRIV_METADATA_PREFIX. 'data' is provided as a string. Any \xXX
+ * (where 'X' is a valid hex digit) will be unescaped to the byte value.
+ */
+static int id3v2_put_priv(ID3v2EncContext *id3, AVIOContext *avioc, const char 
*key, const char *data)
+{
+int len;
+uint8_t *pb;
+AVIOContext *dyn_buf;

[FFmpeg-cvslog] avformat/hlsenc: closed caption tags in the master playlist

2018-01-23 Thread Vishwanath Dixit
ffmpeg | branch: master | Vishwanath Dixit  | Wed Jan 24 
11:42:57 2018 +0800| [1948b76a1beabbcf36480c4b2c2af891886ead88] | committer: 
Steven Liu

avformat/hlsenc: closed caption tags in the master playlist

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1948b76a1beabbcf36480c4b2c2af891886ead88
---

 doc/muxers.texi   |  37 +++
 libavformat/dashenc.c |   2 +-
 libavformat/hlsenc.c  | 155 +-
 libavformat/hlsplaylist.c |   5 +-
 libavformat/hlsplaylist.h |   2 +-
 5 files changed, 196 insertions(+), 5 deletions(-)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index b060c4f360..d9a5cc03dc 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -901,6 +901,43 @@ and they are mapped to the two video only variant streams 
with audio group names
 
 By default, a single hls variant containing all the encoded streams is created.
 
+@item cc_stream_map
+Map string which specifies different closed captions groups and their
+attributes. The closed captions stream groups are separated by space.
+Expected string format is like this
+"ccgroup:,instreamid:,language: ".
+'ccgroup' and 'instreamid' are mandatory attributes. 'language' is an optional
+attribute.
+The closed captions groups configured using this option are mapped to different
+variant streams by providing the same 'ccgroup' name in the
+@code{var_stream_map} string. If @code{var_stream_map} is not set, then the
+first available ccgroup in @code{cc_stream_map} is mapped to the output variant
+stream. The examples for these two use cases are given below.
+
+@example
+ffmpeg -re -i in.ts -b:v 1000k -b:a 64k -a53cc 1 -f hls \
+  -cc_stream_map "ccgroup:cc,instreamid:CC1,language:en" \
+  -master_pl_name master.m3u8 \
+  http://example.com/live/out.m3u8
+@end example
+This example adds @code{#EXT-X-MEDIA} tag with @code{TYPE=CLOSED-CAPTIONS} in
+the master playlist with group name 'cc', langauge 'en' (english) and
+INSTREAM-ID 'CC1'. Also, it adds @code{CLOSED-CAPTIONS} attribute with group
+name 'cc' for the output variant stream.
+@example
+ffmpeg -re -i in.ts -b:v:0 1000k -b:v:1 256k -b:a:0 64k -b:a:1 32k \
+  -a53cc:0 1 -a53cc:1 1\
+  -map 0:v -map 0:a -map 0:v -map 0:a -f hls \
+  -cc_stream_map "ccgroup:cc,instreamid:CC1,language:en 
ccgroup:cc,instreamid:CC2,language:sp" \
+  -var_stream_map "v:0,a:0,ccgroup:cc v:1,a:1,ccgroup:cc" \
+  -master_pl_name master.m3u8 \
+  http://example.com/live/out_%v.m3u8
+@end example
+This example adds two @code{#EXT-X-MEDIA} tags with 
@code{TYPE=CLOSED-CAPTIONS} in
+the master playlist for the INSTREAM-IDs 'CC1' and 'CC2'. Also, it adds
+@code{CLOSED-CAPTIONS} attribute with group name 'cc' for the two output 
variant
+streams.
+
 @item master_pl_name
 Create HLS master playlist with the given name.
 
diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index 39d0afe350..5ece1002fe 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -820,7 +820,7 @@ static int write_manifest(AVFormatContext *s, int final)
 stream_bitrate += max_audio_bitrate;
 }
 get_hls_playlist_name(playlist_file, sizeof(playlist_file), NULL, 
i);
-ff_hls_write_stream_info(st, out, stream_bitrate, playlist_file, 
agroup, NULL);
+ff_hls_write_stream_info(st, out, stream_bitrate, playlist_file, 
agroup, NULL, NULL);
 }
 avio_close(out);
 if (use_rename)
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 42e437f5d1..aab21f2f5e 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -152,9 +152,16 @@ typedef struct VariantStream {
 unsigned int nb_streams;
 int m3u8_created; /* status of media play-list creation */
 char *agroup; /* audio group name */
+char *ccgroup; /* closed caption group name */
 char *baseurl;
 } VariantStream;
 
+typedef struct ClosedCaptionsStream {
+char *ccgroup; /* closed caption group name */
+char *instreamid; /* closed captions INSTREAM-ID */
+char *language; /* closed captions langauge */
+} ClosedCaptionsStream;
+
 typedef struct HLSContext {
 const AVClass *class;  // Class for private options.
 int64_t start_sequence;
@@ -203,11 +210,14 @@ typedef struct HLSContext {
 
 VariantStream *var_streams;
 unsigned int nb_varstreams;
+ClosedCaptionsStream *cc_streams;
+unsigned int nb_ccstreams;
 
 int master_m3u8_created; /* status of master play-list creation */
 char *master_m3u8_url; /* URL of the master m3u8 file */
 int version; /* HLS version */
 char *var_stream_map; /* user specified variant stream map string */
+char *cc_stream_map; /* user specified closed caption streams map string */
 char *master_pl_name;
 unsigned int master_publish_rate;
 int http_persistent;
@@ -1167,7 +1177,8 @@ static int create_master_playlist(AVFormatContext *s,
 AVDictionary *options = NULL;
 unsigned int i, j;
 int m3u8_name_size, ret