[FFmpeg-devel] [PATCH 3/3] libavcodec/ccaption_dec: rewrite packet handler as case statement; remove COR3 macro

2016-01-04 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

---
 libavcodec/ccaption_dec.c | 92 +++
 1 file changed, 53 insertions(+), 39 deletions(-)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index 96f0ccf..788e96a 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -453,54 +453,69 @@ static void handle_char(CCaptionSubContext *ctx, char hi, 
char lo, int64_t pts)
 static int process_cc608(CCaptionSubContext *ctx, int64_t pts, uint8_t hi, 
uint8_t lo)
 {
 int ret = 0;
-#define COR3(var, with1, with2, with3)  ( (var) == (with1) ||  (var) == 
(with2) || (var) == (with3) )
 if (hi == ctx->prev_cmd[0] && lo == ctx->prev_cmd[1]) {
-/* ignore redundant command */
+/* ignore redundant command */
 } else if ( (hi == 0x10 && (lo >= 0x40 || lo <= 0x5f)) ||
   ( (hi >= 0x11 && hi <= 0x17) && (lo >= 0x40 && lo <= 0x7f) ) ) {
 handle_pac(ctx, hi, lo);
 } else if ( ( hi == 0x11 && lo >= 0x20 && lo <= 0x2f ) ||
 ( hi == 0x17 && lo >= 0x2e && lo <= 0x2f) ) {
 handle_textattr(ctx, hi, lo);
-} else if ( COR3(hi, 0x14, 0x15, 0x1C) && lo == 0x20 ) {
-/* resume caption loading */
-ctx->mode = CCMODE_POPON;
-} else if ( COR3(hi, 0x14, 0x15, 0x1C) && lo == 0x24 ) {
-handle_delete_end_of_row(ctx, hi, lo);
-} else if ( COR3(hi, 0x14, 0x15, 0x1C) && lo == 0x25 ) {
-ctx->rollup = 2;
-ctx->mode = CCMODE_ROLLUP_2;
-} else if ( COR3(hi, 0x14, 0x15, 0x1C) && lo == 0x26 ) {
-ctx->rollup = 3;
-ctx->mode = CCMODE_ROLLUP_3;
-} else if ( COR3(hi, 0x14, 0x15, 0x1C) && lo == 0x27 ) {
-ctx->rollup = 4;
-ctx->mode = CCMODE_ROLLUP_4;
-} else if ( COR3(hi, 0x14, 0x15, 0x1C) && lo == 0x29 ) {
-/* resume direct captioning */
-ctx->mode = CCMODE_PAINTON;
-} else if ( COR3(hi, 0x14, 0x15, 0x1C) && lo == 0x2B ) {
-/* resume text display */
-ctx->mode = CCMODE_TEXT;
-} else if ( COR3(hi, 0x14, 0x15, 0x1C) && lo == 0x2C ) {
-/* erase display memory */
-ret = handle_edm(ctx, pts);
-} else if ( COR3(hi, 0x14, 0x15, 0x1C) && lo == 0x2D ) {
-/* carriage return */
-ff_dlog(ctx, "carriage return\n");
-reap_screen(ctx, pts);
-roll_up(ctx);
-ctx->screen_changed = 1;
-ctx->cursor_column = 0;
-} else if ( COR3(hi, 0x14, 0x15, 0x1C) && lo == 0x2F ) {
-/* end of caption */
-ff_dlog(ctx, "handle_eoc\n");
-ret = handle_eoc(ctx, pts);
+} else if (hi == 0x14 || hi == 0x15 || hi == 0x1c) {
+switch (lo) {
+case 0x20:
+/* resume caption loading */
+ctx->mode = CCMODE_POPON;
+break;
+case 0x24:
+handle_delete_end_of_row(ctx, hi, lo);
+break;
+case 0x25:
+ctx->rollup = 2;
+ctx->mode = CCMODE_ROLLUP_2;
+break;
+case 0x26:
+ctx->rollup = 3;
+ctx->mode = CCMODE_ROLLUP_3;
+break;
+case 0x27:
+ctx->rollup = 4;
+ctx->mode = CCMODE_ROLLUP_4;
+break;
+case 0x29:
+/* resume direct captioning */
+ctx->mode = CCMODE_PAINTON;
+break;
+case 0x2b:
+/* resume text display */
+ctx->mode = CCMODE_TEXT;
+break;
+case 0x2c:
+/* erase display memory */
+ret = handle_edm(ctx, pts);
+break;
+case 0x2d:
+/* carriage return */
+ff_dlog(ctx, "carriage return\n");
+reap_screen(ctx, pts);
+roll_up(ctx);
+ctx->screen_changed = 1;
+ctx->cursor_column = 0;
+break;
+case 0x2f:
+/* end of caption */
+ff_dlog(ctx, "handle_eoc\n");
+ret = handle_eoc(ctx, pts);
+break;
+default:
+ff_dlog(ctx, "Unknown command 0x%hhx 0x%hhx\n", hi, lo);
+break;
+}
 } else if (hi>=0x20) {
-/* Standard characters (always in pairs) */
+/* Standard characters (always in pairs) */
 handle_char(ctx, hi, lo, pts);
 } else {
-/* Ignoring all other non data code */
+/* Ignoring all other non data code */
 ff_dlog(ctx, "Unknown command 0x%hhx 0x%hhx\n", hi, lo);
 }
 
@@ -508,7 +523,6 @@ static int process_cc608(CCaptionSubContext *ctx, int64_t 
pts, uint8_t hi, uint8
 ctx->prev_cmd[0] = hi;
 ctx->prev_cmd[1] = lo;
 
-#undef COR3
 return ret;
 }
 
-- 
2.5.3

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


[FFmpeg-devel] [PATCH 2/3] libavcodec/ccaption_dec: clean up and standardize white space

2016-01-04 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

---
 libavcodec/ccaption_dec.c | 98 ++-
 1 file changed, 45 insertions(+), 53 deletions(-)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index 4e478e0..96f0ccf 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -145,10 +145,9 @@ struct Screen {
  * for setting row 1  use row | (1 << 0)
  * for setting row 15 use row | (1 << 14)
  */
-int16_t  row_used;
+int16_t row_used;
 };
 
-
 typedef struct CCaptionSubContext {
 AVClass *class;
 struct Screen screen[2];
@@ -168,7 +167,7 @@ typedef struct CCaptionSubContext {
 char prev_cmd[2];
 /* buffer to store pkt data */
 AVBufferRef *pktbuf;
-}CCaptionSubContext;
+} CCaptionSubContext;
 
 
 static av_cold int init_decoder(AVCodecContext *avctx)
@@ -181,12 +180,12 @@ static av_cold int init_decoder(AVCodecContext *avctx)
 ctx->mode = CCMODE_ROLLUP_2;
 ctx->rollup = 2;
 ret = ff_ass_subtitle_header_default(avctx);
-if(ret < 0) {
+if (ret < 0) {
 return ret;
 }
 /* allocate pkt buffer */
 ctx->pktbuf = av_buffer_alloc(128);
-if( !ctx->pktbuf) {
+if (!ctx->pktbuf) {
 ret = AVERROR(ENOMEM);
 }
 return ret;
@@ -195,7 +194,7 @@ static av_cold int init_decoder(AVCodecContext *avctx)
 static av_cold int close_decoder(AVCodecContext *avctx)
 {
 CCaptionSubContext *ctx = avctx->priv_data;
-av_bprint_finalize( >buffer, NULL);
+av_bprint_finalize(>buffer, NULL);
 av_buffer_unref(>pktbuf);
 return 0;
 }
@@ -203,14 +202,14 @@ static av_cold int close_decoder(AVCodecContext *avctx)
 /**
  * @param ctx closed caption context just to print log
  */
-static int write_char (CCaptionSubContext *ctx, char *row,uint8_t col, char ch)
+static int write_char(CCaptionSubContext *ctx, char *row, uint8_t col, char ch)
 {
-if(col < SCREEN_COLUMNS) {
+if (col < SCREEN_COLUMNS) {
 row[col] = ch;
 return 0;
 }
 /* We have extra space at end only for null character */
-else if ( col == SCREEN_COLUMNS && ch == 0) {
+else if (col == SCREEN_COLUMNS && ch == 0) {
 row[col] = ch;
 return 0;
 }
@@ -227,7 +226,7 @@ static int write_char (CCaptionSubContext *ctx, char 
*row,uint8_t col, char ch)
  * If the second byte doesn't pass parity, it returns INVALIDDATA
  * user can ignore the whole pair and pass the other pair.
  */
-static int validate_cc_data_pair (uint8_t *cc_data_pair)
+static int validate_cc_data_pair(uint8_t *cc_data_pair)
 {
 uint8_t cc_valid = (*cc_data_pair & 4) >>2;
 uint8_t cc_type = *cc_data_pair & 3;
@@ -246,21 +245,19 @@ static int validate_cc_data_pair (uint8_t *cc_data_pair)
 }
 
 //Skip non-data
-if( (cc_data_pair[0] == 0xFA || cc_data_pair[0] == 0xFC || cc_data_pair[0] 
== 0xFD )
+if ((cc_data_pair[0] == 0xFA || cc_data_pair[0] == 0xFC || cc_data_pair[0] 
== 0xFD)
  && (cc_data_pair[1] & 0x7F) == 0 && (cc_data_pair[2] & 0x7F) == 0)
 return AVERROR_PATCHWELCOME;
 
 //skip 708 data
-if(cc_type == 3 || cc_type == 2 )
+if (cc_type == 3 || cc_type == 2)
 return AVERROR_PATCHWELCOME;
 
 /* remove parity bit */
 cc_data_pair[1] &= 0x7F;
 cc_data_pair[2] &= 0x7F;
 
-
 return 0;
-
 }
 
 static struct Screen *get_writing_screen(CCaptionSubContext *ctx)
@@ -286,7 +283,7 @@ static void roll_up(CCaptionSubContext *ctx)
 struct Screen *screen;
 int i, keep_lines;
 
-if(ctx->mode == CCMODE_TEXT)
+if (ctx->mode == CCMODE_TEXT)
 return;
 
 screen = get_writing_screen(ctx);
@@ -296,22 +293,21 @@ static void roll_up(CCaptionSubContext *ctx)
  */
 keep_lines = FFMIN(ctx->cursor_row + 1, ctx->rollup);
 
-for( i = 0; i < ctx->cursor_row - keep_lines; i++ )
+for (i = 0; i < ctx->cursor_row - keep_lines; i++)
 UNSET_FLAG(screen->row_used, i);
 
 
-for( i = 0; i < keep_lines && screen->row_used; i++ ) {
+for (i = 0; i < keep_lines && screen->row_used; i++) {
 const int i_row = ctx->cursor_row - keep_lines + i + 1;
 
-memcpy( screen->characters[i_row], screen->characters[i_row+1], 
SCREEN_COLUMNS );
-memcpy( screen->colors[i_row], screen->colors[i_row+1], 
SCREEN_COLUMNS);
-memcpy( screen->fonts[i_row], screen->fonts[i_row+1], SCREEN_COLUMNS);
-if(CHECK_FLAG(screen->row_used, i_row + 1))
+memcpy(screen->characters[i_row], screen->characters[i_row+1], 
SCREEN_COLUMNS);
+memcpy(screen->colors[i_row], screen->colors[i_row+1], SCREEN_COLUMNS);
+memcpy(screen->fonts[i_row], screen->fonts[i_row+1], SCREEN_COLUMNS);
+if (CHECK_FLAG(screen->row_used, i_row + 1))
 SET_FLAG(scr

[FFmpeg-devel] [PATCH 1/3] libavcodec/ccaption_dec: remove unnecessary include

2016-01-04 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

---
 libavcodec/ccaption_dec.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index 9f67caa..4e478e0 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -21,7 +21,6 @@
 
 #include "avcodec.h"
 #include "ass.h"
-#include "libavutil/internal.h"
 #include "libavutil/opt.h"
 
 #define SCREEN_ROWS 15
-- 
2.5.3

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


[FFmpeg-devel] [PATCH] libavcodec/ccaption_dec: remove unnecessary buffering of closed caption packets

2016-01-01 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

CC data is fed to in small chunks (usually 60 bytes at a time)
and is parsed fully by the eia608 decoder. There is no reason to copy it
into a secondary buffer first.
---
 libavcodec/ccaption_dec.c | 22 +-
 1 file changed, 1 insertion(+), 21 deletions(-)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index 9f67caa..4b1d376 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -167,8 +167,6 @@ typedef struct CCaptionSubContext {
 int64_t startv_time;
 int64_t end_time;
 char prev_cmd[2];
-/* buffer to store pkt data */
-AVBufferRef *pktbuf;
 }CCaptionSubContext;
 
 
@@ -185,11 +183,6 @@ static av_cold int init_decoder(AVCodecContext *avctx)
 if(ret < 0) {
 return ret;
 }
-/* allocate pkt buffer */
-ctx->pktbuf = av_buffer_alloc(128);
-if( !ctx->pktbuf) {
-ret = AVERROR(ENOMEM);
-}
 return ret;
 }
 
@@ -197,7 +190,6 @@ static av_cold int close_decoder(AVCodecContext *avctx)
 {
 CCaptionSubContext *ctx = avctx->priv_data;
 av_bprint_finalize( >buffer, NULL);
-av_buffer_unref(>pktbuf);
 return 0;
 }
 
@@ -524,23 +516,11 @@ static int decode(AVCodecContext *avctx, void *data, int 
*got_sub, AVPacket *avp
 {
 CCaptionSubContext *ctx = avctx->priv_data;
 AVSubtitle *sub = data;
-uint8_t *bptr = NULL;
+uint8_t *bptr = avpkt->data;
 int len = avpkt->size;
 int ret = 0;
 int i;
 
-if ( ctx->pktbuf->size < len) {
-ret = av_buffer_realloc(>pktbuf, len);
- if(ret < 0) {
-av_log(ctx, AV_LOG_WARNING, "Insufficient Memory of %d truncated 
to %d\n",len, ctx->pktbuf->size);
-len = ctx->pktbuf->size;
-ret = 0;
-}
-}
-memcpy(ctx->pktbuf->data, avpkt->data, len);
-bptr = ctx->pktbuf->data;
-
-
 for (i  = 0; i < len; i += 3) {
 uint8_t cc_type = *(bptr + i) & 3;
 if (validate_cc_data_pair( bptr + i) )
-- 
2.5.3

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


Re: [FFmpeg-devel] [PATCH 2/3] libavcodec/ccaption_dec: clean up and standardize white space

2016-01-05 Thread Aman Gupta
On Tue, Jan 5, 2016 at 6:24 PM, Michael Niedermayer <mich...@niedermayer.cc>
wrote:

> On Tue, Jan 05, 2016 at 09:34:35PM +0100, Clément Bœsch wrote:
> > On Mon, Jan 04, 2016 at 07:28:02PM -0800, Aman Gupta wrote:
> > > From: Aman Gupta <a...@tmm1.net>
> > >
> > > ---
> > >  libavcodec/ccaption_dec.c | 98
> ++-
> > >  1 file changed, 45 insertions(+), 53 deletions(-)
> > >
> >
> > There are much more garbage formatting in that file (typically at the
> > beginning of process_cc608 around braces) but still fine with me.
>
> should i apply this patch and the other?
>

Please do, as my follow-up patchsets are based on this patch.


>
> [...]
>
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> The real ebay dictionary, page 3
> "Rare item" - "Common item with rare defect or maybe just a lie"
> "Professional" - "'Toy' made in china, not functional except as doorstop"
> "Experts will know" - "The seller hopes you are not an expert"
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] libavcodec/ccaption_dec: remove unnecessary buffering of closed caption packets

2016-01-05 Thread Aman Gupta
On Tue, Jan 5, 2016 at 12:25 PM, Clément Bœsch  wrote:

> On Sun, Jan 03, 2016 at 01:07:15PM +0100, Clément Bœsch wrote:
> [...]
> > This indeed LGTM, but I'm not the maintainer.
> >
>
> OK I finally understood why it's done that way: validate_cc_data_pair()
> alters the pkt data, but the decoder isn't supposed to do that.
>
> So this patch is actually incorrect in this state.
>

Wow, good catch. The memcpy() makes much more sense now. Thanks.


>
> --
> Clément B.
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 01/10] libavcodec/ccaption_dec: fix whitespace

2016-01-05 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

---
 libavcodec/ccaption_dec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index 34a7208..12e8f1d 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -159,7 +159,7 @@ typedef struct CCaptionSubContext {
 AVBPrint buffer;
 int screen_changed;
 int rollup;
-enum  cc_mode mode;
+enum cc_mode mode;
 int64_t start_time;
 /* visible screen time */
 int64_t startv_time;
-- 
2.5.3

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


[FFmpeg-devel] [PATCH 10/10] libavcodec/ccaption_dec: extract ass time base into constant

2016-01-05 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

---
 libavcodec/ccaption_dec.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index 56b2b52..6dff761 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -30,6 +30,8 @@
 #define UNSET_FLAG(var, val) ( (var) &=  ~( 1 << (val)) )
 #define CHECK_FLAG(var, val) ( (var) &( 1 << (val)) )
 
+static const AVRational ass_tb = {1, 100};
+
 /*
  * TODO list
  * 1) handle font and color completely
@@ -557,8 +559,8 @@ static int decode(AVCodecContext *avctx, void *data, int 
*got_sub, AVPacket *avp
 
 if (ctx->calculate_duration) {
 if (ctx->prev_string) {
-int start_time = av_rescale_q(ctx->prev_time, 
avctx->time_base, (AVRational){ 1, 100 });
-int end_time = av_rescale_q(avpkt->pts, avctx->time_base, 
(AVRational){ 1, 100 });
+int start_time = av_rescale_q(ctx->prev_time, 
avctx->time_base, ass_tb);
+int end_time = av_rescale_q(avpkt->pts, avctx->time_base, 
ass_tb);
 ret = ff_ass_add_rect(sub, ctx->prev_string, start_time, 
end_time - start_time, 0);
 if (ret < 0)
 return ret;
@@ -570,7 +572,7 @@ static int decode(AVCodecContext *avctx, void *data, int 
*got_sub, AVPacket *avp
 ctx->prev_string = av_strdup(ctx->buffer.str);
 ctx->prev_time = avpkt->pts;
 } else {
-int start_time = av_rescale_q(avpkt->pts, avctx->time_base, 
(AVRational){ 1, 100 });
+int start_time = av_rescale_q(avpkt->pts, avctx->time_base, 
ass_tb);
 ret = ff_ass_add_rect_bprint(sub, >buffer, start_time, -1);
 if (ret < 0)
 return ret;
-- 
2.5.3

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


[FFmpeg-devel] [PATCH 07/10] libavcodec/ass.c: increase hardcoded timestamp for infinite duration

2016-01-05 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

before this change, ffmpeg would sometimes generate invalid ASS events
when dealing with mpegts streams that had a large start_time:

Dialogue: 0,20:57:07.37,9:59:59.99,Default,,0,0,0,,(upbeat music playing)
---
 libavcodec/ass.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/ass.c b/libavcodec/ass.c
index 336c308..0484db4 100644
--- a/libavcodec/ass.c
+++ b/libavcodec/ass.c
@@ -92,7 +92,7 @@ int ff_ass_subtitle_header_default(AVCodecContext *avctx)
 static void insert_ts(AVBPrint *buf, int ts)
 {
 if (ts == -1) {
-av_bprintf(buf, "9:59:59.99,");
+av_bprintf(buf, "999:59:59.99,");
 } else {
 int h, m, s;
 
-- 
2.5.3

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


[FFmpeg-devel] [PATCH 03/10] libavcodec/ccaption_dec: add calculate_duration option

2016-01-05 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

new option defaults to true, to preserve existing behavior. by flipping
the option to false, subtitle events are emitted as soon as they are
received and have an infinite duration.

this new mode is useful for realtime decoding of closed captions so they
can be display along with decoded mpeg2 frames.
---
 libavcodec/ccaption_dec.c | 19 ---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index f651c88..9f17e77 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -150,6 +150,7 @@ struct Screen {
 
 typedef struct CCaptionSubContext {
 AVClass *class;
+int calculate_duration;
 struct Screen screen[2];
 int active_screen;
 uint8_t cursor_row;
@@ -545,8 +546,12 @@ static int decode(AVCodecContext *avctx, void *data, int 
*got_sub, AVPacket *avp
 continue;
 else
 process_cc608(ctx, *(bptr + i + 1) & 0x7f, *(bptr + i + 2) & 0x7f);
-if (ctx->screen_changed)
-{
+
+if (!ctx->screen_changed)
+continue;
+ctx->screen_changed = 0;
+
+if (ctx->calculate_duration) {
 if (ctx->prev_string) {
 int start_time = av_rescale_q(ctx->prev_time, 
avctx->time_base, (AVRational){ 1, 100 });
 int end_time = av_rescale_q(avpkt->pts, avctx->time_base, 
(AVRational){ 1, 100 });
@@ -560,7 +565,12 @@ static int decode(AVCodecContext *avctx, void *data, int 
*got_sub, AVPacket *avp
 av_bprintf(>buffer, "\r\n");
 ctx->prev_string = av_strdup(ctx->buffer.str);
 ctx->prev_time = avpkt->pts;
-ctx->screen_changed = 0;
+} else {
+int start_time = av_rescale_q(avpkt->pts, avctx->time_base, 
(AVRational){ 1, 100 });
+ret = ff_ass_add_rect_bprint(sub, >buffer, start_time, -1);
+if (ret < 0)
+return ret;
+sub->pts = av_rescale_q(avpkt->pts, avctx->time_base, 
AV_TIME_BASE_Q);
 }
 }
 
@@ -568,7 +578,10 @@ static int decode(AVCodecContext *avctx, void *data, int 
*got_sub, AVPacket *avp
 return ret;
 }
 
+#define OFFSET(x) offsetof(CCaptionSubContext, x)
+#define SD AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_DECODING_PARAM
 static const AVOption options[] = {
+{ "calculate_duration", "Buffer closed captions to calculate durations.", 
OFFSET(calculate_duration), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, SD },
 {NULL}
 };
 
-- 
2.5.3

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


[FFmpeg-devel] [PATCH 08/10] libavcodec/ccaption_dec.c: fix more whitespace

2016-01-05 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

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

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index 423c576..3de16bf 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -220,7 +220,7 @@ static int write_char(CCaptionSubContext *ctx, char *row, 
uint8_t col, char ch)
 return 0;
 }
 else {
-av_log(ctx, AV_LOG_WARNING,"Data Ignored since exceeding screen 
width\n");
+av_log(ctx, AV_LOG_WARNING, "Data Ignored since exceeding screen 
width\n");
 return AVERROR_INVALIDDATA;
 }
 }
@@ -323,7 +323,7 @@ static int reap_screen(CCaptionSubContext *ctx)
 
 for (i = 0; screen->row_used && i < SCREEN_ROWS; i++)
 {
-if (CHECK_FLAG(screen->row_used,i)) {
+if (CHECK_FLAG(screen->row_used, i)) {
 char *str = screen->characters[i];
 /* skip space */
 while (*str == ' ')
@@ -360,7 +360,7 @@ static void handle_textattr(CCaptionSubContext *ctx, 
uint8_t hi, uint8_t lo)
 ctx->cursor_color = pac2_attribs[i][0];
 ctx->cursor_font = pac2_attribs[i][1];
 
-SET_FLAG(screen->row_used,ctx->cursor_row);
+SET_FLAG(screen->row_used, ctx->cursor_row);
 ret = write_char(ctx, row, ctx->cursor_column, ' ');
 if (ret == 0)
 ctx->cursor_column++;
@@ -377,7 +377,7 @@ static void handle_pac(CCaptionSubContext *ctx, uint8_t hi, 
uint8_t lo)
 int indent, i, ret;
 
 if (row_map[index] <= 0) {
-av_log(ctx, AV_LOG_DEBUG,"Invalid pac index encountered\n");
+av_log(ctx, AV_LOG_DEBUG, "Invalid pac index encountered\n");
 return;
 }
 
@@ -534,7 +534,7 @@ static int decode(AVCodecContext *avctx, void *data, int 
*got_sub, AVPacket *avp
 if (ctx->pktbuf->size < len) {
 ret = av_buffer_realloc(>pktbuf, len);
  if (ret < 0) {
-av_log(ctx, AV_LOG_WARNING, "Insufficient Memory of %d truncated 
to %d\n",len, ctx->pktbuf->size);
+av_log(ctx, AV_LOG_WARNING, "Insufficient Memory of %d truncated 
to %d\n", len, ctx->pktbuf->size);
 len = ctx->pktbuf->size;
 ret = 0;
 }
-- 
2.5.3

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


[FFmpeg-devel] [PATCH 04/10] libavcodec/ccaption_dec: reap_screen after flipping on EOC

2016-01-05 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

---
 libavcodec/ccaption_dec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index 9f17e77..5d4c568 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -399,9 +399,9 @@ static void handle_erase(CCaptionSubContext *ctx, int 
n_screen)
 
 static void handle_eoc(CCaptionSubContext *ctx)
 {
-reap_screen(ctx);
 ctx->active_screen = !ctx->active_screen;
 ctx->cursor_column = 0;
+reap_screen(ctx);
 }
 
 static void handle_delete_end_of_row(CCaptionSubContext *ctx, char hi, char lo)
-- 
2.5.3

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


[FFmpeg-devel] [PATCH 05/10] libavcodec/ccaption_dec: combine ROLLUP modes as they are identical

2016-01-05 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

---
 libavcodec/ccaption_dec.c | 16 ++--
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index 5d4c568..424b434 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -37,9 +37,7 @@
 enum cc_mode {
 CCMODE_POPON,
 CCMODE_PAINTON,
-CCMODE_ROLLUP_2,
-CCMODE_ROLLUP_3,
-CCMODE_ROLLUP_4,
+CCMODE_ROLLUP,
 CCMODE_TEXT,
 };
 
@@ -176,7 +174,7 @@ static av_cold int init_decoder(AVCodecContext *avctx)
 
 av_bprint_init(>buffer, 0, AV_BPRINT_SIZE_UNLIMITED);
 /* taking by default roll up to 2 */
-ctx->mode = CCMODE_ROLLUP_2;
+ctx->mode = CCMODE_ROLLUP;
 ctx->rollup = 2;
 ret = ff_ass_subtitle_header_default(avctx);
 if (ret < 0) {
@@ -266,9 +264,7 @@ static struct Screen *get_writing_screen(CCaptionSubContext 
*ctx)
 // use Inactive screen
 return ctx->screen + !ctx->active_screen;
 case CCMODE_PAINTON:
-case CCMODE_ROLLUP_2:
-case CCMODE_ROLLUP_3:
-case CCMODE_ROLLUP_4:
+case CCMODE_ROLLUP:
 case CCMODE_TEXT:
 // use active screen
 return ctx->screen + ctx->active_screen;
@@ -460,15 +456,15 @@ static void process_cc608(CCaptionSubContext *ctx, 
uint8_t hi, uint8_t lo)
 break;
 case 0x25:
 ctx->rollup = 2;
-ctx->mode = CCMODE_ROLLUP_2;
+ctx->mode = CCMODE_ROLLUP;
 break;
 case 0x26:
 ctx->rollup = 3;
-ctx->mode = CCMODE_ROLLUP_3;
+ctx->mode = CCMODE_ROLLUP;
 break;
 case 0x27:
 ctx->rollup = 4;
-ctx->mode = CCMODE_ROLLUP_4;
+ctx->mode = CCMODE_ROLLUP;
 break;
 case 0x29:
 /* resume direct captioning */
-- 
2.5.3

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


[FFmpeg-devel] [PATCH 02/10] libavcodec/ccaption_dec: fix timestamps on generated subtitles by buffering after EOC/newline commands

2016-01-05 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

before:

  Dialogue: 0,0:00:00.03,0:00:00.67,Default,,0,0,0,,EVERYBODY, TONIGHT WE'LL 
COVER
  Dialogue: 0,0:00:00.67,0:00:02.30,Default,,0,0,0,,EVERYBODY, TONIGHT WE'LL 
COVER\NTHE NEWS WE MISSED OVER THE
  Dialogue: 0,0:00:02.30,0:00:03.57,Default,,0,0,0,,THE NEWS WE MISSED OVER 
THE\NHOLIDAYS AND SEE HOW THE

after:

  Dialogue: 0,0:00:00.67,0:00:02.30,Default,,0,0,0,,EVERYBODY, TONIGHT WE'LL 
COVER
  Dialogue: 0,0:00:02.30,0:00:03.57,Default,,0,0,0,,EVERYBODY, TONIGHT WE'LL 
COVER\NTHE NEWS WE MISSED OVER THE
  Dialogue: 0,0:00:03.57,0:00:04.30,Default,,0,0,0,,THE NEWS WE MISSED OVER 
THE\NHOLIDAYS AND SEE HOW THE
---
 libavcodec/ccaption_dec.c | 47 ---
 1 file changed, 24 insertions(+), 23 deletions(-)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index 12e8f1d..f651c88 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -160,10 +160,8 @@ typedef struct CCaptionSubContext {
 int screen_changed;
 int rollup;
 enum cc_mode mode;
-int64_t start_time;
-/* visible screen time */
-int64_t startv_time;
-int64_t end_time;
+char *prev_string;
+int64_t prev_time;
 char prev_cmd[2];
 /* buffer to store pkt data */
 AVBufferRef *pktbuf;
@@ -310,12 +308,11 @@ static void roll_up(CCaptionSubContext *ctx)
 UNSET_FLAG(screen->row_used, ctx->cursor_row);
 }
 
-static int reap_screen(CCaptionSubContext *ctx, int64_t pts)
+static int reap_screen(CCaptionSubContext *ctx)
 {
 int i;
 int ret = 0;
 struct Screen *screen = ctx->screen + ctx->active_screen;
-ctx->start_time = ctx->startv_time;
 av_bprint_clear(>buffer);
 
 for (i = 0; screen->row_used && i < SCREEN_ROWS; i++)
@@ -341,8 +338,6 @@ static int reap_screen(CCaptionSubContext *ctx, int64_t pts)
 ctx->screen_changed = 1;
 }
 
-ctx->startv_time = pts;
-ctx->end_time = pts;
 return ret;
 }
 
@@ -401,9 +396,9 @@ static void handle_erase(CCaptionSubContext *ctx, int 
n_screen)
 screen->row_used = 0;
 }
 
-static void handle_eoc(CCaptionSubContext *ctx, int64_t pts)
+static void handle_eoc(CCaptionSubContext *ctx)
 {
-reap_screen(ctx, pts);
+reap_screen(ctx);
 ctx->active_screen = !ctx->active_screen;
 ctx->cursor_column = 0;
 }
@@ -415,7 +410,7 @@ static void handle_delete_end_of_row(CCaptionSubContext 
*ctx, char hi, char lo)
 write_char(ctx, row, ctx->cursor_column, 0);
 }
 
-static void handle_char(CCaptionSubContext *ctx, char hi, char lo, int64_t pts)
+static void handle_char(CCaptionSubContext *ctx, char hi, char lo)
 {
 struct Screen *screen = get_writing_screen(ctx);
 char *row = screen->characters[ctx->cursor_row];
@@ -443,7 +438,7 @@ static void handle_char(CCaptionSubContext *ctx, char hi, 
char lo, int64_t pts)
ff_dlog(ctx, "(%c)\n", hi);
 }
 
-static void process_cc608(CCaptionSubContext *ctx, int64_t pts, uint8_t hi, 
uint8_t lo)
+static void process_cc608(CCaptionSubContext *ctx, uint8_t hi, uint8_t lo)
 {
 if (hi == ctx->prev_cmd[0] && lo == ctx->prev_cmd[1]) {
 /* ignore redundant command */
@@ -489,7 +484,7 @@ static void process_cc608(CCaptionSubContext *ctx, int64_t 
pts, uint8_t hi, uint
 case 0x2d:
 /* carriage return */
 ff_dlog(ctx, "carriage return\n");
-reap_screen(ctx, pts);
+reap_screen(ctx);
 roll_up(ctx);
 ctx->cursor_column = 0;
 break;
@@ -500,7 +495,7 @@ static void process_cc608(CCaptionSubContext *ctx, int64_t 
pts, uint8_t hi, uint
 case 0x2f:
 /* end of caption */
 ff_dlog(ctx, "handle_eoc\n");
-handle_eoc(ctx, pts);
+handle_eoc(ctx);
 break;
 default:
 ff_dlog(ctx, "Unknown command 0x%hhx 0x%hhx\n", hi, lo);
@@ -510,7 +505,7 @@ static void process_cc608(CCaptionSubContext *ctx, int64_t 
pts, uint8_t hi, uint
 /* ignore tab offset */
 } else if (hi >= 0x20) {
 /* Standard characters (always in pairs) */
-handle_char(ctx, hi, lo, pts);
+handle_char(ctx, hi, lo);
 } else {
 /* Ignoring all other non data code */
 ff_dlog(ctx, "Unknown command 0x%hhx 0x%hhx\n", hi, lo);
@@ -549,16 +544,22 @@ static int decode(AVCodecContext *avctx, void *data, int 
*got_sub, AVPacket *avp
 if(cc_type == 1)
 continue;
 else
-process_cc608(ctx, avpkt->pts, *(bptr + i + 1) & 0x7f, *(bptr + i 
+ 2) & 0x7f);
+process_cc608(ctx, *(bptr + i + 1) & 0x7f, *(bptr + i + 2) & 0x7f);
 if (ctx->screen_changed)
 {
-int start_time = av_rescale_q(ctx->start_time, avctx->time_base, 
(AVRational){ 1, 100 });
-int 

[FFmpeg-devel] [PATCH 06/10] libavcodec/ccaption_dec: flush screen buffer on seek

2016-01-05 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

---
 libavcodec/ccaption_dec.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index 424b434..423c576 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -196,6 +196,15 @@ static av_cold int close_decoder(AVCodecContext *avctx)
 return 0;
 }
 
+static void flush_decoder(AVCodecContext *avctx)
+{
+CCaptionSubContext *ctx = avctx->priv_data;
+ctx->screen[0].row_used = 0;
+ctx->screen[1].row_used = 0;
+av_bprint_clear(>buffer);
+ctx->screen_changed = 1;
+}
+
 /**
  * @param ctx closed caption context just to print log
  */
@@ -596,6 +605,7 @@ AVCodec ff_ccaption_decoder = {
 .priv_data_size = sizeof(CCaptionSubContext),
 .init   = init_decoder,
 .close  = close_decoder,
+.flush  = flush_decoder,
 .decode = decode,
 .priv_class = _dec_class,
 };
-- 
2.5.3

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


[FFmpeg-devel] [PATCH 09/10] libavcodec/ccaption_dec: default to simpler POPON mode

2016-01-05 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

the default value does not really have any effect in normal operation,
as the mode command is repeated before every new caption. after seeking,
it makes more sense to default to POPON since that is the more common
mode.
---
 libavcodec/ccaption_dec.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index 3de16bf..56b2b52 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -173,9 +173,7 @@ static av_cold int init_decoder(AVCodecContext *avctx)
 CCaptionSubContext *ctx = avctx->priv_data;
 
 av_bprint_init(>buffer, 0, AV_BPRINT_SIZE_UNLIMITED);
-/* taking by default roll up to 2 */
-ctx->mode = CCMODE_ROLLUP;
-ctx->rollup = 2;
+ctx->mode = CCMODE_POPON;
 ret = ff_ass_subtitle_header_default(avctx);
 if (ret < 0) {
 return ret;
@@ -203,6 +201,7 @@ static void flush_decoder(AVCodecContext *avctx)
 ctx->screen[1].row_used = 0;
 av_bprint_clear(>buffer);
 ctx->screen_changed = 1;
+ctx->mode = CCMODE_POPON;
 }
 
 /**
-- 
2.5.3

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


Re: [FFmpeg-devel] [PATCH 03/10] libavcodec/ccaption_dec: add calculate_duration option

2016-01-06 Thread Aman Gupta
The new "calculate_duration" option in this patch defaults to true, to
preserve the existing behavior. You can set it to false to get the new
realtime behavior. This seems a little backwards, so if someone has a
better name for this new behavior I'd be interested to hear it. Maybe the
option can be called "realtime" and default to false?

Here's an example of the old and new optional behavior:

$ ffmpeg -y -nostats -f lavfi -i 'movie=input.ts[out0+subcc]' -map s -f ass
-
Dialogue: 0,0:00:02.70,0:00:07.47,Default,,0,0,0,,- HEY, THINGS ACTUALLY
TURNED\NOUT OKAY FOR ME THIS TIME.
Dialogue: 0,0:00:07.47,0:00:08.61,Default,,0,0,0,,- BUTTERS!
Dialogue: 0,0:00:08.61,0:00:10.48,Default,,0,0,0,,- OH, I KNOW.
Dialogue: 0,0:00:10.48,0:00:41.64,Default,,0,0,0,,Captioning by CaptionMax\
Nwww.captionmax.com
Dialogue: 0,0:00:41.64,0:00:42.28,Default,,0,0,0,,>> Trevor: HAPPY NEW YEAR,
Dialogue: 0,0:00:42.28,0:00:43.91,Default,,0,0,0,,>> Trevor: HAPPY NEW
YEAR,\NEVERYBODY, TONIGHT WE'LL COVER
Dialogue: 0,0:00:43.91,0:00:45.18,Default,,0,0,0,,EVERYBODY, TONIGHT WE'LL
COVER\NTHE NEWS WE MISSED OVER THE

$ ffmpeg -y -calculate_duration 0 -nostats -f lavfi -i
'movie=input.ts[out0+subcc]' -map s -f ass -
Dialogue: 0,0:00:00.20,999:59:59.99,Default,,0,0,0,,
Dialogue: 0,0:00:00.27,999:59:59.99,Default,,0,0,0,,
Dialogue: 0,0:00:02.64,999:59:59.99,Default,,0,0,0,,
Dialogue: 0,0:00:02.70,999:59:59.99,Default,,0,0,0,,- HEY, THINGS ACTUALLY
TURNED\NOUT OKAY FOR ME THIS TIME.
Dialogue: 0,0:00:07.41,999:59:59.99,Default,,0,0,0,,
Dialogue: 0,0:00:07.47,999:59:59.99,Default,,0,0,0,,- BUTTERS!
Dialogue: 0,0:00:08.54,999:59:59.99,Default,,0,0,0,,
Dialogue: 0,0:00:08.61,999:59:59.99,Default,,0,0,0,,- OH, I KNOW.
Dialogue: 0,0:00:10.41,999:59:59.99,Default,,0,0,0,,
Dialogue: 0,0:00:10.48,999:59:59.99,Default,,0,0,0,,Captioning by
CaptionMax\Nwww.captionmax.com
Dialogue: 0,0:00:13.48,999:59:59.99,Default,,0,0,0,,
Dialogue: 0,0:00:41.07,999:59:59.99,Default,,0,0,0,,
Dialogue: 0,0:00:41.27,999:59:59.99,Default,,0,0,0,,>> Trevor
Dialogue: 0,0:00:41.47,999:59:59.99,Default,,0,0,0,,>> Trevor: HAPPY NEW
Dialogue: 0,0:00:41.64,999:59:59.99,Default,,0,0,0,,>> Trevor: HAPPY NEW
YEAR,
Dialogue: 0,0:00:41.84,999:59:59.99,Default,,0,0,0,,>> Trevor: HAPPY NEW
YEAR,\NEVERYBODY,
Dialogue: 0,0:00:42.04,999:59:59.99,Default,,0,0,0,,>> Trevor: HAPPY NEW
YEAR,\NEVERYBODY, TONIGHT WE
Dialogue: 0,0:00:42.24,999:59:59.99,Default,,0,0,0,,>> Trevor: HAPPY NEW
YEAR,\NEVERYBODY, TONIGHT WE'LL COVER
Dialogue: 0,0:00:42.28,999:59:59.99,Default,,0,0,0,,>> Trevor: HAPPY NEW
YEAR,\NEVERYBODY, TONIGHT WE'LL COVER
Dialogue: 0,0:00:42.48,999:59:59.99,Default,,0,0,0,,EVERYBODY, TONIGHT
WE'LL COVER\NTHE NEWS W
Dialogue: 0,0:00:42.68,999:59:59.99,Default,,0,0,0,,EVERYBODY, TONIGHT
WE'LL COVER\NTHE NEWS WE
Dialogue: 0,0:00:43.01,999:59:59.99,Default,,0,0,0,,EVERYBODY, TONIGHT
WE'LL COVER\NTHE NEWS WE M
Dialogue: 0,0:00:43.21,999:59:59.99,Default,,0,0,0,,EVERYBODY, TONIGHT
WE'LL COVER\NTHE NEWS WE MISSED OVER
Dialogue: 0,0:00:43.41,999:59:59.99,Default,,0,0,0,,EVERYBODY, TONIGHT
WE'LL COVER\NTHE NEWS WE MISSED OVER THE
Dialogue: 0,0:00:43.91,999:59:59.99,Default,,0,0,0,,EVERYBODY, TONIGHT
WE'LL COVER\NTHE NEWS WE MISSED OVER THE

On Wed, Jan 6, 2016 at 2:37 AM, wm4 <nfx...@googlemail.com> wrote:

> On Tue,  5 Jan 2016 23:41:35 -0800
> Aman Gupta <ffm...@tmm1.net> wrote:
>
> > From: Aman Gupta <a...@tmm1.net>
> >
> > new option defaults to true, to preserve existing behavior. by flipping
> > the option to false, subtitle events are emitted as soon as they are
> > received and have an infinite duration.
> >
> > this new mode is useful for realtime decoding of closed captions so they
> > can be display along with decoded mpeg2 frames.
> > ---
> >  libavcodec/ccaption_dec.c | 19 ---
> >  1 file changed, 16 insertions(+), 3 deletions(-)
> >
> > diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
> > index f651c88..9f17e77 100644
> > --- a/libavcodec/ccaption_dec.c
> > +++ b/libavcodec/ccaption_dec.c
> > @@ -150,6 +150,7 @@ struct Screen {
> >
> >  typedef struct CCaptionSubContext {
> >  AVClass *class;
> > +int calculate_duration;
> >  struct Screen screen[2];
> >  int active_screen;
> >  uint8_t cursor_row;
> > @@ -545,8 +546,12 @@ static int decode(AVCodecContext *avctx, void
> *data, int *got_sub, AVPacket *avp
> >  continue;
> >  else
> >  process_cc608(ctx, *(bptr + i + 1) & 0x7f, *(bptr + i + 2)
> & 0x7f);
> > -if (ctx->screen_changed)
> > -{
> > +
> > +if (!ctx->screen_changed)
> > +continue;
> > +ctx->screen_changed = 0;
&g

Re: [FFmpeg-devel] [PATCH 04/10] libavcodec/ccaption_dec: reap_screen after flipping on EOC

2016-01-07 Thread Aman Gupta
Probably should have written a longer commit message here. The EOC command
stands for "end of caption" aka "display buffer". It's used with POPON
mode, where characters are written to an off-screen buffer and EOC flips
the buffers to display what has been written so far. Thus, it makes sense
to reap the screen *after* flipping the active screen, not *before*.

The previous behavior was simply wrong, but masked by other bugs also fixed
in this patchset.

Aman

On Tue, Jan 5, 2016 at 11:41 PM, Aman Gupta <ffm...@tmm1.net> wrote:

> From: Aman Gupta <a...@tmm1.net>
>
> ---
>  libavcodec/ccaption_dec.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
> index 9f17e77..5d4c568 100644
> --- a/libavcodec/ccaption_dec.c
> +++ b/libavcodec/ccaption_dec.c
> @@ -399,9 +399,9 @@ static void handle_erase(CCaptionSubContext *ctx, int
> n_screen)
>
>  static void handle_eoc(CCaptionSubContext *ctx)
>  {
> -reap_screen(ctx);
>  ctx->active_screen = !ctx->active_screen;
>  ctx->cursor_column = 0;
> +reap_screen(ctx);
>  }
>
>  static void handle_delete_end_of_row(CCaptionSubContext *ctx, char hi,
> char lo)
> --
> 2.5.3
>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 04/10] libavcodec/ccaption_dec: reap_screen after flipping on EOC

2016-01-08 Thread Aman Gupta
On Fri, Jan 8, 2016 at 2:50 AM, Anshul Maheshwari <anshul.ffm...@gmail.com>
wrote:

>
>
> On Thu, Jan 7, 2016 at 6:14 AM, Aman Gupta <a...@tmm1.net> wrote:
>
>> Probably should have written a longer commit message here. The EOC
>> command stands for "end of caption" aka "display buffer". It's used with
>> POPON mode, where characters are written to an off-screen buffer and EOC
>> flips the buffers to display what has been written so far. Thus, it makes
>> sense to reap the screen *after* flipping the active screen, not *before*.
>>
>> The previous behavior was simply wrong, but masked by other bugs also
>> fixed in this patchset.
>>
>> Aman
>>
>> On Tue, Jan 5, 2016 at 11:41 PM, Aman Gupta <ffm...@tmm1.net> wrote:
>>
>>> From: Aman Gupta <a...@tmm1.net>
>>>
>>> ---
>>>  libavcodec/ccaption_dec.c | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
>>> index 9f17e77..5d4c568 100644
>>> --- a/libavcodec/ccaption_dec.c
>>> +++ b/libavcodec/ccaption_dec.c
>>> @@ -399,9 +399,9 @@ static void handle_erase(CCaptionSubContext *ctx,
>>> int n_screen)
>>>
>>>  static void handle_eoc(CCaptionSubContext *ctx)
>>>  {
>>> -reap_screen(ctx);
>>>  ctx->active_screen = !ctx->active_screen;
>>>  ctx->cursor_column = 0;
>>> +reap_screen(ctx);
>>>  }
>>>
>>>  static void handle_delete_end_of_row(CCaptionSubContext *ctx, char hi,
>>> char lo)
>>> --
>>> 2.5.3
>>>
>>>
>> I dont see it as bug, this problem comes because of change in 02/10 patch.
>
> handle_eoc always called handle_edm, am I missing some patch?
>

I removed the call to EDM from inside EOC, in "libavcodec/ccaption_dec:
reap_screen is not necessary when clearing screen or buffer"

Always calling EDM does not make sense, because the caption stream will
already send EDM when it is required. I think the EDM from EOC behavior was
a work around because previously "erase non-displayed memory" was not
implemented. See commit: libavcodec/ccaption_dec: implement "erase non
displayed memory"


>
> how does it matter, since this code has to be exectued sequentially? reap
> before or after I see them  at same instant or at same command.
>

This matters because reap_screen will look at active_screen. EOC means
"display buffer", so we must first flip the active screen to display the
off-screen buffer, and then reap it. If you reap first, you are reading
from the incorrect buffer.


>
>
> -Anshul
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 1/2] lavc/ccaption_dec: flush context on seek

2016-01-09 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

---
 libavcodec/ccaption_dec.c | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index fc6431b..8bef771 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -165,6 +165,24 @@ static av_cold int close_decoder(AVCodecContext *avctx)
 return 0;
 }
 
+static void flush_decoder(AVCodecContext *avctx)
+{
+CCaptionSubContext *ctx = avctx->priv_data;
+ctx->screen[0].row_used = 0;
+ctx->screen[1].row_used = 0;
+ctx->prev_cmd[0] = 0;
+ctx->prev_cmd[1] = 0;
+ctx->mode = CCMODE_ROLLUP;
+ctx->rollup = 2;
+ctx->cursor_row = 0;
+ctx->cursor_column = 0;
+ctx->cursor_font = 0;
+ctx->cursor_color = 0;
+ctx->active_screen = 0;
+av_bprint_clear(>buffer);
+ctx->buffer_changed = 0;
+}
+
 /**
  * @param ctx closed caption context just to print log
  */
@@ -570,6 +588,7 @@ AVCodec ff_ccaption_decoder = {
 .priv_data_size = sizeof(CCaptionSubContext),
 .init   = init_decoder,
 .close  = close_decoder,
+.flush  = flush_decoder,
 .decode = decode,
 .priv_class = _dec_class,
 };
-- 
2.5.3

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


[FFmpeg-devel] [PATCH 2/2] lavc/ccaption_dec: implement real_time option

2016-01-09 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

This new mode is useful for realtime decoding of closed captions so they
can be display along with mpeg2 frames.

Closed caption streams contain two major types of captions:

- POPON captions, which are buffered off-screen and displayed
  only after EOC (end of caption, aka display buffer)

- PAINTON/ROLLUP captions, which are written to the display as soon as
  they arrive.

In a typical real-time eia608 decoder, commands like EOC (end of
caption; display buffer), EDM (erase display memory) and EBM (erase
buffered memory) perform their expected functions as soon as the
commands are processed. This is implemented in the real_time branches
added in this commit.

Before this commit, and in the !real_time branches after this commit,
the decoder cleverly implements its own version of the decoder which is
specifically geared towards buffered decoding. It does so by actively
ignoring commands like EBM (erase buffered memory), and then re-using
the non-display buffer to hold the previous caption while the new one is
received. This is the opposite of the real-time decoder, which uses the
non-display buffer to hold the new caption while the display buffer is
still showing the current caption.

In addition to ignoring EBM, the buffered decoder also has custom
implementations for EDM and EOC. An EDM (erase display memory) command
flushes the existing contents before clearing the screen, and EOC
similarly always flushes the active buffer (the previous subtitle)
before flipping buffers.
---
 libavcodec/ccaption_dec.c  | 85 +-
 tests/fate/subtitles.mak   |  3 ++
 tests/ref/fate/sub-cc-realtime | 42 +
 3 files changed, 121 insertions(+), 9 deletions(-)
 create mode 100644 tests/ref/fate/sub-cc-realtime

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index 8bef771..8c26fcc 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -116,6 +116,7 @@ struct Screen {
 
 typedef struct CCaptionSubContext {
 AVClass *class;
+int real_time;
 struct Screen screen[2];
 int active_screen;
 uint8_t cursor_row;
@@ -130,6 +131,8 @@ typedef struct CCaptionSubContext {
 /* visible screen time */
 int64_t startv_time;
 int64_t end_time;
+int screen_touched;
+int64_t last_real_time;
 char prev_cmd[2];
 /* buffer to store pkt data */
 AVBufferRef *pktbuf;
@@ -180,7 +183,10 @@ static void flush_decoder(AVCodecContext *avctx)
 ctx->cursor_color = 0;
 ctx->active_screen = 0;
 av_bprint_clear(>buffer);
-ctx->buffer_changed = 0;
+ctx->last_real_time = 0;
+ctx->screen_touched = 0;
+/* emit empty subtitle on seek in realtime mode */
+ctx->buffer_changed = ctx->real_time ? 1 : 0;
 }
 
 /**
@@ -418,15 +424,33 @@ static void handle_edm(CCaptionSubContext *ctx, int64_t 
pts)
 {
 struct Screen *screen = ctx->screen + ctx->active_screen;
 
-reap_screen(ctx, pts);
+// In buffered mode, keep writing to screen until it is wiped.
+// Before wiping the display, capture contents to emit subtitle.
+if (!ctx->real_time)
+reap_screen(ctx, pts);
+
 screen->row_used = 0;
+
+// In realtime mode, emit an empty caption so the last one doesn't
+// stay on the screen.
+if (ctx->real_time)
+reap_screen(ctx, pts);
 }
 
 static void handle_eoc(CCaptionSubContext *ctx, int64_t pts)
 {
-handle_edm(ctx,pts);
+// In buffered mode, we wait til the *next* EOC and
+// reap what was already on the screen since the last EOC.
+if (!ctx->real_time)
+handle_edm(ctx,pts);
+
 ctx->active_screen = !ctx->active_screen;
 ctx->cursor_column = 0;
+
+// In realtime mode, we display the buffered contents (after
+// flipping the buffer to active above) as soon as EOC arrives.
+if (ctx->real_time)
+reap_screen(ctx, pts);
 }
 
 static void handle_delete_end_of_row(CCaptionSubContext *ctx, char hi, char lo)
@@ -448,6 +472,9 @@ static void handle_char(CCaptionSubContext *ctx, char hi, 
char lo, int64_t pts)
 }
 write_char(ctx, screen, 0);
 
+if (ctx->mode != CCMODE_POPON)
+ctx->screen_touched = 1;
+
 /* reset prev command since character can repeat */
 ctx->prev_cmd[0] = 0;
 ctx->prev_cmd[1] = 0;
@@ -497,10 +524,20 @@ static void process_cc608(CCaptionSubContext *ctx, 
int64_t pts, uint8_t hi, uint
 case 0x2d:
 /* carriage return */
 ff_dlog(ctx, "carriage return\n");
-reap_screen(ctx, pts);
+if (!ctx->real_time)
+reap_screen(ctx, pts);
 roll_up(ctx);
 ctx->cursor_column = 0;
 break;
+case 0x2e:
+/* erase buffered (non displayed) memory */
+// Only in realtime mode. In buffered mode, we re-use the

[FFmpeg-devel] [PATCH 1/3] libavcodec/ccaption_dec: rename to screen_changed to screen_reaped

2016-01-06 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

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

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index 6dff761..706da16 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -158,7 +158,7 @@ typedef struct CCaptionSubContext {
 uint8_t cursor_color;
 uint8_t cursor_font;
 AVBPrint buffer;
-int screen_changed;
+int screen_reaped;
 int rollup;
 enum cc_mode mode;
 char *prev_string;
@@ -202,7 +202,7 @@ static void flush_decoder(AVCodecContext *avctx)
 ctx->screen[0].row_used = 0;
 ctx->screen[1].row_used = 0;
 av_bprint_clear(>buffer);
-ctx->screen_changed = 1;
+ctx->screen_reaped = 1;
 ctx->mode = CCMODE_POPON;
 }
 
@@ -342,9 +342,9 @@ static int reap_screen(CCaptionSubContext *ctx)
 if (screen->row_used && ctx->buffer.len >= 2) {
 ctx->buffer.len -= 2;
 ctx->buffer.str[ctx->buffer.len] = 0;
-ctx->screen_changed = 1;
 }
 
+ctx->screen_reaped = 1;
 return ret;
 }
 
@@ -553,9 +553,9 @@ static int decode(AVCodecContext *avctx, void *data, int 
*got_sub, AVPacket *avp
 else
 process_cc608(ctx, *(bptr + i + 1) & 0x7f, *(bptr + i + 2) & 0x7f);
 
-if (!ctx->screen_changed)
+if (!ctx->screen_reaped)
 continue;
-ctx->screen_changed = 0;
+ctx->screen_reaped = 0;
 
 if (ctx->calculate_duration) {
 if (ctx->prev_string) {
-- 
2.5.3

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


[FFmpeg-devel] [PATCH 2/3] libavcodec/ccaption_dec: in realtime mode, emit new ASS events every 200ms

2016-01-06 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

---
 libavcodec/ccaption_dec.c | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index 706da16..737c3f6 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -159,6 +159,7 @@ typedef struct CCaptionSubContext {
 uint8_t cursor_font;
 AVBPrint buffer;
 int screen_reaped;
+int screen_touched;
 int rollup;
 enum cc_mode mode;
 char *prev_string;
@@ -487,6 +488,7 @@ static void process_cc608(CCaptionSubContext *ctx, uint8_t 
hi, uint8_t lo)
 case 0x2c:
 /* erase display memory */
 handle_erase(ctx, ctx->active_screen);
+ctx->screen_touched = 1;
 break;
 case 0x2d:
 /* carriage return */
@@ -513,6 +515,8 @@ static void process_cc608(CCaptionSubContext *ctx, uint8_t 
hi, uint8_t lo)
 } else if (hi >= 0x20) {
 /* Standard characters (always in pairs) */
 handle_char(ctx, hi, lo);
+if (ctx->mode != CCMODE_POPON)
+ctx->screen_touched = 1;
 } else {
 /* Ignoring all other non data code */
 ff_dlog(ctx, "Unknown command 0x%hhx 0x%hhx\n", hi, lo);
@@ -577,9 +581,23 @@ static int decode(AVCodecContext *avctx, void *data, int 
*got_sub, AVPacket *avp
 if (ret < 0)
 return ret;
 sub->pts = av_rescale_q(avpkt->pts, avctx->time_base, 
AV_TIME_BASE_Q);
+ctx->prev_time = avpkt->pts;
 }
 }
 
+if (!ctx->calculate_duration && ctx->screen_touched &&
+avpkt->pts > ctx->prev_time + av_rescale_q(20, ass_tb, 
avctx->time_base)) {
+ctx->screen_touched = 0;
+
+reap_screen(ctx);
+ctx->screen_reaped = 0;
+
+int start_time = av_rescale_q(avpkt->pts, avctx->time_base, ass_tb);
+ff_ass_add_rect_bprint(sub, >buffer, start_time, -1);
+sub->pts = av_rescale_q(avpkt->pts, avctx->time_base, AV_TIME_BASE_Q);
+ctx->prev_time = avpkt->pts;
+}
+
 *got_sub = sub->num_rects > 0;
 return ret;
 }
-- 
2.5.3

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


[FFmpeg-devel] [PATCH 3/3] libavcodec/ccaption_dec: emit blank ASS events only in realtime mode

2016-01-06 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

---
 libavcodec/ccaption_dec.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index 737c3f6..8e3008d 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -345,7 +345,9 @@ static int reap_screen(CCaptionSubContext *ctx)
 ctx->buffer.str[ctx->buffer.len] = 0;
 }
 
-ctx->screen_reaped = 1;
+if (ctx->buffer.len || !ctx->calculate_duration)
+ctx->screen_reaped = 1;
+
 return ret;
 }
 
-- 
2.5.3

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


[FFmpeg-devel] [PATCH v2 8/9] lavc/ccaption_dec: implement positioning for closed captions

2016-01-12 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

Positioning math is based on the guidelines in
https://dvcs.w3.org/hg/text-tracks/raw-file/default/608toVTT/608toVTT.html#positioning-in-cea-608
---
 libavcodec/ccaption_dec.c | 29 +
 1 file changed, 25 insertions(+), 4 deletions(-)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index 1c8a0d0..4ec063e 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -316,7 +316,7 @@ static void roll_up(CCaptionSubContext *ctx)
 
 static int capture_screen(CCaptionSubContext *ctx)
 {
-int i;
+int i, j, tab = 0;
 struct Screen *screen = ctx->screen + ctx->active_screen;
 enum cc_font prev_font = CCFONT_REGULAR;
 av_bprint_clear(>buffer);
@@ -325,13 +325,30 @@ static int capture_screen(CCaptionSubContext *ctx)
 {
 if (CHECK_FLAG(screen->row_used, i)) {
 const char *row = screen->characters[i];
+j = 0;
+while (row[j] == ' ')
+j++;
+if (!tab || j < tab)
+tab = j;
+}
+}
+
+for (i = 0; screen->row_used && i < SCREEN_ROWS; i++)
+{
+if (CHECK_FLAG(screen->row_used, i)) {
+const char *row = screen->characters[i];
 const char *font = screen->fonts[i];
-int j = 0;
+int x, y, seen_char = 0;
+j = 0;
 
 /* skip leading space */
-while (row[j] == ' ')
+while (row[j] == ' ' && j < tab)
 j++;
 
+x = ASS_DEFAULT_PLAYRESX * (0.1 + 0.0250 * j);
+y = ASS_DEFAULT_PLAYRESY * (0.1 + 0.0533 * i);
+av_bprintf(>buffer, "{\\an7}{\\pos(%d,%d)}", x, y);
+
 for (; j < SCREEN_COLUMNS; j++) {
 const char *e_tag = "", *s_tag = "";
 
@@ -365,8 +382,12 @@ static int capture_screen(CCaptionSubContext *ctx)
 prev_font = font[j];
 if (row[j] == 1)
 av_bprintf(>buffer, "%s%s\u266A", e_tag, s_tag);
-else
+else if (row[j] == ' ' && !seen_char)
+av_bprintf(>buffer, "%s%s\\h", e_tag, s_tag);
+else {
 av_bprintf(>buffer, "%s%s%c", e_tag, s_tag, row[j]);
+seen_char = 1;
+}
 
 }
 av_bprintf(>buffer, "\\N");
-- 
2.5.3

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


[FFmpeg-devel] [PATCH v2 5/9] lavc/ccaption_dec: implement tab offset commands

2016-01-12 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

---
 libavcodec/ccaption_dec.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index 8c913fe..50625df 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -558,6 +558,11 @@ static void process_cc608(CCaptionSubContext *ctx, int64_t 
pts, uint8_t hi, uint
 } else if (hi >= 0x20) {
 /* Standard characters (always in pairs) */
 handle_char(ctx, hi, lo, pts);
+} else if (hi == 0x17 && lo >= 0x21 && lo <= 0x23) {
+/* Tab offsets (spacing) */
+for (int i = 0; i < lo - 0x20; i++) {
+handle_char(ctx, ' ', 0, pts);
+}
 } else {
 /* Ignoring all other non data code */
 ff_dlog(ctx, "Unknown command 0x%hhx 0x%hhx\n", hi, lo);
-- 
2.5.3

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


[FFmpeg-devel] [PATCH v2 3/9] fate: add test for realtime ccaption decoder

2016-01-12 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

---
 tests/fate/subtitles.mak   |  3 +++
 tests/ref/fate/sub-cc-realtime | 42 ++
 2 files changed, 45 insertions(+)
 create mode 100644 tests/ref/fate/sub-cc-realtime

diff --git a/tests/fate/subtitles.mak b/tests/fate/subtitles.mak
index d273f2e..8aa0279 100644
--- a/tests/fate/subtitles.mak
+++ b/tests/fate/subtitles.mak
@@ -4,6 +4,9 @@ fate-sub-aqtitle: CMD = fmtstdout ass -sub_charenc windows-1250 
-i $(TARGET_SAMP
 FATE_SUBTITLES_ASS-$(call ALLYES, AVDEVICE LAVFI_INDEV CCAPTION_DECODER 
MOVIE_FILTER MPEGTS_DEMUXER) += fate-sub-cc
 fate-sub-cc: CMD = fmtstdout ass -f lavfi -i 
"movie=$(TARGET_SAMPLES)/sub/Closedcaption_rollup.m2v[out0+subcc]"
 
+FATE_SUBTITLES_ASS-$(call ALLYES, AVDEVICE LAVFI_INDEV CCAPTION_DECODER 
MOVIE_FILTER MPEGTS_DEMUXER) += fate-sub-cc-realtime
+fate-sub-cc-realtime: CMD = fmtstdout ass -real_time 1 -f lavfi -i 
"movie=$(TARGET_SAMPLES)/sub/Closedcaption_rollup.m2v[out0+subcc]"
+
 FATE_SUBTITLES_ASS-$(call DEMDEC, ASS, ASS) += fate-sub-ass-to-ass-transcode
 fate-sub-ass-to-ass-transcode: CMD = fmtstdout ass -i 
$(TARGET_SAMPLES)/sub/1ededcbd7b.ass
 
diff --git a/tests/ref/fate/sub-cc-realtime b/tests/ref/fate/sub-cc-realtime
new file mode 100644
index 000..0b4037c
--- /dev/null
+++ b/tests/ref/fate/sub-cc-realtime
@@ -0,0 +1,42 @@
+[Script Info]
+; Script generated by FFmpeg/Lavc
+ScriptType: v4.00+
+PlayResX: 384
+PlayResY: 288
+
+[V4+ Styles]
+Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, 
OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, 
Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, 
MarginV, Encoding
+Style: 
Default,Monospace,16,0,0,0,0,100,100,0,0,3,1,0,2,10,10,10,0
+
+[Events]
+Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
+Dialogue: 0,0:00:14.14,999:59:59.99,Default,,0,0,0,,(
+Dialogue: 0,0:00:15.47,999:59:59.99,Default,,0,0,0,,({\i1} in
+Dialogue: 0,0:00:15.92,999:59:59.99,Default,,0,0,0,,({\i1} inau
+Dialogue: 0,0:00:16.36,999:59:59.99,Default,,0,0,0,,({\i1} inaudi
+Dialogue: 0,0:00:16.81,999:59:59.99,Default,,0,0,0,,({\i1} inaudibl
+Dialogue: 0,0:00:17.25,999:59:59.99,Default,,0,0,0,,({\i1} inaudible 
+Dialogue: 0,0:00:17.70,999:59:59.99,Default,,0,0,0,,({\i1} inaudible ra
+Dialogue: 0,0:00:18.14,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radi
+Dialogue: 0,0:00:18.59,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
+Dialogue: 0,0:00:19.03,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio ch
+Dialogue: 0,0:00:19.48,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio chat
+Dialogue: 0,0:00:19.92,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatte
+Dialogue: 0,0:00:20.36,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter
+Dialogue: 0,0:00:21.70,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )
+Dialogue: 0,0:00:42.61,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>>
+Dialogue: 0,0:00:43.05,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> S
+Dialogue: 0,0:00:43.50,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Saf
+Dialogue: 0,0:00:43.94,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Safet
+Dialogue: 0,0:00:44.39,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Safety 
+Dialogue: 0,0:00:44.83,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Safety re
+Dialogue: 0,0:00:45.28,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Safety rema
+Dialogue: 0,0:00:45.72,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Safety remain
+Dialogue: 0,0:00:46.17,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Safety remains 
+Dialogue: 0,0:00:46.61,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Safety remains ou
+Dialogue: 0,0:00:47.06,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Safety remains our 
+Dialogue: 0,0:00:47.50,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Safety remains our nu
+Dialogue: 0,0:00:47.95,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Safety remains our numb
+Dialogue: 0,0:00:48.39,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Safety remains our number
+Dialogue: 0,0:00:48.84,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Safety remains our number o
+Dialogue: 0,0:00:49.28,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Safety remains our number one
-- 
2.5.3

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


[FFmpeg-devel] [PATCH v2 9/9] fate: update sub-cc tests for subtitle positioning

2016-01-12 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

---
 tests/ref/fate/sub-cc  |  4 +--
 tests/ref/fate/sub-cc-realtime | 60 +-
 2 files changed, 32 insertions(+), 32 deletions(-)

diff --git a/tests/ref/fate/sub-cc b/tests/ref/fate/sub-cc
index 0d5bc77..4cc02d1 100644
--- a/tests/ref/fate/sub-cc
+++ b/tests/ref/fate/sub-cc
@@ -10,5 +10,5 @@ Style: 
Default,Monospace,16,0,0,0,0,100,100,0,0,3,1,0,
 
 [Events]
 Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
-Dialogue: 0,0:00:12.36,0:00:40.83,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )
-Dialogue: 0,0:00:40.83,0:00:59.07,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Safety remains our number one
+Dialogue: 0,0:00:12.36,0:00:40.83,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} 
inaudible radio chatter{\i0} )
+Dialogue: 0,0:00:40.83,0:00:59.07,Default,,0,0,0,,{\an7}{\pos(38,28)}({\i1} 
inaudible radio chatter{\i0} )\N{\an7}{\pos(38,44)}>> Safety remains our number 
one
diff --git a/tests/ref/fate/sub-cc-realtime b/tests/ref/fate/sub-cc-realtime
index 0b4037c..be800a4 100644
--- a/tests/ref/fate/sub-cc-realtime
+++ b/tests/ref/fate/sub-cc-realtime
@@ -10,33 +10,33 @@ Style: 
Default,Monospace,16,0,0,0,0,100,100,0,0,3,1,0,
 
 [Events]
 Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
-Dialogue: 0,0:00:14.14,999:59:59.99,Default,,0,0,0,,(
-Dialogue: 0,0:00:15.47,999:59:59.99,Default,,0,0,0,,({\i1} in
-Dialogue: 0,0:00:15.92,999:59:59.99,Default,,0,0,0,,({\i1} inau
-Dialogue: 0,0:00:16.36,999:59:59.99,Default,,0,0,0,,({\i1} inaudi
-Dialogue: 0,0:00:16.81,999:59:59.99,Default,,0,0,0,,({\i1} inaudibl
-Dialogue: 0,0:00:17.25,999:59:59.99,Default,,0,0,0,,({\i1} inaudible 
-Dialogue: 0,0:00:17.70,999:59:59.99,Default,,0,0,0,,({\i1} inaudible ra
-Dialogue: 0,0:00:18.14,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radi
-Dialogue: 0,0:00:18.59,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
-Dialogue: 0,0:00:19.03,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio ch
-Dialogue: 0,0:00:19.48,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio chat
-Dialogue: 0,0:00:19.92,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatte
-Dialogue: 0,0:00:20.36,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter
-Dialogue: 0,0:00:21.70,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )
-Dialogue: 0,0:00:42.61,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>>
-Dialogue: 0,0:00:43.05,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> S
-Dialogue: 0,0:00:43.50,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Saf
-Dialogue: 0,0:00:43.94,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Safet
-Dialogue: 0,0:00:44.39,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Safety 
-Dialogue: 0,0:00:44.83,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Safety re
-Dialogue: 0,0:00:45.28,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Safety rema
-Dialogue: 0,0:00:45.72,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Safety remain
-Dialogue: 0,0:00:46.17,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Safety remains 
-Dialogue: 0,0:00:46.61,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Safety remains ou
-Dialogue: 0,0:00:47.06,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Safety remains our 
-Dialogue: 0,0:00:47.50,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Safety remains our nu
-Dialogue: 0,0:00:47.95,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Safety remains our numb
-Dialogue: 0,0:00:48.39,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Safety remains our number
-Dialogue: 0,0:00:48.84,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Safety remains our number o
-Dialogue: 0,0:00:49.28,999:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Safety remains our number one
+Dialogue: 0,0:00:14.14,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}(
+Dialogue: 0,0:00:15.47,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} in
+Dialogue: 0,0:00:15.92,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} 
inau
+Dialogue: 0,0:00:16.36,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} 
inaudi
+Dialogue: 0,0:00:16.81,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} 
inaudibl
+Dialogue: 0,0:00:17.25,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} 
inaudible 
+Dialogue: 0,0:00:17.70,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} 
inaudible ra
+Dialogue: 0,0:00:18.14,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} 
inaudible radi
+Dialogue: 0,0:00:18.59

[FFmpeg-devel] [PATCH v2 1/9] lavc/ccaption_dec: flush context on seek

2016-01-12 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

---
 libavcodec/ccaption_dec.c | 21 +
 1 file changed, 21 insertions(+)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index ca497e5..a9dfc94 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -173,6 +173,26 @@ static av_cold int close_decoder(AVCodecContext *avctx)
 return 0;
 }
 
+static void flush_decoder(AVCodecContext *avctx)
+{
+CCaptionSubContext *ctx = avctx->priv_data;
+ctx->screen[0].row_used = 0;
+ctx->screen[1].row_used = 0;
+ctx->prev_cmd[0] = 0;
+ctx->prev_cmd[1] = 0;
+ctx->mode = CCMODE_ROLLUP;
+ctx->rollup = 2;
+ctx->cursor_row = 0;
+ctx->cursor_column = 0;
+ctx->cursor_font = 0;
+ctx->cursor_color = 0;
+ctx->active_screen = 0;
+ctx->last_real_time = 0;
+ctx->screen_touched = 0;
+ctx->buffer_changed = 0;
+av_bprint_clear(>buffer);
+}
+
 /**
  * @param ctx closed caption context just to print log
  */
@@ -578,6 +598,7 @@ AVCodec ff_ccaption_decoder = {
 .priv_data_size = sizeof(CCaptionSubContext),
 .init   = init_decoder,
 .close  = close_decoder,
+.flush  = flush_decoder,
 .decode = decode,
 .priv_class = _dec_class,
 };
-- 
2.5.3

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


[FFmpeg-devel] [PATCH v2 4/9] lavc/ccaption_dec: default rollup to row 10

2016-01-12 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

This ensures that captions are written towards the bottom of the screen
when tuning into mid-stream. The row will be reset on the receipt of the
next PAC command. Row 10 was chosen as it corresponds to the value of
"0" in a PAC (see row_map in handle_pac()).
---
 libavcodec/ccaption_dec.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index 6bdd754..8c913fe 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -148,6 +148,7 @@ static av_cold int init_decoder(AVCodecContext *avctx)
 /* taking by default roll up to 2 */
 ctx->mode = CCMODE_ROLLUP;
 ctx->rollup = 2;
+ctx->cursor_row = 10;
 ret = ff_ass_subtitle_header(avctx, "Monospace",
  ASS_DEFAULT_FONT_SIZE,
  ASS_DEFAULT_COLOR,
@@ -185,7 +186,7 @@ static void flush_decoder(AVCodecContext *avctx)
 ctx->prev_cmd[1] = 0;
 ctx->mode = CCMODE_ROLLUP;
 ctx->rollup = 2;
-ctx->cursor_row = 0;
+ctx->cursor_row = 10;
 ctx->cursor_column = 0;
 ctx->cursor_font = 0;
 ctx->cursor_color = 0;
-- 
2.5.3

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


[FFmpeg-devel] [PATCH v2 7/9] lavc/ccaption_dec: implement musical glyph

2016-01-12 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

This is the most commonly used character from the special north-american
character set. All the non-standard charsets are "optional" according to
the spec, and we currently implement none of them. This commit adds
support for "♪" which very popular (and has no ascii fallback), typically
used to indicate lyrics in captions.
---
 libavcodec/ccaption_dec.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index ff0735e..1c8a0d0 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -363,7 +363,11 @@ static int capture_screen(CCaptionSubContext *ctx)
 }
 }
 prev_font = font[j];
-av_bprintf(>buffer, "%s%s%c", e_tag, s_tag, row[j]);
+if (row[j] == 1)
+av_bprintf(>buffer, "%s%s\u266A", e_tag, s_tag);
+else
+av_bprintf(>buffer, "%s%s%c", e_tag, s_tag, row[j]);
+
 }
 av_bprintf(>buffer, "\\N");
 }
@@ -557,6 +561,9 @@ static void process_cc608(CCaptionSubContext *ctx, int64_t 
pts, uint8_t hi, uint
 ff_dlog(ctx, "Unknown command 0x%hhx 0x%hhx\n", hi, lo);
 break;
 }
+} else if (hi == 0x11 && lo == 0x37) {
+/* Musical note glyph */
+handle_char(ctx, 1, 0, pts);
 } else if (hi >= 0x20) {
 /* Standard characters (always in pairs) */
 handle_char(ctx, hi, lo, pts);
-- 
2.5.3

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


[FFmpeg-devel] [PATCH v2 2/9] lavc/ccaption_dec: implement real_time option

2016-01-12 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

This new mode is useful for realtime decoding of closed captions so they
can be display along with mpeg2 frames.

Closed caption streams contain two major types of captions:

- POPON captions, which are buffered off-screen and displayed
  only after EOC (end of caption, aka display buffer)

- PAINTON/ROLLUP captions, which are written to the display as soon as
  they arrive.

In a typical real-time eia608 decoder, commands like EOC (end of
caption; display buffer), EDM (erase display memory) and EBM (erase
buffered memory) perform their expected functions as soon as the
commands are processed. This is implemented in the real_time branches
added in this commit.

Before this commit, and in the !real_time branches after this commit,
the decoder cleverly implements its own version of the decoder which is
specifically geared towards buffered decoding. It does so by actively
ignoring commands like EBM (erase buffered memory), and then re-using
the non-display buffer to hold the previous caption while the new one is
received. This is the opposite of the real-time decoder, which uses the
non-display buffer to hold the new caption while the display buffer is
still showing the current caption.

In addition to ignoring EBM, the buffered decoder also has custom
implementations for EDM and EOC. An EDM (erase display memory) command
flushes the existing contents before clearing the screen, and EOC
similarly always flushes the active buffer (the previous subtitle)
before flipping buffers.
---
 libavcodec/ccaption_dec.c | 80 ++-
 1 file changed, 72 insertions(+), 8 deletions(-)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index a9dfc94..6bdd754 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -116,6 +116,7 @@ struct Screen {
 
 typedef struct CCaptionSubContext {
 AVClass *class;
+int real_time;
 struct Screen screen[2];
 int active_screen;
 uint8_t cursor_row;
@@ -130,6 +131,8 @@ typedef struct CCaptionSubContext {
 /* visible screen time */
 int64_t startv_time;
 int64_t end_time;
+int screen_touched;
+int64_t last_real_time;
 char prev_cmd[2];
 /* buffer to store pkt data */
 AVBufferRef *pktbuf;
@@ -428,15 +431,33 @@ static void handle_edm(CCaptionSubContext *ctx, int64_t 
pts)
 {
 struct Screen *screen = ctx->screen + ctx->active_screen;
 
-reap_screen(ctx, pts);
+// In buffered mode, keep writing to screen until it is wiped.
+// Before wiping the display, capture contents to emit subtitle.
+if (!ctx->real_time)
+reap_screen(ctx, pts);
+
 screen->row_used = 0;
+
+// In realtime mode, emit an empty caption so the last one doesn't
+// stay on the screen.
+if (ctx->real_time)
+reap_screen(ctx, pts);
 }
 
 static void handle_eoc(CCaptionSubContext *ctx, int64_t pts)
 {
-handle_edm(ctx,pts);
+// In buffered mode, we wait til the *next* EOC and
+// reap what was already on the screen since the last EOC.
+if (!ctx->real_time)
+handle_edm(ctx,pts);
+
 ctx->active_screen = !ctx->active_screen;
 ctx->cursor_column = 0;
+
+// In realtime mode, we display the buffered contents (after
+// flipping the buffer to active above) as soon as EOC arrives.
+if (ctx->real_time)
+reap_screen(ctx, pts);
 }
 
 static void handle_delete_end_of_row(CCaptionSubContext *ctx, char hi, char lo)
@@ -458,6 +479,9 @@ static void handle_char(CCaptionSubContext *ctx, char hi, 
char lo, int64_t pts)
 }
 write_char(ctx, screen, 0);
 
+if (ctx->mode != CCMODE_POPON)
+ctx->screen_touched = 1;
+
 /* reset prev command since character can repeat */
 ctx->prev_cmd[0] = 0;
 ctx->prev_cmd[1] = 0;
@@ -507,10 +531,20 @@ static void process_cc608(CCaptionSubContext *ctx, 
int64_t pts, uint8_t hi, uint
 case 0x2d:
 /* carriage return */
 ff_dlog(ctx, "carriage return\n");
-reap_screen(ctx, pts);
+if (!ctx->real_time)
+reap_screen(ctx, pts);
 roll_up(ctx);
 ctx->cursor_column = 0;
 break;
+case 0x2e:
+/* erase buffered (non displayed) memory */
+// Only in realtime mode. In buffered mode, we re-use the inactive 
screen
+// for our own buffering.
+if (ctx->real_time) {
+struct Screen *screen = ctx->screen + !ctx->active_screen;
+screen->row_used = 0;
+}
+break;
 case 0x2f:
 /* end of caption */
 ff_dlog(ctx, "handle_eoc\n");
@@ -562,24 +596,54 @@ static int decode(AVCodecContext *avctx, void *data, int 
*got_sub, AVPacket *avp
 continue;
 else
 process_cc608(ctx, avpkt->pts, *(bptr + i + 

[FFmpeg-devel] [PATCH v2 6/9] lavc/ccaption_dec: clear all unused rows during rollup

2016-01-12 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

Sometimes rollup captions can move around the screen. This fixes "ghost"
captions from below the current rollup area from continuing to be
captured when a rollup moves higher up on the screen.
---
 libavcodec/ccaption_dec.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index 50625df..ff0735e 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -295,9 +295,11 @@ static void roll_up(CCaptionSubContext *ctx)
  */
 keep_lines = FFMIN(ctx->cursor_row + 1, ctx->rollup);
 
-for (i = 0; i < ctx->cursor_row - keep_lines; i++)
+for (i = 0; i < SCREEN_ROWS; i++) {
+if (i > (ctx->cursor_row - keep_lines) && i <= ctx->cursor_row)
+continue;
 UNSET_FLAG(screen->row_used, i);
-
+}
 
 for (i = 0; i < keep_lines && screen->row_used; i++) {
 const int i_row = ctx->cursor_row - keep_lines + i + 1;
@@ -307,8 +309,8 @@ static void roll_up(CCaptionSubContext *ctx)
 memcpy(screen->fonts[i_row], screen->fonts[i_row+1], SCREEN_COLUMNS);
 if (CHECK_FLAG(screen->row_used, i_row + 1))
 SET_FLAG(screen->row_used, i_row);
-
 }
+
 UNSET_FLAG(screen->row_used, ctx->cursor_row);
 }
 
-- 
2.5.3

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


Re: [FFmpeg-devel] [PATCH v2 1/9] lavc/ccaption_dec: flush context on seek

2016-01-12 Thread Aman Gupta
On Tue, Jan 12, 2016 at 5:42 PM, Aman Gupta <ffm...@tmm1.net> wrote:

> From: Aman Gupta <a...@tmm1.net>
>
> ---
>  libavcodec/ccaption_dec.c | 21 +
>  1 file changed, 21 insertions(+)
>
> diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
> index ca497e5..a9dfc94 100644
> --- a/libavcodec/ccaption_dec.c
> +++ b/libavcodec/ccaption_dec.c
> @@ -173,6 +173,26 @@ static av_cold int close_decoder(AVCodecContext
> *avctx)
>  return 0;
>  }
>
> +static void flush_decoder(AVCodecContext *avctx)
> +{
> +CCaptionSubContext *ctx = avctx->priv_data;
> +ctx->screen[0].row_used = 0;
> +ctx->screen[1].row_used = 0;
> +ctx->prev_cmd[0] = 0;
> +ctx->prev_cmd[1] = 0;
> +ctx->mode = CCMODE_ROLLUP;
> +ctx->rollup = 2;
> +ctx->cursor_row = 0;
> +ctx->cursor_column = 0;
> +ctx->cursor_font = 0;
> +ctx->cursor_color = 0;
> +ctx->active_screen = 0;
> +ctx->last_real_time = 0;
> +ctx->screen_touched = 0;
>

I messed up a rebase here... these two fields weren't introduced until the
next commit.

I've re-rolled the patchset here with a fix:
https://github.com/tmm1/ffmpeg/compare/master...upstream-cc.patch


> +ctx->buffer_changed = 0;
> +av_bprint_clear(>buffer);
> +}
> +
>  /**
>   * @param ctx closed caption context just to print log
>   */
> @@ -578,6 +598,7 @@ AVCodec ff_ccaption_decoder = {
>  .priv_data_size = sizeof(CCaptionSubContext),
>  .init   = init_decoder,
>  .close  = close_decoder,
> +.flush  = flush_decoder,
>  .decode = decode,
>  .priv_class = _dec_class,
>  };
> --
> 2.5.3
>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 1/3] avformat/mpegts: enhance logging in trace mode

2016-06-14 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

---
 libavformat/mpegts.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 4d1bc6d..6acb797 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -446,7 +446,7 @@ static MpegTSFilter *mpegts_open_filter(MpegTSContext *ts, 
unsigned int pid,
 {
 MpegTSFilter *filter;
 
-av_log(ts->stream, AV_LOG_TRACE, "Filter: pid=0x%x\n", pid);
+av_log(ts->stream, AV_LOG_TRACE, "Filter: pid=0x%x type=%d\n", pid, type);
 
 if (pid >= NB_PID_MAX || ts->pids[pid])
 return NULL;
@@ -1890,8 +1890,8 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t 
*section, int section_len
 if (skip_identical(h, tssf))
 return;
 
-av_log(ts->stream, AV_LOG_TRACE, "sid=0x%x sec_num=%d/%d version=%d\n",
-h->id, h->sec_num, h->last_sec_num, h->version);
+av_log(ts->stream, AV_LOG_TRACE, "sid=0x%x sec_num=%d/%d version=%d 
tid=%d\n",
+h->id, h->sec_num, h->last_sec_num, h->version, h->tid);
 
 if (h->tid != PMT_TID)
 return;
-- 
2.8.1

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


[FFmpeg-devel] [PATCH 2/3] avformat/utils: in debug mode, print number of streams found before avformat_find_stream_info()

2016-06-14 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

---
 libavformat/utils.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index 25c9a1b..494379a 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -3297,8 +3297,8 @@ int avformat_find_stream_info(AVFormatContext *ic, 
AVDictionary **options)
 }
 
 if (ic->pb)
-av_log(ic, AV_LOG_DEBUG, "Before avformat_find_stream_info() pos: 
%"PRId64" bytes read:%"PRId64" seeks:%d\n",
-   avio_tell(ic->pb), ic->pb->bytes_read, ic->pb->seek_count);
+av_log(ic, AV_LOG_DEBUG, "Before avformat_find_stream_info() pos: 
%"PRId64" bytes read:%"PRId64" seeks:%d nb_streams:%d\n",
+   avio_tell(ic->pb), ic->pb->bytes_read, ic->pb->seek_count, 
ic->nb_streams);
 
 for (i = 0; i < ic->nb_streams; i++) {
 const AVCodec *codec;
-- 
2.8.1

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


[FFmpeg-devel] [PATCH] avcodec/utils: ensure conversion from ass to ass_with_timings works with unknown durations

2016-06-14 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

the eia_608 decoder with real_time=1 emits subtitles with an unknown
duration, which were getting converted into ass incorrectly before this
patch.
---
 libavcodec/utils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 402a9d8..1047a74 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -2554,7 +2554,7 @@ static int convert_sub_to_old_ass_form(AVSubtitle *sub, 
const AVPacket *pkt, AVR
 
 /* rescale timing to ASS time base (ms) */
 ts_start = av_rescale_q(pkt->pts, tb, av_make_q(1, 100));
-if (pkt->duration != -1)
+if (pkt->duration != -1 && sub->end_display_time != -1)
 ts_duration = av_rescale_q(pkt->duration, tb, av_make_q(1, 100));
 sub->end_display_time = FFMAX(sub->end_display_time, 10 * ts_duration);
 
-- 
2.8.1

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


[FFmpeg-devel] [PATCH 3/3] avformat/mpegts: include stream types for mpeg2 and aac

2016-06-14 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

this removes the need to probe to discover mpeg2 and aac streams
inside mpegts containers, thus speeding up initial playback.
---
 libavformat/mpegts.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 6acb797..f46984d 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -700,6 +700,7 @@ static const StreamType ISO_types[] = {
 { 0x11, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_AAC_LATM   }, /* LATM syntax */
 #endif
 { 0x1b, AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_H264   },
+{ 0x1c, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_AAC},
 { 0x20, AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_H264   },
 { 0x21, AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_JPEG2000   },
 { 0x24, AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_HEVC   },
@@ -726,6 +727,7 @@ static const StreamType HDMV_types[] = {
 
 /* ATSC ? */
 static const StreamType MISC_types[] = {
+{ 0x80, AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_MPEG2VIDEO },
 { 0x81, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_AC3 },
 { 0x8a, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_DTS },
 { 0 },
-- 
2.8.1

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


[FFmpeg-devel] [PATCH 1/5] avcodec/ccaption_dec: change write_char() to void as return value is unused

2016-06-14 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

---
 libavcodec/ccaption_dec.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index 3b15149..a6d879e 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -315,7 +315,7 @@ static void flush_decoder(AVCodecContext *avctx)
 /**
  * @param ctx closed caption context just to print log
  */
-static int write_char(CCaptionSubContext *ctx, struct Screen *screen, char ch)
+static void write_char(CCaptionSubContext *ctx, struct Screen *screen, char ch)
 {
 uint8_t col = ctx->cursor_column;
 char *row = screen->characters[ctx->cursor_row];
@@ -328,16 +328,16 @@ static int write_char(CCaptionSubContext *ctx, struct 
Screen *screen, char ch)
 charset[col] = ctx->cursor_charset;
 ctx->cursor_charset = CCSET_BASIC_AMERICAN;
 if (ch) ctx->cursor_column++;
-return 0;
+return;
 }
 /* We have extra space at end only for null character */
 else if (col == SCREEN_COLUMNS && ch == 0) {
 row[col] = ch;
-return 0;
+return;
 }
 else {
 av_log(ctx, AV_LOG_WARNING, "Data Ignored since exceeding screen 
width\n");
-return AVERROR_INVALIDDATA;
+return;
 }
 }
 
-- 
2.8.1

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


[FFmpeg-devel] [PATCH 4/5] fate: update sub-cc tests for closed caption positioning

2016-06-14 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

---
 tests/ref/fate/sub-cc  |  4 +--
 tests/ref/fate/sub-cc-realtime | 60 +-
 2 files changed, 32 insertions(+), 32 deletions(-)

diff --git a/tests/ref/fate/sub-cc b/tests/ref/fate/sub-cc
index 0d5bc77..4cc02d1 100644
--- a/tests/ref/fate/sub-cc
+++ b/tests/ref/fate/sub-cc
@@ -10,5 +10,5 @@ Style: 
Default,Monospace,16,0,0,0,0,100,100,0,0,3,1,0,
 
 [Events]
 Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
-Dialogue: 0,0:00:12.36,0:00:40.83,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )
-Dialogue: 0,0:00:40.83,0:00:59.07,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Safety remains our number one
+Dialogue: 0,0:00:12.36,0:00:40.83,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} 
inaudible radio chatter{\i0} )
+Dialogue: 0,0:00:40.83,0:00:59.07,Default,,0,0,0,,{\an7}{\pos(38,28)}({\i1} 
inaudible radio chatter{\i0} )\N{\an7}{\pos(38,44)}>> Safety remains our number 
one
diff --git a/tests/ref/fate/sub-cc-realtime b/tests/ref/fate/sub-cc-realtime
index c9e6b6c..be800a4 100644
--- a/tests/ref/fate/sub-cc-realtime
+++ b/tests/ref/fate/sub-cc-realtime
@@ -10,33 +10,33 @@ Style: 
Default,Monospace,16,0,0,0,0,100,100,0,0,3,1,0,
 
 [Events]
 Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
-Dialogue: 0,0:00:14.14,9:59:59.99,Default,,0,0,0,,(
-Dialogue: 0,0:00:15.47,9:59:59.99,Default,,0,0,0,,({\i1} in
-Dialogue: 0,0:00:15.92,9:59:59.99,Default,,0,0,0,,({\i1} inau
-Dialogue: 0,0:00:16.36,9:59:59.99,Default,,0,0,0,,({\i1} inaudi
-Dialogue: 0,0:00:16.81,9:59:59.99,Default,,0,0,0,,({\i1} inaudibl
-Dialogue: 0,0:00:17.25,9:59:59.99,Default,,0,0,0,,({\i1} inaudible 
-Dialogue: 0,0:00:17.70,9:59:59.99,Default,,0,0,0,,({\i1} inaudible ra
-Dialogue: 0,0:00:18.14,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radi
-Dialogue: 0,0:00:18.59,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
-Dialogue: 0,0:00:19.03,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio ch
-Dialogue: 0,0:00:19.48,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio chat
-Dialogue: 0,0:00:19.92,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio chatte
-Dialogue: 0,0:00:20.36,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter
-Dialogue: 0,0:00:21.70,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )
-Dialogue: 0,0:00:42.61,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>>
-Dialogue: 0,0:00:43.05,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> S
-Dialogue: 0,0:00:43.50,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Saf
-Dialogue: 0,0:00:43.94,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Safet
-Dialogue: 0,0:00:44.39,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Safety 
-Dialogue: 0,0:00:44.83,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Safety re
-Dialogue: 0,0:00:45.28,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Safety rema
-Dialogue: 0,0:00:45.72,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Safety remain
-Dialogue: 0,0:00:46.17,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Safety remains 
-Dialogue: 0,0:00:46.61,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Safety remains ou
-Dialogue: 0,0:00:47.06,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Safety remains our 
-Dialogue: 0,0:00:47.50,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Safety remains our nu
-Dialogue: 0,0:00:47.95,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Safety remains our numb
-Dialogue: 0,0:00:48.39,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Safety remains our number
-Dialogue: 0,0:00:48.84,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Safety remains our number o
-Dialogue: 0,0:00:49.28,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio 
chatter{\i0} )\N>> Safety remains our number one
+Dialogue: 0,0:00:14.14,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}(
+Dialogue: 0,0:00:15.47,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} in
+Dialogue: 0,0:00:15.92,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} 
inau
+Dialogue: 0,0:00:16.36,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} 
inaudi
+Dialogue: 0,0:00:16.81,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} 
inaudibl
+Dialogue: 0,0:00:17.25,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} 
inaudible 
+Dialogue: 0,0:00:17.70,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} 
inaudible ra
+Dialogue: 0,0:00:18.14,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} 
inaudible radi
+Dialogue: 0,0:00:18.59,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} 

[FFmpeg-devel] [PATCH 3/5] avcodec/ccaption_dec: implement positioning for closed captions

2016-06-14 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

Positioning math is based on the guidelines in 
https://dvcs.w3.org/hg/text-tracks/raw-file/default/608toVTT/608toVTT.html#positioning-in-cea-608
---
 libavcodec/ccaption_dec.c | 29 ++---
 1 file changed, 26 insertions(+), 3 deletions(-)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index 0b4a061..16a7959 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -435,7 +435,7 @@ static void roll_up(CCaptionSubContext *ctx)
 
 static int capture_screen(CCaptionSubContext *ctx)
 {
-int i;
+int i, j, tab = 0;
 struct Screen *screen = ctx->screen + ctx->active_screen;
 enum cc_font prev_font = CCFONT_REGULAR;
 av_bprint_clear(>buffer);
@@ -444,15 +444,33 @@ static int capture_screen(CCaptionSubContext *ctx)
 {
 if (CHECK_FLAG(screen->row_used, i)) {
 const char *row = screen->characters[i];
+const char *charset = screen->charsets[i];
+j = 0;
+while (row[j] == ' ' && charset[j] == CCSET_BASIC_AMERICAN)
+j++;
+if (!tab || j < tab)
+tab = j;
+}
+}
+
+for (i = 0; screen->row_used && i < SCREEN_ROWS; i++)
+{
+if (CHECK_FLAG(screen->row_used, i)) {
+const char *row = screen->characters[i];
 const char *font = screen->fonts[i];
 const char *charset = screen->charsets[i];
 const char *override;
-int j = 0;
+int x, y, seen_char = 0;
+j = 0;
 
 /* skip leading space */
-while (row[j] == ' ' && charset[j] == CCSET_BASIC_AMERICAN)
+while (row[j] == ' ' && charset[j] == CCSET_BASIC_AMERICAN && j < 
tab)
 j++;
 
+x = ASS_DEFAULT_PLAYRESX * (0.1 + 0.0250 * j);
+y = ASS_DEFAULT_PLAYRESY * (0.1 + 0.0533 * i);
+av_bprintf(>buffer, "{\\an7}{\\pos(%d,%d)}", x, y);
+
 for (; j < SCREEN_COLUMNS; j++) {
 const char *e_tag = "", *s_tag = "";
 
@@ -487,9 +505,14 @@ static int capture_screen(CCaptionSubContext *ctx)
 override = charset_overrides[(int)charset[j]][(int)row[j]];
 if (override) {
 av_bprintf(>buffer, "%s%s%s", e_tag, s_tag, override);
+seen_char = 1;
+} else if (row[j] == ' ' && !seen_char) {
+av_bprintf(>buffer, "%s%s\\h", e_tag, s_tag);
 } else {
 av_bprintf(>buffer, "%s%s%c", e_tag, s_tag, row[j]);
+seen_char = 1;
 }
+
 }
 av_bprintf(>buffer, "\\N");
 }
-- 
2.8.1

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


[FFmpeg-devel] [PATCH 2/5] avcodec/ccaption_dec: implement tab offset commands

2016-06-14 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

---
 libavcodec/ccaption_dec.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index a6d879e..0b4a061 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -713,6 +713,11 @@ static void process_cc608(CCaptionSubContext *ctx, int64_t 
pts, uint8_t hi, uint
 /* Standard characters (always in pairs) */
 handle_char(ctx, hi, lo, pts);
 ctx->prev_cmd[0] = ctx->prev_cmd[1] = 0;
+} else if (hi == 0x17 && lo >= 0x21 && lo <= 0x23) {
+/* Tab offsets (spacing) */
+for (int i = 0; i < lo - 0x20; i++) {
+handle_char(ctx, ' ', 0, pts);
+}
 } else {
 /* Ignoring all other non data code */
 ff_dlog(ctx, "Unknown command 0x%hhx 0x%hhx\n", hi, lo);
-- 
2.8.1

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


[FFmpeg-devel] [PATCH 5/5] avcodec/ccaption_dec: default rollup to row 10

2016-06-14 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

This ensures that captions are written towards the bottom of the screen
when tuning into mid-stream. The row will be reset on the receipt of the
next PAC command. Row 10 was chosen as it corresponds to the value of
"0" in a PAC (see row_map in handle_pac()).
---
 libavcodec/ccaption_dec.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index 16a7959..4a2db31 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -261,6 +261,7 @@ static av_cold int init_decoder(AVCodecContext *avctx)
 /* taking by default roll up to 2 */
 ctx->mode = CCMODE_ROLLUP;
 ctx->rollup = 2;
+ctx->cursor_row = 10;
 ret = ff_ass_subtitle_header(avctx, "Monospace",
  ASS_DEFAULT_FONT_SIZE,
  ASS_DEFAULT_COLOR,
@@ -298,7 +299,7 @@ static void flush_decoder(AVCodecContext *avctx)
 ctx->prev_cmd[1] = 0;
 ctx->mode = CCMODE_ROLLUP;
 ctx->rollup = 2;
-ctx->cursor_row = 0;
+ctx->cursor_row = 10;
 ctx->cursor_column = 0;
 ctx->cursor_font = 0;
 ctx->cursor_color = 0;
-- 
2.8.1

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


Re: [FFmpeg-devel] [PATCH] added support for hardware assist H264 video encoding for the Raspberry Pi

2016-06-22 Thread Aman Gupta
This patch should fix the assertion failure you see:
https://github.com/FFmpeg/FFmpeg/commit/1087f0dc172a9adf779e41bf2dc82639fb04ebd4

Aman
On Sat, Jun 18, 2016 at 8:43 AM Amancio Hasty <aha...@gmail.com> wrote:

>
> > On Jun 16, 2016, at 11:16 AM, Aman Gupta <ffm...@tmm1.net> wrote:
> >
> > The patchset that was merged into libav is now available in ffmpeg as
> well:
> > https://github.com/FFmpeg/FFmpeg/blob/master/libavcodec/omx.c
> >
> > You can compile ffmpeg from the master branch
> > with --enable-omx --enable-omx-rpi
> >
> > Aman
> >
> > On Thu, Jun 16, 2016 at 2:16 AM, Amancio Hasty <aha...@gmail.com> wrote:
> >
> >>
> >>> On May 9, 2016, at 7:55 AM, Amancio Hasty <aha...@gmail.com> wrote:
> >>>
> >>> Hi,
> >>>
> >>> So what is the next step?
> >>>
> >>> If you want testers I suggest posting to ccrisan’s motionpie mailing
> >> list.
> >>> Cheers
> >>> Amancio
> >>>
> >>>
> >>>> On Mar 31, 2016, at 7:27 PM, Amancio Hasty <aha...@gmail.com> wrote:
> >>>>
> >>>> I am not a lawyer…
> >>>>
> >>>>
> >>>> I updated the patch.  vc264.c now has a the copyright notice embedded
> in
> >>>> a volatile global so if a binary is compiled against vc264.o , the
> >> copyright notice
> >>>> can be displayed by:
> >>>> strings ffmpeg | grep -i copyright
> >>>>
> >>>> LICENSE.md has been updated to include Broadcom’s copyright notice.
> >>>>
> >>>> A distribution of a  binary that includes vc264.o should include
> >> LICENSE.md and if
> >>>> that is missing,  the copyright notice can be displayed via the shell
> >>>> command ‘strings’ .
> >>>>
> >>>> Amancio
> >>>> 
> >>>>> On Mar 22, 2016, at 12:12 PM, Lou Logan <l...@lrcd.com> wrote:
> >>>>>
> >>>>> On Mon, 21 Mar 2016 20:07:01 -0700, Amancio Hasty wrote:
> >>>>>
> >>>>>> From 874a72eec2a78f4935fea091003e534b5f8d5413 Mon Sep 17 00:00:00
> 2001
> >>>>>> From: Amancio Hasty <aha...@gmail.com>
> >>>>>> Date: Mon, 21 Mar 2016 18:56:05 -0700
> >>>>>> Subject: [PATCH] added support for hardware assist H264  video
> >> encoding for
> >>>>>> the Raspberry Pi
> >>>>>>
> >>>>>> ---
> >>>>>> configure  |  12 ++
> >>>>>> libavcodec/Makefile|   1 +
> >>>>>> libavcodec/allcodecs.c |   2 +
> >>>>>> libavcodec/vc264.c | 387
> >> +
> >>>>>> 4 files changed, 402 insertions(+)
> >>>>>> create mode 100644 libavcodec/vc264.c
> >>>>>>
> >>>>> [...]
> >>>>>> diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
> >>>>>> index 2a25d66..3c7bd9b 100644
> >>>>>> --- a/libavcodec/allcodecs.c
> >>>>>> +++ b/libavcodec/allcodecs.c
> >>>>>> @@ -74,6 +74,7 @@ void avcodec_register_all(void)
> >>>>>>  initialized = 1;
> >>>>>>
> >>>>>
> >>>>> Nit: Whitespace on the line above should be removed.
> >>>>>
> >>>>> [...]
> >>>>>> --- /dev/null
> >>>>>> +++ b/libavcodec/vc264.c
> >>>>>> @@ -0,0 +1,387 @@
> >>>>>> +/*  H.264 hardware assist video encoding code taken from
> >>>>>> + * raspberry's os :
> >>>>>> + *   /opt/vc/src/hello_pi/hello_encode/encode.c
> >>>>>> + */
> >>>>>> +
> >>>>>> +/*
> >>>>>> +Copyright (c) 2012, Broadcom Europe Ltd
> >>>>>> +Copyright (c) 2012, Kalle Vahlman <zuh@iki>
> >>>>>> +Tuomas Kulve <tuo...@kulve.fi>
> >>>>>> +All rights reserved.
> >>>>>> +
> >>>>>> +Redistribution and use in source and binary forms, with or without
> >>>>>> +modification, are permitted provided that the following conditions
> >> are met:
> >>>>>> +* Redistributions of sour

Re: [FFmpeg-devel] [PATCH] added support for hardware assist H264 video encoding for the Raspberry Pi

2016-06-16 Thread Aman Gupta
The patchset that was merged into libav is now available in ffmpeg as well:
https://github.com/FFmpeg/FFmpeg/blob/master/libavcodec/omx.c

You can compile ffmpeg from the master branch
with --enable-omx --enable-omx-rpi

Aman

On Thu, Jun 16, 2016 at 2:16 AM, Amancio Hasty  wrote:

>
> > On May 9, 2016, at 7:55 AM, Amancio Hasty  wrote:
> >
> > Hi,
> >
> > So what is the next step?
> >
> > If you want testers I suggest posting to ccrisan’s motionpie mailing
> list.
> > Cheers
> > Amancio
> >
> >
> >> On Mar 31, 2016, at 7:27 PM, Amancio Hasty  wrote:
> >>
> >> I am not a lawyer…
> >>
> >>
> >> I updated the patch.  vc264.c now has a the copyright notice embedded in
> >> a volatile global so if a binary is compiled against vc264.o , the
> copyright notice
> >> can be displayed by:
> >> strings ffmpeg | grep -i copyright
> >>
> >> LICENSE.md has been updated to include Broadcom’s copyright notice.
> >>
> >> A distribution of a  binary that includes vc264.o should include
> LICENSE.md and if
> >> that is missing,  the copyright notice can be displayed via the shell
> >> command ‘strings’ .
> >>
> >> Amancio
> >> 
> >>> On Mar 22, 2016, at 12:12 PM, Lou Logan  wrote:
> >>>
> >>> On Mon, 21 Mar 2016 20:07:01 -0700, Amancio Hasty wrote:
> >>>
>  From 874a72eec2a78f4935fea091003e534b5f8d5413 Mon Sep 17 00:00:00 2001
>  From: Amancio Hasty 
>  Date: Mon, 21 Mar 2016 18:56:05 -0700
>  Subject: [PATCH] added support for hardware assist H264  video
> encoding for
>  the Raspberry Pi
> 
>  ---
>  configure  |  12 ++
>  libavcodec/Makefile|   1 +
>  libavcodec/allcodecs.c |   2 +
>  libavcodec/vc264.c | 387
> +
>  4 files changed, 402 insertions(+)
>  create mode 100644 libavcodec/vc264.c
> 
> >>> [...]
>  diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
>  index 2a25d66..3c7bd9b 100644
>  --- a/libavcodec/allcodecs.c
>  +++ b/libavcodec/allcodecs.c
>  @@ -74,6 +74,7 @@ void avcodec_register_all(void)
>    initialized = 1;
> 
> >>>
> >>> Nit: Whitespace on the line above should be removed.
> >>>
> >>> [...]
>  --- /dev/null
>  +++ b/libavcodec/vc264.c
>  @@ -0,0 +1,387 @@
>  +/*  H.264 hardware assist video encoding code taken from
>  + * raspberry's os :
>  + *   /opt/vc/src/hello_pi/hello_encode/encode.c
>  + */
>  +
>  +/*
>  +Copyright (c) 2012, Broadcom Europe Ltd
>  +Copyright (c) 2012, Kalle Vahlman 
>  +Tuomas Kulve 
>  +All rights reserved.
>  +
>  +Redistribution and use in source and binary forms, with or without
>  +modification, are permitted provided that the following conditions
> are met:
>  +* Redistributions of source code must retain the above copyright
>  +  notice, this list of conditions and the following disclaimer.
>  +  * Redistributions in binary form must reproduce the above
> copyright
>  +  notice, this list of conditions and the following disclaimer
> in the
>  +  documentation and/or other materials provided with the
> distribution.
>  +  * Neither the name of the copyright holder nor the
>  +  names of its contributors may be used to endorse or promote
> products
>  +  derived from this software without specific prior written
> permission.
>  +
>  +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
> "AS IS" AND
>  +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
> THE IMPLIED
>  +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
> ARE
>  +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
> BE LIABLE FOR ANY
>  +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
> DAMAGES
>  +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
> SERVICES;
>  +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
> CAUSED AND
>  +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
> OR TORT
>  +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
> USE OF THIS
>  +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
> >>>
> >>> I wonder if any of the above legalese is compatible. Granted, I see a
> >>> similar paragraph in "libavformat/aadec.c".
> >>>
>  + * ffmpeg driver for hardware assist video H.264 encoding using
> Broadcom's GPU
>  + * Copyright (C) 2016 Amancio Hasty aha...@gmail.com
>  + *
>  + *
>  + * This file is part of FFmpeg.
>  + *
>  + * FFmpeg is free software; you can redistribute it and/or
>  + * modify it under the terms of the GNU Lesser General Public
>  + * License as published by the Free Software Foundation; either
>  + * version 2.1 of the 

Re: [FFmpeg-devel] DVB Teletext to HLS Wbvtt Subtitles

2016-01-18 Thread Aman Gupta
ffmpeg has a webvtt encoder and decoder already. You can use this command
to convert mpeg2 closed captions into webvtt:

  ffmpeg -f lavfi -i 'movie=input.mpg[out0+subcc]' -map s out.vtt

Aman

On Mon, Jan 18, 2016 at 7:25 AM, Sébastien Cramatte 
wrote:

> Hi,
>
> We are working on an IPTv project using FFMPEG.
> Now we stream Live TV channels  in HLS format.
>
> We need to add Webvtt subtitles but as fare as I known Ffmpeg doesn't
> support it yet.
> We have make some lab test using CCExtractor +  Home made Webvtt  perl
> segmenter  and it works but  we are
> unable to sync subtitles with video/audio.
>
> We have seen that exists some Webvtt  patch for FFMpeg but I don't know if
> this code works or not.
>
> Basically we need to get DVB Mpeg2 TS  subtitles track  and   output it
> as  webvtt hls   directly with FFMpeg at same time as video / audios tracks.
> We are searching to hire a guy  that can achieve this job for us.
>
> Regards,
>
> Sebastien
>
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 1/2] lavc/ccaption_dec: do not ignore repeated character commands

2016-02-10 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

control codes in a cc stream can be repeated, and must be ignored.
however, repeated characters must not be ignored. the code attempted to
wipe prev_cmd in handle_char to allow repeated characters to be
processed, but prev_cmd would previously get reset _after_ handle_char()

i also moved the prev_cmd reset out from handle_char() so it can be
re-used for special character sets, which _must_ be ignored when
repeated.
---
 libavcodec/ccaption_dec.c | 19 ++-
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index 790f071..5fb2ec6 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -484,9 +484,6 @@ static void handle_char(CCaptionSubContext *ctx, char hi, 
char lo, int64_t pts)
 if (ctx->mode != CCMODE_POPON)
 ctx->screen_touched = 1;
 
-/* reset prev command since character can repeat */
-ctx->prev_cmd[0] = 0;
-ctx->prev_cmd[1] = 0;
 if (lo)
ff_dlog(ctx, "(%c,%c)\n", hi, lo);
 else
@@ -497,8 +494,15 @@ static void process_cc608(CCaptionSubContext *ctx, int64_t 
pts, uint8_t hi, uint
 {
 if (hi == ctx->prev_cmd[0] && lo == ctx->prev_cmd[1]) {
 /* ignore redundant command */
-} else if ( (hi == 0x10 && (lo >= 0x40 && lo <= 0x5f)) ||
-  ( (hi >= 0x11 && hi <= 0x17) && (lo >= 0x40 && lo <= 0x7f) ) ) {
+return;
+}
+
+/* set prev command */
+ctx->prev_cmd[0] = hi;
+ctx->prev_cmd[1] = lo;
+
+if ( (hi == 0x10 && (lo >= 0x40 && lo <= 0x5f)) ||
+   ( (hi >= 0x11 && hi <= 0x17) && (lo >= 0x40 && lo <= 0x7f) ) ) {
 handle_pac(ctx, hi, lo);
 } else if ( ( hi == 0x11 && lo >= 0x20 && lo <= 0x2f ) ||
 ( hi == 0x17 && lo >= 0x2e && lo <= 0x2f) ) {
@@ -559,14 +563,11 @@ static void process_cc608(CCaptionSubContext *ctx, 
int64_t pts, uint8_t hi, uint
 } else if (hi >= 0x20) {
 /* Standard characters (always in pairs) */
 handle_char(ctx, hi, lo, pts);
+ctx->prev_cmd[0] = ctx->prev_cmd[1] = 0;
 } else {
 /* Ignoring all other non data code */
 ff_dlog(ctx, "Unknown command 0x%hhx 0x%hhx\n", hi, lo);
 }
-
-/* set prev command */
-ctx->prev_cmd[0] = hi;
-ctx->prev_cmd[1] = lo;
 }
 
 static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket 
*avpkt)
-- 
2.5.3

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


[FFmpeg-devel] [PATCH 2/2] lavc/ccaption_dec: implement special and extended character sets

2016-02-10 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

---
 libavcodec/ccaption_dec.c | 151 +-
 1 file changed, 148 insertions(+), 3 deletions(-)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index 5fb2ec6..c22f939 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -63,6 +63,116 @@ enum cc_font {
 CCFONT_UNDERLINED_ITALICS,
 };
 
+enum cc_charset {
+CCSET_BASIC_AMERICAN,
+CCSET_SPECIAL_AMERICAN,
+CCSET_EXTENDED_SPANISH_FRENCH,
+CCSET_EXTENDED_PORTUGUESE_GERMAN,
+};
+
+static const char *charset_overrides[4][128] =
+{
+[CCSET_BASIC_AMERICAN] = {
+[0x27] = "’",
+[0x2a] = "á",
+[0x5c] = "é",
+[0x5e] = "í",
+[0x5f] = "ó",
+[0x60] = "ú",
+[0x7b] = "ç",
+[0x7c] = "÷",
+[0x7d] = "Ñ",
+[0x7e] = "ñ",
+[0x7f] = "\u2588"
+},
+[CCSET_SPECIAL_AMERICAN] = {
+[0x30] = "®",
+[0x31] = "°",
+[0x32] = "½",
+[0x33] = "¿",
+[0x34] = "™",
+[0x35] = "¢",
+[0x36] = "£",
+[0x37] = "♪",
+[0x38] = "à",
+[0x39] = "\u00A0",
+[0x3a] = "è",
+[0x3b] = "â",
+[0x3c] = "ê",
+[0x3d] = "î",
+[0x3e] = "ô",
+[0x3f] = "û",
+},
+[CCSET_EXTENDED_SPANISH_FRENCH] = {
+[0x20] = "Á",
+[0x21] = "É",
+[0x22] = "Ó",
+[0x23] = "Ú",
+[0x24] = "Ü",
+[0x25] = "ü",
+[0x26] = "´",
+[0x27] = "¡",
+[0x28] = "*",
+[0x29] = "‘",
+[0x2a] = "-",
+[0x2b] = "©",
+[0x2c] = "℠",
+[0x2d] = "·",
+[0x2e] = "“",
+[0x2f] = "”",
+[0x30] = "À",
+[0x31] = "Â",
+[0x32] = "Ç",
+[0x33] = "È",
+[0x34] = "Ê",
+[0x35] = "Ë",
+[0x36] = "ë",
+[0x37] = "Î",
+[0x38] = "Ï",
+[0x39] = "ï",
+[0x3a] = "Ô",
+[0x3b] = "Ù",
+[0x3c] = "ù",
+[0x3d] = "Û",
+[0x3e] = "«",
+[0x3f] = "»",
+},
+[CCSET_EXTENDED_PORTUGUESE_GERMAN] = {
+[0x20] = "Ã",
+[0x21] = "ã",
+[0x22] = "Í",
+[0x23] = "Ì",
+[0x24] = "ì",
+[0x25] = "Ò",
+[0x26] = "ò",
+[0x27] = "Õ",
+[0x28] = "õ",
+[0x29] = "{",
+[0x2a] = "}",
+[0x2b] = "\\",
+[0x2c] = "^",
+[0x2d] = "_",
+[0x2e] = "|",
+[0x2f] = "~",
+[0x30] = "Ä",
+[0x31] = "ä",
+[0x32] = "Ö",
+[0x33] = "ö",
+[0x34] = "ß",
+[0x35] = "¥",
+[0x36] = "¤",
+[0x37] = "¦",
+[0x38] = "Å",
+[0x39] = "å",
+[0x3a] = "Ø",
+[0x3b] = "ø",
+[0x3c] = "┌",
+[0x3d] = "┐",
+[0x3e] = "└",
+[0x3f] = "┘",
+},
+};
+
 static const unsigned char pac2_attribs[32][3] = // Color, font, ident
 {
 { CCCOL_WHITE,   CCFONT_REGULAR,0 },  // 0x40 || 0x60
@@ -103,6 +213,7 @@ static const unsigned char pac2_attribs[32][3] = // Color, 
font, ident
 struct Screen {
 /* +1 is used to compensate null character of string */
 uint8_t characters[SCREEN_ROWS][SCREEN_COLUMNS+1];
+uint8_t charsets[SCREEN_ROWS][SCREEN_COLUMNS+1];
 uint8_t colors[SCREEN_ROWS][SCREEN_COLUMNS+1];
 uint8_t fonts[SCREEN_ROWS][SCREEN_COLUMNS+1];
 /*
@@ -123,6 +234,7 @@ typedef struct CCaptionSubContext {
 uint8_t cursor_column;
 uint8_t cursor_color;
 uint8_t cursor_font;
+uint8_t cursor_charset;
 AVBPrint buffer;
 int buffer_changed;
 int rollup;
@@ -189,6 +301,7 @@ static void flush_decoder(AVCodecContext *avctx)
 ctx->cursor_column = 0;
 ctx->cursor_font = 0;
 ctx->cursor_color = 0;
+ctx->cursor_charset = 0;
 ctx->active_screen = 0;
 ctx->last_real_time = 0;
 ctx->screen_touched = 0;
@@ -204,10 +317,13 @@ static int write_char(CCaptionSubContext *ctx, struct 
Screen *screen, char ch)
 uint

[FFmpeg-devel] [PATCH v2 2/2] lavc/ccaption_dec: implement special and extended character sets

2016-02-13 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

character sets implemented as defined in 
https://en.wikipedia.org/wiki/EIA-608#Characters
---
 libavcodec/ccaption_dec.c | 152 +-
 1 file changed, 149 insertions(+), 3 deletions(-)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index 5fb2ec6..fc361b2 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -63,6 +63,116 @@ enum cc_font {
 CCFONT_UNDERLINED_ITALICS,
 };
 
+enum cc_charset {
+CCSET_BASIC_AMERICAN,
+CCSET_SPECIAL_AMERICAN,
+CCSET_EXTENDED_SPANISH_FRENCH_MISC,
+CCSET_EXTENDED_PORTUGUESE_GERMAN_DANISH,
+};
+
+static const char *charset_overrides[4][128] =
+{
+[CCSET_BASIC_AMERICAN] = {
+[0x27] = "’",
+[0x2a] = "á",
+[0x5c] = "é",
+[0x5e] = "í",
+[0x5f] = "ó",
+[0x60] = "ú",
+[0x7b] = "ç",
+[0x7c] = "÷",
+[0x7d] = "Ñ",
+[0x7e] = "ñ",
+[0x7f] = "\u2588"
+},
+[CCSET_SPECIAL_AMERICAN] = {
+[0x30] = "®",
+[0x31] = "°",
+[0x32] = "½",
+[0x33] = "¿",
+[0x34] = "™",
+[0x35] = "¢",
+[0x36] = "£",
+[0x37] = "♪",
+[0x38] = "à",
+[0x39] = "\u00A0",
+[0x3a] = "è",
+[0x3b] = "â",
+[0x3c] = "ê",
+[0x3d] = "î",
+[0x3e] = "ô",
+[0x3f] = "û",
+},
+[CCSET_EXTENDED_SPANISH_FRENCH_MISC] = {
+[0x20] = "Á",
+[0x21] = "É",
+[0x22] = "Ó",
+[0x23] = "Ú",
+[0x24] = "Ü",
+[0x25] = "ü",
+[0x26] = "´",
+[0x27] = "¡",
+[0x28] = "*",
+[0x29] = "‘",
+[0x2a] = "-",
+[0x2b] = "©",
+[0x2c] = "℠",
+[0x2d] = "·",
+[0x2e] = "“",
+[0x2f] = "”",
+[0x30] = "À",
+[0x31] = "Â",
+[0x32] = "Ç",
+[0x33] = "È",
+[0x34] = "Ê",
+[0x35] = "Ë",
+[0x36] = "ë",
+[0x37] = "Î",
+[0x38] = "Ï",
+[0x39] = "ï",
+[0x3a] = "Ô",
+[0x3b] = "Ù",
+[0x3c] = "ù",
+[0x3d] = "Û",
+[0x3e] = "«",
+[0x3f] = "»",
+},
+[CCSET_EXTENDED_PORTUGUESE_GERMAN_DANISH] = {
+[0x20] = "Ã",
+[0x21] = "ã",
+[0x22] = "Í",
+[0x23] = "Ì",
+[0x24] = "ì",
+[0x25] = "Ò",
+[0x26] = "ò",
+[0x27] = "Õ",
+[0x28] = "õ",
+[0x29] = "{",
+[0x2a] = "}",
+[0x2b] = "\\",
+[0x2c] = "^",
+[0x2d] = "_",
+[0x2e] = "|",
+[0x2f] = "~",
+[0x30] = "Ä",
+[0x31] = "ä",
+[0x32] = "Ö",
+[0x33] = "ö",
+[0x34] = "ß",
+[0x35] = "¥",
+[0x36] = "¤",
+[0x37] = "¦",
+[0x38] = "Å",
+[0x39] = "å",
+[0x3a] = "Ø",
+[0x3b] = "ø",
+[0x3c] = "┌",
+[0x3d] = "┐",
+[0x3e] = "└",
+[0x3f] = "┘",
+},
+};
+
 static const unsigned char pac2_attribs[32][3] = // Color, font, ident
 {
 { CCCOL_WHITE,   CCFONT_REGULAR,0 },  // 0x40 || 0x60
@@ -103,6 +213,7 @@ static const unsigned char pac2_attribs[32][3] = // Color, 
font, ident
 struct Screen {
 /* +1 is used to compensate null character of string */
 uint8_t characters[SCREEN_ROWS][SCREEN_COLUMNS+1];
+uint8_t charsets[SCREEN_ROWS][SCREEN_COLUMNS+1];
 uint8_t colors[SCREEN_ROWS][SCREEN_COLUMNS+1];
 uint8_t fonts[SCREEN_ROWS][SCREEN_COLUMNS+1];
 /*
@@ -123,6 +234,7 @@ typedef struct CCaptionSubContext {
 uint8_t cursor_column;
 uint8_t cursor_color;
 uint8_t cursor_font;
+uint8_t cursor_charset;
 AVBPrint buffer;
 int buffer_changed;
 int rollup;
@@ -189,6 +301,7 @@ static void flush_decoder(AVCodecContext *avctx)
 ctx->cursor_column = 0;
 ctx->cursor_font = 0;
 ctx->cursor_color = 0;
+ctx->cursor_charset = 0;
 ctx->active_screen = 0;
 ctx->last_real_time = 0;
 ctx->screen_touched = 0;
@@ 

[FFmpeg-devel] [PATCH v2 1/2] lavc/ccaption_dec: do not ignore repeated character commands

2016-02-13 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

control codes in a cc stream can be repeated, and must be ignored.
however, repeated characters must not be ignored. the code attempted to
wipe prev_cmd in handle_char to allow repeated characters to be
processed, but prev_cmd would previously get reset _after_ handle_char()

i also moved the prev_cmd reset out from handle_char() so it can be
re-used for special character sets, which _must_ be ignored when
repeated.
---
 libavcodec/ccaption_dec.c | 19 ++-
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index 790f071..5fb2ec6 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -484,9 +484,6 @@ static void handle_char(CCaptionSubContext *ctx, char hi, 
char lo, int64_t pts)
 if (ctx->mode != CCMODE_POPON)
 ctx->screen_touched = 1;
 
-/* reset prev command since character can repeat */
-ctx->prev_cmd[0] = 0;
-ctx->prev_cmd[1] = 0;
 if (lo)
ff_dlog(ctx, "(%c,%c)\n", hi, lo);
 else
@@ -497,8 +494,15 @@ static void process_cc608(CCaptionSubContext *ctx, int64_t 
pts, uint8_t hi, uint
 {
 if (hi == ctx->prev_cmd[0] && lo == ctx->prev_cmd[1]) {
 /* ignore redundant command */
-} else if ( (hi == 0x10 && (lo >= 0x40 && lo <= 0x5f)) ||
-  ( (hi >= 0x11 && hi <= 0x17) && (lo >= 0x40 && lo <= 0x7f) ) ) {
+return;
+}
+
+/* set prev command */
+ctx->prev_cmd[0] = hi;
+ctx->prev_cmd[1] = lo;
+
+if ( (hi == 0x10 && (lo >= 0x40 && lo <= 0x5f)) ||
+   ( (hi >= 0x11 && hi <= 0x17) && (lo >= 0x40 && lo <= 0x7f) ) ) {
 handle_pac(ctx, hi, lo);
 } else if ( ( hi == 0x11 && lo >= 0x20 && lo <= 0x2f ) ||
 ( hi == 0x17 && lo >= 0x2e && lo <= 0x2f) ) {
@@ -559,14 +563,11 @@ static void process_cc608(CCaptionSubContext *ctx, 
int64_t pts, uint8_t hi, uint
 } else if (hi >= 0x20) {
 /* Standard characters (always in pairs) */
 handle_char(ctx, hi, lo, pts);
+ctx->prev_cmd[0] = ctx->prev_cmd[1] = 0;
 } else {
 /* Ignoring all other non data code */
 ff_dlog(ctx, "Unknown command 0x%hhx 0x%hhx\n", hi, lo);
 }
-
-/* set prev command */
-ctx->prev_cmd[0] = hi;
-ctx->prev_cmd[1] = lo;
 }
 
 static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket 
*avpkt)
-- 
2.5.3

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


[FFmpeg-devel] [PATCH v3 2/2] lavc/ccaption_dec: implement special and extended character sets

2016-02-14 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

character sets implemented as defined in 
https://en.wikipedia.org/wiki/EIA-608#Characters
---
 libavcodec/ccaption_dec.c | 152 +-
 1 file changed, 149 insertions(+), 3 deletions(-)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index 5fb2ec6..237272c 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -63,6 +63,116 @@ enum cc_font {
 CCFONT_UNDERLINED_ITALICS,
 };
 
+enum cc_charset {
+CCSET_BASIC_AMERICAN,
+CCSET_SPECIAL_AMERICAN,
+CCSET_EXTENDED_SPANISH_FRENCH_MISC,
+CCSET_EXTENDED_PORTUGUESE_GERMAN_DANISH,
+};
+
+static const char *charset_overrides[4][128] =
+{
+[CCSET_BASIC_AMERICAN] = {
+[0x27] = "\u2019",
+[0x2a] = "\u00e1",
+[0x5c] = "\u00e9",
+[0x5e] = "\u00ed",
+[0x5f] = "\u00f3",
+[0x60] = "\u00fa",
+[0x7b] = "\u00e7",
+[0x7c] = "\u00f7",
+[0x7d] = "\u00d1",
+[0x7e] = "\u00f1",
+[0x7f] = "\u2588"
+},
+[CCSET_SPECIAL_AMERICAN] = {
+[0x30] = "\u00ae",
+[0x31] = "\u00b0",
+[0x32] = "\u00bd",
+[0x33] = "\u00bf",
+[0x34] = "\u2122",
+[0x35] = "\u00a2",
+[0x36] = "\u00a3",
+[0x37] = "\u266a",
+[0x38] = "\u00e0",
+[0x39] = "\u00A0",
+[0x3a] = "\u00e8",
+[0x3b] = "\u00e2",
+[0x3c] = "\u00ea",
+[0x3d] = "\u00ee",
+[0x3e] = "\u00f4",
+[0x3f] = "\u00fb",
+},
+[CCSET_EXTENDED_SPANISH_FRENCH_MISC] = {
+[0x20] = "\u00c1",
+[0x21] = "\u00c9",
+[0x22] = "\u00d3",
+[0x23] = "\u00da",
+[0x24] = "\u00dc",
+[0x25] = "\u00fc",
+[0x26] = "\u00b4",
+[0x27] = "\u00a1",
+[0x28] = "*",
+[0x29] = "\u2018",
+[0x2a] = "-",
+[0x2b] = "\u00a9",
+[0x2c] = "\u2120",
+[0x2d] = "\u00b7",
+[0x2e] = "\u201c",
+[0x2f] = "\u201d",
+[0x30] = "\u00c0",
+[0x31] = "\u00c2",
+[0x32] = "\u00c7",
+[0x33] = "\u00c8",
+[0x34] = "\u00ca",
+[0x35] = "\u00cb",
+[0x36] = "\u00eb",
+[0x37] = "\u00ce",
+[0x38] = "\u00cf",
+[0x39] = "\u00ef",
+[0x3a] = "\u00d4",
+[0x3b] = "\u00d9",
+[0x3c] = "\u00f9",
+[0x3d] = "\u00db",
+[0x3e] = "\u00ab",
+[0x3f] = "\u00bb",
+},
+[CCSET_EXTENDED_PORTUGUESE_GERMAN_DANISH] = {
+[0x20] = "\u00c3",
+[0x21] = "\u00e3",
+[0x22] = "\u00cd",
+[0x23] = "\u00cc",
+[0x24] = "\u00ec",
+[0x25] = "\u00d2",
+[0x26] = "\u00f2",
+[0x27] = "\u00d5",
+[0x28] = "\u00f5",
+[0x29] = "{",
+[0x2a] = "}",
+[0x2b] = "\\",
+[0x2c] = "^",
+[0x2d] = "_",
+[0x2e] = "|",
+[0x2f] = "~",
+[0x30] = "\u00c4",
+[0x31] = "\u00e4",
+[0x32] = "\u00d6",
+[0x33] = "\u00f6",
+[0x34] = "\u00df",
+[0x35] = "\u00a5",
+[0x36] = "\u00a4",
+[0x37] = "\u00a6",
+[0x38] = "\u00c5",
+[0x39] = "\u00e5",
+[0x3a] = "\u00d8",
+[0x3b] = "\u00f8",
+[0x3c] = "\u250c",
+[0x3d] = "\u2510",
+[0x3e] = "\u2514",
+[0x3f] = "\u2518",
+},
+};
+
 static const unsigned char pac2_attribs[32][3] = // Color, font, ident
 {
 { CCCOL_WHITE,   CCFONT_REGULAR,0 },  // 0x40 || 0x60
@@ -103,6 +213,7 @@ static const unsigned char pac2_attribs[32][3] = // Color, 
font, ident
 struct Screen {
 /* +1 is used to compensate null character of string */
 uint8_t characters[SCREEN_ROWS][SCREEN_COLUMNS+1];
+uint8_t charsets[SCREEN_ROWS][SCREEN_COLUMNS+1];
 uint8_t colors[SCREEN_ROWS][SCREEN_COLUMNS+1];
 uint8_t fonts[SCREEN_ROWS][SCREEN_COLUMNS+1];
 /*
@@ -123,6 +234,7 @@ typedef struct CCaptionSubContext {
 uint8_t cursor_column;
 uint8_t cursor_color;
 ui

[FFmpeg-devel] [PATCH v3 1/2] lavc/ccaption_dec: do not ignore repeated character commands

2016-02-14 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

control codes in a cc stream can be repeated, and must be ignored.
however, repeated characters must not be ignored. the code attempted to
wipe prev_cmd in handle_char to allow repeated characters to be
processed, but prev_cmd would previously get reset _after_ handle_char()

i also moved the prev_cmd reset out from handle_char() so it can be
re-used for special character sets, which _must_ be ignored when
repeated.
---
 libavcodec/ccaption_dec.c | 19 ++-
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index 790f071..5fb2ec6 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -484,9 +484,6 @@ static void handle_char(CCaptionSubContext *ctx, char hi, 
char lo, int64_t pts)
 if (ctx->mode != CCMODE_POPON)
 ctx->screen_touched = 1;
 
-/* reset prev command since character can repeat */
-ctx->prev_cmd[0] = 0;
-ctx->prev_cmd[1] = 0;
 if (lo)
ff_dlog(ctx, "(%c,%c)\n", hi, lo);
 else
@@ -497,8 +494,15 @@ static void process_cc608(CCaptionSubContext *ctx, int64_t 
pts, uint8_t hi, uint
 {
 if (hi == ctx->prev_cmd[0] && lo == ctx->prev_cmd[1]) {
 /* ignore redundant command */
-} else if ( (hi == 0x10 && (lo >= 0x40 && lo <= 0x5f)) ||
-  ( (hi >= 0x11 && hi <= 0x17) && (lo >= 0x40 && lo <= 0x7f) ) ) {
+return;
+}
+
+/* set prev command */
+ctx->prev_cmd[0] = hi;
+ctx->prev_cmd[1] = lo;
+
+if ( (hi == 0x10 && (lo >= 0x40 && lo <= 0x5f)) ||
+   ( (hi >= 0x11 && hi <= 0x17) && (lo >= 0x40 && lo <= 0x7f) ) ) {
 handle_pac(ctx, hi, lo);
 } else if ( ( hi == 0x11 && lo >= 0x20 && lo <= 0x2f ) ||
 ( hi == 0x17 && lo >= 0x2e && lo <= 0x2f) ) {
@@ -559,14 +563,11 @@ static void process_cc608(CCaptionSubContext *ctx, 
int64_t pts, uint8_t hi, uint
 } else if (hi >= 0x20) {
 /* Standard characters (always in pairs) */
 handle_char(ctx, hi, lo, pts);
+ctx->prev_cmd[0] = ctx->prev_cmd[1] = 0;
 } else {
 /* Ignoring all other non data code */
 ff_dlog(ctx, "Unknown command 0x%hhx 0x%hhx\n", hi, lo);
 }
-
-/* set prev command */
-ctx->prev_cmd[0] = hi;
-ctx->prev_cmd[1] = lo;
 }
 
 static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket 
*avpkt)
-- 
2.5.3

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


Re: [FFmpeg-devel] [PATCH] added support for hardware assist H264 video encoding for the Raspberry Pi

2016-05-05 Thread Aman Gupta
I confirmed that this patch works on the rpi3, when compiling ffmpeg with
`--enable-omx --enable-omx-rpi` and using `ffmpeg -v:c h264_omx`

I had to make some minor changes for ffmpeg compatibility which I pushed to
my rebase branch.

Aman

On Thu, Apr 21, 2016 at 10:14 AM, Amancio Hasty <aha...@gmail.com> wrote:

> Curious,
>
> Do these patches work with ffmpeg running on RPi?
>
> Thanks,
> Amancio
>
> > On Apr 19, 2016, at 12:00 PM, Aman Gupta <ffm...@tmm1.net> wrote:
> >
> > On Thu, Apr 7, 2016 at 3:03 AM, Mark Thompson <s...@jkqxz.net  s...@jkqxz.net>> wrote:
> >
> >> On 06/04/16 14:25, Amancio Hasty wrote:
> >>>
> >>>> On Apr 6, 2016, at 3:42 AM, wm4 <nfx...@googlemail.com> wrote:
> >>>>
> >>>> On Wed, 6 Apr 2016 02:56:49 -0700
> >>>> Amancio Hasty <aha...@gmail.com> wrote:
> >>>>
> >>>>> If you think is better and it works , are there any plans to
> >> incorporate such an older patch?
> >>>>
> >>>> I asked the author - he's looking into getting it ready for merge.
> >>>>
> >>>
> >>> Curious, any reasonable estimate of when the merge is going to happen?
> >>>
> >>
> >> https://lists.libav.org/pipermail/libav-devel/2016-April/076042.html
> >> https://lists.libav.org/pipermail/libav-devel/2016-April/076040.html
> >> https://lists.libav.org/pipermail/libav-devel/2016-April/076041.html
> >>
> >> Please test/review!  (Make sure it works for you and has the features
> you
> >> want,
> >> at least.)
> >>
> >
> > Looks like these patches were merged into libav already. I've rebased
> them
> > on top of ffmpeg master here:
> > https://github.com/FFmpeg/FFmpeg/compare/master...tmm1:rebase-omx.patch
> <https://github.com/FFmpeg/FFmpeg/compare/master...tmm1:rebase-omx.patch>
> >
> > Aman
> >
> >
> >>
> >> ___
> >> ffmpeg-devel mailing list
> >> ffmpeg-devel@ffmpeg.org <mailto:ffmpeg-devel@ffmpeg.org>
> >> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel <
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel>
> >>
> > ___
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org <mailto:ffmpeg-devel@ffmpeg.org>
> > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel <
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH v3 1/2] lavc/ccaption_dec: do not ignore repeated character commands

2016-04-19 Thread Aman Gupta
This is a tricky one.. I tried your sample in VLC, and it has the same
issue as the latest version of ffmpeg.

The previous behavior of ffmpeg can be restored with the following patch:

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index 3b15149..9eff843 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -712,7 +712,6 @@ static void process_cc608(CCaptionSubContext *ctx,
int64_t pts, uint8_t hi, uint
 } else if (hi >= 0x20) {
 /* Standard characters (always in pairs) */
 handle_char(ctx, hi, lo, pts);
-ctx->prev_cmd[0] = ctx->prev_cmd[1] = 0;
 } else {
 /* Ignoring all other non data code */
 ff_dlog(ctx, "Unknown command 0x%hhx 0x%hhx\n", hi, lo);

However, I've encountered a number of samples where the same character is
legitimately repeated and is not supposed to be skipped.

For instance, the samples on
http://hackipedia.org/ATSC/EIA-608%20samples/EIA-608%20character%20set%20test/
(https://www.youtube.com/watch?v=8TZLxPdC3hk) repeat the character "."
multiple times to show correct spacing.

Similarly, there are an endless number of words in the english language
with repeated characters, such as "ss" in endless and "rr" in correct.

It is unclear to me how the decoder is supposed to distinguish between
characters that are meant to be displayed twice, vs streams that repeat
every ascii character unconditionally.

Further, in your sample it appears that every command is repeated not twice
(as is common in many streams for special character sets and other command,
see
http://hackipedia.org/ATSC/EIA-608%20samples/EIA-608%20character%20set%20test/README.TXT),
but three times.

Aman

On Mon, Apr 18, 2016 at 1:01 PM, Aman Gupta <a...@tmm1.net> wrote:

> Please send me the sample and I will try to fix the issue.
>
> Aman
>
> On Mon, Apr 18, 2016 at 1:22 PM Thierry Foucu <tfo...@gmail.com> wrote:
>
>> Hi all
>>
>> On Sun, Feb 14, 2016 at 6:11 PM, Aman Gupta <ffm...@tmm1.net> wrote:
>>
>>> From: Aman Gupta <a...@tmm1.net>
>>>
>>> control codes in a cc stream can be repeated, and must be ignored.
>>> however, repeated characters must not be ignored. the code attempted to
>>> wipe prev_cmd in handle_char to allow repeated characters to be
>>> processed, but prev_cmd would previously get reset _after_ handle_char()
>>>
>>> i also moved the prev_cmd reset out from handle_char() so it can be
>>> re-used for special character sets, which _must_ be ignored when
>>> repeated.
>>> ---
>>>  libavcodec/ccaption_dec.c | 19 ++-
>>>  1 file changed, 10 insertions(+), 9 deletions(-)
>>>
>>> diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
>>> index 790f071..5fb2ec6 100644
>>> --- a/libavcodec/ccaption_dec.c
>>> +++ b/libavcodec/ccaption_dec.c
>>> @@ -484,9 +484,6 @@ static void handle_char(CCaptionSubContext *ctx,
>>> char hi, char lo, int64_t pts)
>>>  if (ctx->mode != CCMODE_POPON)
>>>  ctx->screen_touched = 1;
>>>
>>> -/* reset prev command since character can repeat */
>>> -ctx->prev_cmd[0] = 0;
>>> -ctx->prev_cmd[1] = 0;
>>>  if (lo)
>>> ff_dlog(ctx, "(%c,%c)\n", hi, lo);
>>>  else
>>> @@ -497,8 +494,15 @@ static void process_cc608(CCaptionSubContext *ctx,
>>> int64_t pts, uint8_t hi, uint
>>>  {
>>>  if (hi == ctx->prev_cmd[0] && lo == ctx->prev_cmd[1]) {
>>>  /* ignore redundant command */
>>> -} else if ( (hi == 0x10 && (lo >= 0x40 && lo <= 0x5f)) ||
>>> -  ( (hi >= 0x11 && hi <= 0x17) && (lo >= 0x40 && lo <=
>>> 0x7f) ) ) {
>>> +return;
>>> +}
>>> +
>>> +/* set prev command */
>>> +ctx->prev_cmd[0] = hi;
>>> +ctx->prev_cmd[1] = lo;
>>> +
>>> +if ( (hi == 0x10 && (lo >= 0x40 && lo <= 0x5f)) ||
>>> +   ( (hi >= 0x11 && hi <= 0x17) && (lo >= 0x40 && lo <= 0x7f) ) ) {
>>>  handle_pac(ctx, hi, lo);
>>>  } else if ( ( hi == 0x11 && lo >= 0x20 && lo <= 0x2f ) ||
>>>  ( hi == 0x17 && lo >= 0x2e && lo <= 0x2f) ) {
>>> @@ -559,14 +563,11 @@ static void process_cc608(CCaptionSubContext *ctx,
>>> int64_t pts, uint8_t hi, uint
>>>  } else if (hi >= 0x20) {
>>>  /* Standard cha

Re: [FFmpeg-devel] [PATCH v3 1/2] lavc/ccaption_dec: do not ignore repeated character commands

2016-04-18 Thread Aman Gupta
Please send me the sample and I will try to fix the issue.

Aman
On Mon, Apr 18, 2016 at 1:22 PM Thierry Foucu <tfo...@gmail.com> wrote:

> Hi all
>
> On Sun, Feb 14, 2016 at 6:11 PM, Aman Gupta <ffm...@tmm1.net> wrote:
>
>> From: Aman Gupta <a...@tmm1.net>
>>
>> control codes in a cc stream can be repeated, and must be ignored.
>> however, repeated characters must not be ignored. the code attempted to
>> wipe prev_cmd in handle_char to allow repeated characters to be
>> processed, but prev_cmd would previously get reset _after_ handle_char()
>>
>> i also moved the prev_cmd reset out from handle_char() so it can be
>> re-used for special character sets, which _must_ be ignored when
>> repeated.
>> ---
>>  libavcodec/ccaption_dec.c | 19 ++-
>>  1 file changed, 10 insertions(+), 9 deletions(-)
>>
>> diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
>> index 790f071..5fb2ec6 100644
>> --- a/libavcodec/ccaption_dec.c
>> +++ b/libavcodec/ccaption_dec.c
>> @@ -484,9 +484,6 @@ static void handle_char(CCaptionSubContext *ctx, char
>> hi, char lo, int64_t pts)
>>  if (ctx->mode != CCMODE_POPON)
>>  ctx->screen_touched = 1;
>>
>> -/* reset prev command since character can repeat */
>> -ctx->prev_cmd[0] = 0;
>> -ctx->prev_cmd[1] = 0;
>>  if (lo)
>> ff_dlog(ctx, "(%c,%c)\n", hi, lo);
>>  else
>> @@ -497,8 +494,15 @@ static void process_cc608(CCaptionSubContext *ctx,
>> int64_t pts, uint8_t hi, uint
>>  {
>>  if (hi == ctx->prev_cmd[0] && lo == ctx->prev_cmd[1]) {
>>  /* ignore redundant command */
>> -} else if ( (hi == 0x10 && (lo >= 0x40 && lo <= 0x5f)) ||
>> -  ( (hi >= 0x11 && hi <= 0x17) && (lo >= 0x40 && lo <= 0x7f)
>> ) ) {
>> +return;
>> +}
>> +
>> +/* set prev command */
>> +ctx->prev_cmd[0] = hi;
>> +ctx->prev_cmd[1] = lo;
>> +
>> +if ( (hi == 0x10 && (lo >= 0x40 && lo <= 0x5f)) ||
>> +   ( (hi >= 0x11 && hi <= 0x17) && (lo >= 0x40 && lo <= 0x7f) ) ) {
>>  handle_pac(ctx, hi, lo);
>>  } else if ( ( hi == 0x11 && lo >= 0x20 && lo <= 0x2f ) ||
>>  ( hi == 0x17 && lo >= 0x2e && lo <= 0x2f) ) {
>> @@ -559,14 +563,11 @@ static void process_cc608(CCaptionSubContext *ctx,
>> int64_t pts, uint8_t hi, uint
>>  } else if (hi >= 0x20) {
>>  /* Standard characters (always in pairs) */
>>  handle_char(ctx, hi, lo, pts);
>> +ctx->prev_cmd[0] = ctx->prev_cmd[1] = 0;
>>  } else {
>>  /* Ignoring all other non data code */
>>  ff_dlog(ctx, "Unknown command 0x%hhx 0x%hhx\n", hi, lo);
>>  }
>> -
>> -/* set prev command */
>> -ctx->prev_cmd[0] = hi;
>> -ctx->prev_cmd[1] = lo;
>>  }
>>
>>  static int decode(AVCodecContext *avctx, void *data, int *got_sub,
>> AVPacket *avpkt)
>> --
>> 2.5.3
>>
>>
> This commit seems to break some US broadcast CC decoding. (I can provide a
> 15MB sample file if needed)
>
> Before this commit:
> ffmpeg -f lavfi -i "movie=IhedxzUUxNo.ts[out0+subcc]" -map s "ts.srt"
> cat ts.srt
> 1
> 00:00:01,035 --> 00:00:02,035
> FAR-RANGING IMPACT PLACES IN THE
>
> 2
> 00:00:02,036 --> 00:00:04,466
> FAR-RANGING IMPACT PLACES IN THE
> CHURCH AND AT THE LEVEL OF
>
> 3
> 00:00:04,471 --> 00:00:06,811
> CHURCH AND AT THE LEVEL OF
> POLICY ALL ACROSS THE GLOBE.
>
> 4
> 00:00:06,807 --> 00:00:08,537
> POLICY ALL ACROSS THE GLOBE.
> CERTAINLY IN THE AREA OF
>
> 5
> 00:00:08,542 --> 00:00:10,382
> CERTAINLY IN THE AREA OF
> PASTORAL CARE, I HOPE THAT IT
>
> 6
> 00:00:10,377 --> 00:00:14,677
> PASTORAL CARE, I HOPE THAT IT
> WILL LEAD TO LESS DOGMATICTI
>
> 7
> 00:00:14,682 --> 00:00:16,352
> WILL LEAD TO LESS DOGMATICTI
> INTERACTION WITH PEOPLE ACROSS A
>
> 8
> 00:00:16,350 --> 00:00:16,920
> INTERACTION WITH PEOPLE ACROSS A
> THE BOARD.
>
> 9
> 00:00:16,917 --> 00:00:18,287
> THE BOARD.
> I HOPE THAT, YOU KNOW, THERE'S
>
> 10
> 00:00:18,285 --> 00:00:20,785
> I HOPE THAT, YOU KNOW, THERE'S
> MORE OF A SENSE THAT THE CHURCH
>
>
>
> After that commit,
> cat ts.srt
> 1
> 00:00:01,035 --> 00:00:02

Re: [FFmpeg-devel] Change bitrate on-the-fly

2016-08-01 Thread Aman Gupta
I would find your patch useful and am looking forward to reviewing
it. Using a socket isn't a bad way to do it IMHO- it's portable and allows
easy integration from any language.

Another option would be to extend the existing ffmpeg interactive mode to
handle your new command. Currently ffmpeg allows sending commands to
filters, but tbh it's pretty confusing to use and not well documented.

I'd love to see a generic control interface for ffmpeg that was easy to use
programatically, and could handle simple commands like "pause", "resume",
"seek ", etc.

Aman

On Sun, Jul 31, 2016 at 9:32 AM, Llorx  wrote:

> Hi,
>
> About 1 or 2 years ago I had written an addition for ffmpeg to change the
> video bitrate while ffmpeg is running. The way I've done it is by listening
> to a UDP socket for an int32, and each time a 4 byte packet enters, changes
> the bitrate, taking effect instantly. Works like a charm, and the UDP way
> fits my needings without problems. I needed it because currently I have a
> business that requires streaming video in some difficult and
> bandwith-changing environments, so I have a thrid party program than
> launchs ffmpeg and analyzes the packets sent to detect bandwidth
> alterations, changing the bitrate accordingly.
>
> Now I would like to share it with the community, as I had some messages
> from some users telling me to release it (As I posted a question about this
> on Stack Overflow).
>
> I know that the UDP thing is a bit hackish, so I would like to ask you,
> ffmpeg masters, how do you consider that this can be applied in a more
> "professional" way. I thought that instead of listening to a UDP socket
> (configurable at launch time with a parameter), I can use named pipes,
> memory mapped files or simply process signaling. The last method is only
> available on Unix with SA_SIGINFO. Windows can't handle such signal
> behaviour.
>
> What do you think is the best option?
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] avcodec/utils: only warn when passed invalid lowres value

2016-08-04 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

This makes it easier to use the lowres option when dealing with input
files in different codecs. If the codec doesn't support lowres=1 for
instance, it will throw a warning and use lowres=0 instead of erroring
out completely.
---
 libavcodec/utils.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index f7adb52..783f62c 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -1389,10 +1389,9 @@ int attribute_align_arg avcodec_open2(AVCodecContext 
*avctx, const AVCodec *code
 avctx->thread_count = 1;
 
 if (avctx->codec->max_lowres < avctx->lowres || avctx->lowres < 0) {
-av_log(avctx, AV_LOG_ERROR, "The maximum value for lowres supported by 
the decoder is %d\n",
+av_log(avctx, AV_LOG_WARNING, "The maximum value for lowres supported 
by the decoder is %d\n",
avctx->codec->max_lowres);
-ret = AVERROR(EINVAL);
-goto free_and_end;
+avctx->lowres = avctx->codec->max_lowres;
 }
 
 #if FF_API_VISMV
-- 
2.8.1

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


[FFmpeg-devel] [PATCH v3] avfilter/scale: refactor common code for scaling height/width expressions

2017-02-01 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

Implements support for height/width expressions in vf_scale_vaapi,
by refactoring common code into a new libavfilter/scale.c
---
 libavfilter/Makefile |   8 +--
 libavfilter/scale.c  | 152 +++
 libavfilter/scale.h  |  28 
 libavfilter/vf_scale.c   | 109 +++
 libavfilter/vf_scale_npp.c   |  93 +++---
 libavfilter/vf_scale_vaapi.c |  19 --
 6 files changed, 216 insertions(+), 193 deletions(-)
 create mode 100644 libavfilter/scale.c
 create mode 100644 libavfilter/scale.h

diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 68a94be..3231f08 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -257,10 +257,10 @@ OBJS-$(CONFIG_REPEATFIELDS_FILTER)   += 
vf_repeatfields.o
 OBJS-$(CONFIG_REVERSE_FILTER)+= f_reverse.o
 OBJS-$(CONFIG_ROTATE_FILTER) += vf_rotate.o
 OBJS-$(CONFIG_SAB_FILTER)+= vf_sab.o
-OBJS-$(CONFIG_SCALE_FILTER)  += vf_scale.o
-OBJS-$(CONFIG_SCALE_NPP_FILTER)  += vf_scale_npp.o
-OBJS-$(CONFIG_SCALE_VAAPI_FILTER)+= vf_scale_vaapi.o
-OBJS-$(CONFIG_SCALE2REF_FILTER)  += vf_scale.o
+OBJS-$(CONFIG_SCALE_FILTER)  += vf_scale.o scale.o
+OBJS-$(CONFIG_SCALE_NPP_FILTER)  += vf_scale_npp.o scale.o
+OBJS-$(CONFIG_SCALE_VAAPI_FILTER)+= vf_scale_vaapi.o scale.o
+OBJS-$(CONFIG_SCALE2REF_FILTER)  += vf_scale.o scale.o
 OBJS-$(CONFIG_SELECT_FILTER) += f_select.o
 OBJS-$(CONFIG_SELECTIVECOLOR_FILTER) += vf_selectivecolor.o
 OBJS-$(CONFIG_SENDCMD_FILTER)+= f_sendcmd.o
diff --git a/libavfilter/scale.c b/libavfilter/scale.c
new file mode 100644
index 000..50cd442
--- /dev/null
+++ b/libavfilter/scale.c
@@ -0,0 +1,152 @@
+/*
+ * Copyright (c) 2007 Bobby Bingham
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include 
+#include "scale.h"
+#include "libavutil/eval.h"
+#include "libavutil/mathematics.h"
+#include "libavutil/pixdesc.h"
+
+static const char *const var_names[] = {
+"PI",
+"PHI",
+"E",
+"in_w",   "iw",
+"in_h",   "ih",
+"out_w",  "ow",
+"out_h",  "oh",
+"a",
+"sar",
+"dar",
+"hsub",
+"vsub",
+"ohsub",
+"ovsub",
+NULL
+};
+
+enum var_name {
+VAR_PI,
+VAR_PHI,
+VAR_E,
+VAR_IN_W,   VAR_IW,
+VAR_IN_H,   VAR_IH,
+VAR_OUT_W,  VAR_OW,
+VAR_OUT_H,  VAR_OH,
+VAR_A,
+VAR_SAR,
+VAR_DAR,
+VAR_HSUB,
+VAR_VSUB,
+VAR_OHSUB,
+VAR_OVSUB,
+VARS_NB
+};
+
+int ff_scale_eval_dimensions(void *log_ctx,
+const char *w_expr, const char *h_expr,
+AVFilterLink *inlink, AVFilterLink *outlink,
+int *ret_w, int *ret_h)
+{
+const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
+const AVPixFmtDescriptor *out_desc = av_pix_fmt_desc_get(outlink->format);
+const char *expr;
+int w, h;
+int factor_w, factor_h;
+int eval_w, eval_h;
+int ret;
+double var_values[VARS_NB], res;
+
+var_values[VAR_PI]= M_PI;
+var_values[VAR_PHI]   = M_PHI;
+var_values[VAR_E] = M_E;
+var_values[VAR_IN_W]  = var_values[VAR_IW] = inlink->w;
+var_values[VAR_IN_H]  = var_values[VAR_IH] = inlink->h;
+var_values[VAR_OUT_W] = var_values[VAR_OW] = NAN;
+var_values[VAR_OUT_H] = var_values[VAR_OH] = NAN;
+var_values[VAR_A] = (double) inlink->w / inlink->h;
+var_values[VAR_SAR]   = inlink->sample_aspect_ratio.num ?
+(double) inlink->sample_aspect_ratio.num / 
inlink->sample_aspect_ratio.den : 1;
+var_values[VAR_DAR]   = var_values[VAR_A] * var_values[VAR_SAR];
+var_values[VAR_HSUB]  = 1 << desc->log2_chroma_w;
+var_values[VAR_VSUB]  = 1 << desc->log2_chroma_h;
+var_values[VAR_OHSUB] = 1 << out_desc->log2_chroma_w;
+var_values[VAR_OVSUB] = 1 <

[FFmpeg-devel] [PATCH v2] avfilter/scale: refactor common code for scaling height/width expressions

2017-02-01 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

Implements support for height/width expressions in vf_scale_vaapi,
by refactoring common code into a new libavfilter/scale.c
---
 libavfilter/Makefile |   8 +--
 libavfilter/scale.c  | 152 +++
 libavfilter/scale.h  |  28 
 libavfilter/vf_scale.c   | 109 +++
 libavfilter/vf_scale_npp.c   |  94 +++---
 libavfilter/vf_scale_vaapi.c |  19 --
 6 files changed, 217 insertions(+), 193 deletions(-)
 create mode 100644 libavfilter/scale.c
 create mode 100644 libavfilter/scale.h

diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 68a94be..3231f08 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -257,10 +257,10 @@ OBJS-$(CONFIG_REPEATFIELDS_FILTER)   += 
vf_repeatfields.o
 OBJS-$(CONFIG_REVERSE_FILTER)+= f_reverse.o
 OBJS-$(CONFIG_ROTATE_FILTER) += vf_rotate.o
 OBJS-$(CONFIG_SAB_FILTER)+= vf_sab.o
-OBJS-$(CONFIG_SCALE_FILTER)  += vf_scale.o
-OBJS-$(CONFIG_SCALE_NPP_FILTER)  += vf_scale_npp.o
-OBJS-$(CONFIG_SCALE_VAAPI_FILTER)+= vf_scale_vaapi.o
-OBJS-$(CONFIG_SCALE2REF_FILTER)  += vf_scale.o
+OBJS-$(CONFIG_SCALE_FILTER)  += vf_scale.o scale.o
+OBJS-$(CONFIG_SCALE_NPP_FILTER)  += vf_scale_npp.o scale.o
+OBJS-$(CONFIG_SCALE_VAAPI_FILTER)+= vf_scale_vaapi.o scale.o
+OBJS-$(CONFIG_SCALE2REF_FILTER)  += vf_scale.o scale.o
 OBJS-$(CONFIG_SELECT_FILTER) += f_select.o
 OBJS-$(CONFIG_SELECTIVECOLOR_FILTER) += vf_selectivecolor.o
 OBJS-$(CONFIG_SENDCMD_FILTER)+= f_sendcmd.o
diff --git a/libavfilter/scale.c b/libavfilter/scale.c
new file mode 100644
index 000..caa4680
--- /dev/null
+++ b/libavfilter/scale.c
@@ -0,0 +1,152 @@
+/*
+ * Copyright (c) 2007 Bobby Bingham
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include 
+#include "scale.h"
+#include "libavutil/eval.h"
+#include "libavutil/mathematics.h"
+#include "libavutil/pixdesc.h"
+
+static const char *const var_names[] = {
+"PI",
+"PHI",
+"E",
+"in_w",   "iw",
+"in_h",   "ih",
+"out_w",  "ow",
+"out_h",  "oh",
+"a",
+"sar",
+"dar",
+"hsub",
+"vsub",
+"ohsub",
+"ovsub",
+NULL
+};
+
+enum var_name {
+VAR_PI,
+VAR_PHI,
+VAR_E,
+VAR_IN_W,   VAR_IW,
+VAR_IN_H,   VAR_IH,
+VAR_OUT_W,  VAR_OW,
+VAR_OUT_H,  VAR_OH,
+VAR_A,
+VAR_SAR,
+VAR_DAR,
+VAR_HSUB,
+VAR_VSUB,
+VAR_OHSUB,
+VAR_OVSUB,
+VARS_NB
+};
+
+int ff_scale_eval_dimensions(void *log_ctx,
+const char *w_expr, const char *h_expr,
+AVFilterLink *inlink, AVFilterLink *outlink,
+int *ret_w, int *ret_h)
+{
+const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
+const AVPixFmtDescriptor *out_desc = av_pix_fmt_desc_get(outlink->format);
+const char *expr;
+int w, h;
+int factor_w, factor_h;
+int eval_w, eval_h;
+int ret;
+double var_values[VARS_NB], res;
+
+var_values[VAR_PI]= M_PI;
+var_values[VAR_PHI]   = M_PHI;
+var_values[VAR_E] = M_E;
+var_values[VAR_IN_W]  = var_values[VAR_IW] = inlink->w;
+var_values[VAR_IN_H]  = var_values[VAR_IH] = inlink->h;
+var_values[VAR_OUT_W] = var_values[VAR_OW] = NAN;
+var_values[VAR_OUT_H] = var_values[VAR_OH] = NAN;
+var_values[VAR_A] = (double) inlink->w / inlink->h;
+var_values[VAR_SAR]   = inlink->sample_aspect_ratio.num ?
+(double) inlink->sample_aspect_ratio.num / 
inlink->sample_aspect_ratio.den : 1;
+var_values[VAR_DAR]   = var_values[VAR_A] * var_values[VAR_SAR];
+var_values[VAR_HSUB]  = 1 << desc->log2_chroma_w;
+var_values[VAR_VSUB]  = 1 << desc->log2_chroma_h;
+var_values[VAR_OHSUB] = 1 << out_desc->log2_chroma_w;
+var_values[VAR_OVSUB] = 1 <

Re: [FFmpeg-devel] [PATCH] avformat/hlsenc: add hls_flag option to create segments atomically

2017-02-01 Thread Aman Gupta
On Tue, Jan 31, 2017 at 12:29 PM, Aman Gupta <ffm...@tmm1.net> wrote:

> From: Aman Gupta <a...@tmm1.net>
>
> Adds a `-hls_flags +temp_file` which will write segment data to
> filename.tmp, and then rename to filename when the segment is complete
> and before the file is added to the m3u8 playlist.
>
> This patch is similar in spirit to one used in Plex's ffmpeg fork, and
> allows a transcoding webserver to ensure incomplete segment files are
> never served up accidentally.
> ---
>  libavformat/hlsenc.c | 15 +++
>  1 file changed, 15 insertions(+)
>
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index bd1e684..23b9011 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -76,6 +76,7 @@ typedef enum HLSFlags {
>  HLS_SECOND_LEVEL_SEGMENT_INDEX = (1 << 8), // include segment index
> in segment filenames when use_localtime  e.g.: %%03d
>  HLS_SECOND_LEVEL_SEGMENT_DURATION = (1 << 9), // include segment
> duration (microsec) in segment filenames when use_localtime  e.g.: %%09t
>  HLS_SECOND_LEVEL_SEGMENT_SIZE = (1 << 10), // include segment size
> (bytes) in segment filenames when use_localtime  e.g.: %%014s
> +HLS_TEMP_FILE = (1 << 11),
>  } HLSFlags;
>
>  typedef enum {
> @@ -915,6 +916,10 @@ static int hls_start(AVFormatContext *s)
>
>  set_http_options(, c);
>
> +if (c->flags & HLS_TEMP_FILE) {
> +av_strlcat(oc->filename, ".tmp", sizeof(oc->filename));
> +}
> +
>  if (c->key_info_file) {
>  if ((err = hls_encryption_start(s)) < 0)
>  goto fail;
> @@ -1276,6 +1281,15 @@ static int hls_write_packet(AVFormatContext *s,
> AVPacket *pkt)
>
>  av_write_frame(oc, NULL); /* Flush any buffered data */
>
> +if (hls->flags & HLS_TEMP_FILE) {
> +size_t len = strlen(oc->filename);
> +char final_filename[sizeof(oc->filename)];
> +av_strlcpy(final_filename, oc->filename, len);
> +final_filename[len-4] = '\0';
> +ff_rename(oc->filename, final_filename, s);
>

This doesn't work on windows, since you cannot rename the file while it is
still open. Strangely ff_rename is not logging any errors in this case.


> +oc->filename[len-4] = '\0';
> +}
> +
>  new_start_pos = avio_tell(hls->avf->pb);
>  hls->size = new_start_pos - hls->start_pos;
>  ret = hls_append_segment(s, hls, hls->duration, hls->start_pos,
> hls->size);
> @@ -1406,6 +1420,7 @@ static const AVOption options[] = {
>  {"hls_subtitle_path", "set path of hls subtitles",
> OFFSET(subtitle_filename), AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,E},
>  {"hls_flags", "set flags affecting HLS playlist and media file
> generation", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64 = 0 }, 0, UINT_MAX, E,
> "flags"},
>  {"single_file",   "generate a single media file indexed with byte
> ranges", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_SINGLE_FILE }, 0, UINT_MAX,   E,
> "flags"},
> +{"temp_file", "write segment to temporary file and rename when
> complete", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_TEMP_FILE }, 0, UINT_MAX,   E,
> "flags"},
>  {"delete_segments", "delete segment files that are no longer part of
> the playlist", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_DELETE_SEGMENTS }, 0,
> UINT_MAX,   E, "flags"},
>  {"round_durations", "round durations in m3u8 to whole numbers", 0,
> AV_OPT_TYPE_CONST, {.i64 = HLS_ROUND_DURATIONS }, 0, UINT_MAX,   E,
> "flags"},
>  {"discont_start", "start the playlist with a discontinuity tag", 0,
> AV_OPT_TYPE_CONST, {.i64 = HLS_DISCONT_START }, 0, UINT_MAX,   E, "flags"},
> --
> 2.10.1 (Apple Git-78)
>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH v2] avformat/hlsenc: add hls_flag option to write segments to temporary file until complete

2017-02-01 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

Adds a `-hls_flags +temp_file` which will write segment data to
filename.tmp, and then rename to filename when the segment is complete.

This patch is similar in spirit to one used in Plex's ffmpeg fork, and
allows a transcoding webserver to ensure incomplete segment files are
never served up accidentally.
---
 libavformat/hlsenc.c | 25 +
 1 file changed, 25 insertions(+)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index bd1e684..17d4fe4 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -76,6 +76,7 @@ typedef enum HLSFlags {
 HLS_SECOND_LEVEL_SEGMENT_INDEX = (1 << 8), // include segment index in 
segment filenames when use_localtime  e.g.: %%03d
 HLS_SECOND_LEVEL_SEGMENT_DURATION = (1 << 9), // include segment duration 
(microsec) in segment filenames when use_localtime  e.g.: %%09t
 HLS_SECOND_LEVEL_SEGMENT_SIZE = (1 << 10), // include segment size (bytes) 
in segment filenames when use_localtime  e.g.: %%014s
+HLS_TEMP_FILE = (1 << 11),
 } HLSFlags;
 
 typedef enum {
@@ -416,6 +417,7 @@ static int hls_mux_init(AVFormatContext *s)
 return ret;
 oc = hls->avf;
 
+oc->filename[0]= '\0';
 oc->oformat= hls->oformat;
 oc->interrupt_callback = s->interrupt_callback;
 oc->max_delay  = s->max_delay;
@@ -815,6 +817,15 @@ static int hls_start(AVFormatContext *s)
 char *filename, iv_string[KEYSIZE*2 + 1];
 int err = 0;
 
+if ((c->flags & HLS_TEMP_FILE) && oc->filename[0] != 0) {
+size_t len = strlen(oc->filename);
+char final_filename[sizeof(oc->filename)];
+av_strlcpy(final_filename, oc->filename, len);
+final_filename[len-4] = '\0';
+ff_rename(oc->filename, final_filename, s);
+oc->filename[len-4] = '\0';
+}
+
 if (c->flags & HLS_SINGLE_FILE) {
 av_strlcpy(oc->filename, c->basename,
sizeof(oc->filename));
@@ -915,6 +926,10 @@ static int hls_start(AVFormatContext *s)
 
 set_http_options(, c);
 
+if (c->flags & HLS_TEMP_FILE) {
+av_strlcat(oc->filename, ".tmp", sizeof(oc->filename));
+}
+
 if (c->key_info_file) {
 if ((err = hls_encryption_start(s)) < 0)
 goto fail;
@@ -1364,6 +1379,15 @@ static int hls_write_trailer(struct AVFormatContext *s)
  ff_rename(old_filename, hls->avf->filename, hls);
 }
 
+if ((hls->flags & HLS_TEMP_FILE) && oc->filename[0] != 0) {
+size_t len = strlen(oc->filename);
+char final_filename[sizeof(oc->filename)];
+av_strlcpy(final_filename, oc->filename, len);
+final_filename[len-4] = '\0';
+ff_rename(oc->filename, final_filename, s);
+oc->filename[len-4] = '\0';
+}
+
 if (vtt_oc) {
 if (vtt_oc->pb)
 av_write_trailer(vtt_oc);
@@ -1406,6 +1430,7 @@ static const AVOption options[] = {
 {"hls_subtitle_path", "set path of hls subtitles", 
OFFSET(subtitle_filename), AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,E},
 {"hls_flags", "set flags affecting HLS playlist and media file 
generation", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64 = 0 }, 0, UINT_MAX, E, 
"flags"},
 {"single_file",   "generate a single media file indexed with byte ranges", 
0, AV_OPT_TYPE_CONST, {.i64 = HLS_SINGLE_FILE }, 0, UINT_MAX,   E, "flags"},
+{"temp_file", "write segment to temporary file and rename when complete", 
0, AV_OPT_TYPE_CONST, {.i64 = HLS_TEMP_FILE }, 0, UINT_MAX,   E, "flags"},
 {"delete_segments", "delete segment files that are no longer part of the 
playlist", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_DELETE_SEGMENTS }, 0, UINT_MAX,   
E, "flags"},
 {"round_durations", "round durations in m3u8 to whole numbers", 0, 
AV_OPT_TYPE_CONST, {.i64 = HLS_ROUND_DURATIONS }, 0, UINT_MAX,   E, "flags"},
 {"discont_start", "start the playlist with a discontinuity tag", 0, 
AV_OPT_TYPE_CONST, {.i64 = HLS_DISCONT_START }, 0, UINT_MAX,   E, "flags"},
-- 
2.10.1 (Apple Git-78)

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


Re: [FFmpeg-devel] [PATCH] avutil/hwcontext_vaapi: fix SEGV in vaTerminate when vaInitialize fails

2017-02-02 Thread Aman Gupta
On Thu, Feb 2, 2017 at 9:29 AM, Aman Gupta <ffm...@tmm1.net> wrote:

> From: Aman Gupta <a...@tmm1.net>
>
> Program terminated with signal SIGSEGV, Segmentation fault.
> opts=opts@entry=0x0, flags=flags@entry=0) at libavutil/hwcontext.c:494
>

Looks like my editor ate the gdb backtrace I had pasted. Will resubmit with
the commit message fixed if no one has objects to the diff.


> ---
>  libavutil/hwcontext_vaapi.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
> index 6176bdc..0051acb 100644
> --- a/libavutil/hwcontext_vaapi.c
> +++ b/libavutil/hwcontext_vaapi.c
> @@ -961,14 +961,13 @@ static int vaapi_device_create(AVHWDeviceContext
> *ctx, const char *device,
>  return AVERROR(EINVAL);
>  }
>
> -hwctx->display = display;
> -
>  vas = vaInitialize(display, , );
>  if (vas != VA_STATUS_SUCCESS) {
>  av_log(ctx, AV_LOG_ERROR, "Failed to initialise VAAPI "
> "connection: %d (%s).\n", vas, vaErrorStr(vas));
>  return AVERROR(EIO);
>  }
> +hwctx->display = display;
>  av_log(ctx, AV_LOG_VERBOSE, "Initialised VAAPI connection: "
> "version %d.%d\n", major, minor);
>
> --
> 2.10.1 (Apple Git-78)
>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH v2] avutil/hwcontext_vaapi: fix SEGV in vaTerminate when vaInitialize fails

2017-02-02 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

Program terminated with signal SIGSEGV, Segmentation fault.
  #0  0x00aff8a4 in vaTerminate ()
  #1  0x00ae50ce in vaapi_device_free (ctx=) at 
libavutil/hwcontext_vaapi.c:882
  #2  0x00ae1f9e in hwdevice_ctx_free (opaque=, 
data=) at libavutil/hwcontext.c:66
  #3  0x00ad856f in buffer_replace (src=0x0, dst=0x7fffa26ef1b8) at 
libavutil/buffer.c:119
  #4  av_buffer_unref (buf=buf@entry=0x7fffa26ef1f8) at libavutil/buffer.c:129
  #5  0x00ae299f in av_hwdevice_ctx_create (pdevice_ref=0x170ac50 
, type=type@entry=AV_HWDEVICE_TYPE_VAAPI, device=,
  opts=opts@entry=0x0, flags=flags@entry=0) at libavutil/hwcontext.c:494
  #6  0x00400968 in vaapi_device_init (device=) at 
ffmpeg_vaapi.c:223
---
 libavutil/hwcontext_vaapi.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index 6176bdc..0051acb 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -961,14 +961,13 @@ static int vaapi_device_create(AVHWDeviceContext *ctx, 
const char *device,
 return AVERROR(EINVAL);
 }
 
-hwctx->display = display;
-
 vas = vaInitialize(display, , );
 if (vas != VA_STATUS_SUCCESS) {
 av_log(ctx, AV_LOG_ERROR, "Failed to initialise VAAPI "
"connection: %d (%s).\n", vas, vaErrorStr(vas));
 return AVERROR(EIO);
 }
+hwctx->display = display;
 av_log(ctx, AV_LOG_VERBOSE, "Initialised VAAPI connection: "
"version %d.%d\n", major, minor);
 
-- 
2.10.1 (Apple Git-78)

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


Re: [FFmpeg-devel] [PATCH] avformat/hlsenc: add hls_flag option to create segments atomically

2017-02-02 Thread Aman Gupta
On Wed, Feb 1, 2017 at 6:03 AM, Bodecs Bela <bode...@vivanet.hu> wrote:

>
>
> 2017.01.31. 21:29 keltezéssel, Aman Gupta írta:
>
>> From: Aman Gupta <a...@tmm1.net>
>>
>> Adds a `-hls_flags +temp_file` which will write segment data to
>> filename.tmp, and then rename to filename when the segment is complete
>> and before the file is added to the m3u8 playlist.
>>
>> This patch is similar in spirit to one used in Plex's ffmpeg fork, and
>> allows a transcoding webserver to ensure incomplete segment files are
>> never served up accidentally.
>> ---
>>   libavformat/hlsenc.c | 15 +++
>>   1 file changed, 15 insertions(+)
>>
>> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
>> index bd1e684..23b9011 100644
>> --- a/libavformat/hlsenc.c
>> +++ b/libavformat/hlsenc.c
>> @@ -76,6 +76,7 @@ typedef enum HLSFlags {
>>   HLS_SECOND_LEVEL_SEGMENT_INDEX = (1 << 8), // include segment index
>> in segment filenames when use_localtime  e.g.: %%03d
>>   HLS_SECOND_LEVEL_SEGMENT_DURATION = (1 << 9), // include segment
>> duration (microsec) in segment filenames when use_localtime  e.g.: %%09t
>>   HLS_SECOND_LEVEL_SEGMENT_SIZE = (1 << 10), // include segment size
>> (bytes) in segment filenames when use_localtime  e.g.: %%014s
>> +HLS_TEMP_FILE = (1 << 11),
>>   } HLSFlags;
>> typedef enum {
>> @@ -915,6 +916,10 @@ static int hls_start(AVFormatContext *s)
>> set_http_options(, c);
>>   +if (c->flags & HLS_TEMP_FILE) {
>> +av_strlcat(oc->filename, ".tmp", sizeof(oc->filename));
>> +}
>> +
>>   if (c->key_info_file) {
>>   if ((err = hls_encryption_start(s)) < 0)
>>   goto fail;
>> @@ -1276,6 +1281,15 @@ static int hls_write_packet(AVFormatContext *s,
>> AVPacket *pkt)
>> av_write_frame(oc, NULL); /* Flush any buffered data */
>>   +if (hls->flags & HLS_TEMP_FILE) {
>> +size_t len = strlen(oc->filename);
>> +char final_filename[sizeof(oc->filename)];
>> +av_strlcpy(final_filename, oc->filename, len);
>> +final_filename[len-4] = '\0';
>> +ff_rename(oc->filename, final_filename, s);
>> +oc->filename[len-4] = '\0';
>> +}
>> +
>>   new_start_pos = avio_tell(hls->avf->pb);
>>   hls->size = new_start_pos - hls->start_pos;
>>   ret = hls_append_segment(s, hls, hls->duration, hls->start_pos,
>> hls->size);
>> @@ -1406,6 +1420,7 @@ static const AVOption options[] = {
>>   {"hls_subtitle_path", "set path of hls subtitles",
>> OFFSET(subtitle_filename), AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,E},
>>   {"hls_flags", "set flags affecting HLS playlist and media file
>> generation", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64 = 0 }, 0, UINT_MAX, E,
>> "flags"},
>>   {"single_file",   "generate a single media file indexed with byte
>> ranges", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_SINGLE_FILE }, 0, UINT_MAX,   E,
>> "flags"},
>> +{"temp_file", "write segment to temporary file and rename when
>> complete", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_TEMP_FILE }, 0, UINT_MAX,   E,
>> "flags"},
>>   {"delete_segments", "delete segment files that are no longer part
>> of the playlist", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_DELETE_SEGMENTS }, 0,
>> UINT_MAX,   E, "flags"},
>>   {"round_durations", "round durations in m3u8 to whole numbers", 0,
>> AV_OPT_TYPE_CONST, {.i64 = HLS_ROUND_DURATIONS }, 0, UINT_MAX,   E,
>> "flags"},
>>   {"discont_start", "start the playlist with a discontinuity tag", 0,
>> AV_OPT_TYPE_CONST, {.i64 = HLS_DISCONT_START }, 0, UINT_MAX,   E, "flags"},
>>
> I think the phrase  in your email subject "to create atomically"
> misleading because another renaming may occur afterwards your temp renaming
> if second_level_segment_size or second_level_segment_duration flag is on.
> But the idea to write segment content into a temp file is good by me. To
> ensure the amoticity the two distinct renamings may be merged.
>

I agree my use of "atomic" is confusing. I removed this from the commit
message in v2 of the patch.


>
> I have never thought of it but after your idea I concluded  that the
> segment file n

Re: [FFmpeg-devel] [PATCH] avutil/hwcontext_vaapi: fix SEGV in vaTerminate when vaInitialize fails

2017-02-03 Thread Aman Gupta
On Fri, Feb 3, 2017 at 12:19 PM, Mark Thompson <s...@jkqxz.net> wrote:

> On 03/02/17 05:45, wm4 wrote:
> > On Thu,  2 Feb 2017 09:29:13 -0800
> > Aman Gupta <ffm...@tmm1.net> wrote:
> >
> >> From: Aman Gupta <a...@tmm1.net>
> >>
> >> Program terminated with signal SIGSEGV, Segmentation fault.
> >> opts=opts@entry=0x0, flags=flags@entry=0) at
> libavutil/hwcontext.c:494
> >> ---
> >>  libavutil/hwcontext_vaapi.c | 3 +--
> >>  1 file changed, 1 insertion(+), 2 deletions(-)
> >>
> >> diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
> >> index 6176bdc..0051acb 100644
> >> --- a/libavutil/hwcontext_vaapi.c
> >> +++ b/libavutil/hwcontext_vaapi.c
> >> @@ -961,14 +961,13 @@ static int vaapi_device_create(AVHWDeviceContext
> *ctx, const char *device,
> >>  return AVERROR(EINVAL);
> >>  }
> >>
> >> -hwctx->display = display;
> >> -
> >>  vas = vaInitialize(display, , );
> >>  if (vas != VA_STATUS_SUCCESS) {
> >>  av_log(ctx, AV_LOG_ERROR, "Failed to initialise VAAPI "
> >> "connection: %d (%s).\n", vas, vaErrorStr(vas));
> >>  return AVERROR(EIO);
> >>  }
> >> +hwctx->display = display;
> >>  av_log(ctx, AV_LOG_VERBOSE, "Initialised VAAPI connection: "
> >> "version %d.%d\n", major, minor);
> >>
> >
> > Would that mean it doesn't free the display that was created with
> > vaGetDisplay? Is that right?
> >
> > In my experiments, calling vaTerminate right after vaGetDisplay works
> > just fine.
>
> Right, looking more carefully at libva that is exactly what you are meant
> to do, and the code there is careful to make it all work.  The segfault
> case I was thinking of here isn't exactly the same (and used the Intel
> proprietary driver, which should probably be considered dubious), so
> applying it was premature.
>
> Aman, can you explain more about the case you saw this in?
>

I saw this when I was using libva master. vaInitialize() was failing in my
environment (see https://github.com/01org/libva/issues/20) and after the
failure ffmpeg crashed.

Here was the output from ffmpeg:

libva info: VA-API version 0.40.0
libva info: va_getDriverName() returns 1
libva error: va_getDriverName() failed with operation
failed,driver_name=i965
[AVHWDeviceContext @ 0x1b03d80] Failed to initialise VAAPI connection: 1
(operation failed).
Segmentation fault

And the backtrace:

  #0  0x00aff8a4 in vaTerminate ()
  #1  0x00ae50ce in vaapi_device_free (ctx=) at
libavutil/hwcontext_vaapi.c:882
  #2  0x00ae1f9e in hwdevice_ctx_free (opaque=,
data=) at libavutil/hwcontext.c:66
  #3  0x00ad856f in buffer_replace (src=0x0, dst=0x7fffa26ef1b8) at
libavutil/buffer.c:119
  #4  av_buffer_unref (buf=buf@entry=0x7fffa26ef1f8) at
libavutil/buffer.c:129
  #5  0x00ae299f in av_hwdevice_ctx_create (pdevice_ref=0x170ac50
, type=type@entry=AV_HWDEVICE_TYPE_VAAPI, device=,
  opts=opts@entry=0x0, flags=flags@entry=0) at libavutil/hwcontext.c:494
  #6  0x00400968 in vaapi_device_init (device=) at
ffmpeg_vaapi.c:223

Definitely possible that this is a bug in libva instead, and that failure
midway through vaInitialize() is not dealt with appropriately during
vaTerminate().

Feel free to revert the commit.

Aman


> - Mark
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] avfilter/scale: refactor common code for scaling height/width expressions

2017-01-31 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

Implements support for height/width expressions in vf_scale_vaapi,
by refactoring common code into a new libavfilter/scale.c
---
 libavfilter/Makefile |   8 +--
 libavfilter/scale.c  | 143 +++
 libavfilter/scale.h  |  31 ++
 libavfilter/vf_scale.c   | 109 +++--
 libavfilter/vf_scale_npp.c   |  87 +++---
 libavfilter/vf_scale_vaapi.c |  18 +-
 6 files changed, 208 insertions(+), 188 deletions(-)
 create mode 100644 libavfilter/scale.c
 create mode 100644 libavfilter/scale.h

diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 68a94be..3231f08 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -257,10 +257,10 @@ OBJS-$(CONFIG_REPEATFIELDS_FILTER)   += 
vf_repeatfields.o
 OBJS-$(CONFIG_REVERSE_FILTER)+= f_reverse.o
 OBJS-$(CONFIG_ROTATE_FILTER) += vf_rotate.o
 OBJS-$(CONFIG_SAB_FILTER)+= vf_sab.o
-OBJS-$(CONFIG_SCALE_FILTER)  += vf_scale.o
-OBJS-$(CONFIG_SCALE_NPP_FILTER)  += vf_scale_npp.o
-OBJS-$(CONFIG_SCALE_VAAPI_FILTER)+= vf_scale_vaapi.o
-OBJS-$(CONFIG_SCALE2REF_FILTER)  += vf_scale.o
+OBJS-$(CONFIG_SCALE_FILTER)  += vf_scale.o scale.o
+OBJS-$(CONFIG_SCALE_NPP_FILTER)  += vf_scale_npp.o scale.o
+OBJS-$(CONFIG_SCALE_VAAPI_FILTER)+= vf_scale_vaapi.o scale.o
+OBJS-$(CONFIG_SCALE2REF_FILTER)  += vf_scale.o scale.o
 OBJS-$(CONFIG_SELECT_FILTER) += f_select.o
 OBJS-$(CONFIG_SELECTIVECOLOR_FILTER) += vf_selectivecolor.o
 OBJS-$(CONFIG_SENDCMD_FILTER)+= f_sendcmd.o
diff --git a/libavfilter/scale.c b/libavfilter/scale.c
new file mode 100644
index 000..b0f4be2
--- /dev/null
+++ b/libavfilter/scale.c
@@ -0,0 +1,143 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "scale.h"
+
+static const char *const var_names[] = {
+"PI",
+"PHI",
+"E",
+"in_w",   "iw",
+"in_h",   "ih",
+"out_w",  "ow",
+"out_h",  "oh",
+"a",
+"sar",
+"dar",
+"hsub",
+"vsub",
+"ohsub",
+"ovsub",
+NULL
+};
+
+enum var_name {
+VAR_PI,
+VAR_PHI,
+VAR_E,
+VAR_IN_W,   VAR_IW,
+VAR_IN_H,   VAR_IH,
+VAR_OUT_W,  VAR_OW,
+VAR_OUT_H,  VAR_OH,
+VAR_A,
+VAR_SAR,
+VAR_DAR,
+VAR_HSUB,
+VAR_VSUB,
+VAR_OHSUB,
+VAR_OVSUB,
+VARS_NB
+};
+
+int ff_scale_eval_dimensions(void *ctx,
+const char *w_expr, const char *h_expr,
+AVFilterLink *inlink, AVFilterLink *outlink,
+int *ret_w, int *ret_h)
+{
+const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
+const AVPixFmtDescriptor *out_desc = av_pix_fmt_desc_get(outlink->format);
+const char *expr;
+int w, h;
+int factor_w, factor_h;
+int eval_w, eval_h;
+int ret;
+double var_values[VARS_NB], res;
+
+var_values[VAR_IN_W]  = var_values[VAR_IW] = inlink->w;
+var_values[VAR_IN_H]  = var_values[VAR_IH] = inlink->h;
+var_values[VAR_OUT_W] = var_values[VAR_OW] = NAN;
+var_values[VAR_OUT_H] = var_values[VAR_OH] = NAN;
+var_values[VAR_A] = (double) inlink->w / inlink->h;
+var_values[VAR_SAR]   = inlink->sample_aspect_ratio.num ?
+(double) inlink->sample_aspect_ratio.num / 
inlink->sample_aspect_ratio.den : 1;
+var_values[VAR_DAR]   = var_values[VAR_A] * var_values[VAR_SAR];
+var_values[VAR_HSUB]  = 1 << desc->log2_chroma_w;
+var_values[VAR_VSUB]  = 1 << desc->log2_chroma_h;
+var_values[VAR_OHSUB] = 1 << out_desc->log2_chroma_w;
+var_values[VAR_OVSUB] = 1 << out_desc->log2_chroma_h;
+
+/* evaluate width and height */
+av_expr_parse_and_eval(, (expr = w_expr),
+   var_names, var_values,
+   NULL, NULL, NULL, NULL, NULL, 0, ctx);
+eval_w = var_values[VAR_OUT_W] = var_

[FFmpeg-devel] aac_latm: SSR is not implemented

2017-01-31 Thread Aman Gupta
I have a mpegts file with a HE-AAC audio track that cannot be decoded by
ffmpeg. I have uploaded a sample at the link below, as requested by the
decoder.

Happy to help with a patch to fix this issue, if someone can point me in
the right direction. FWIW, VLC is able to decode the audio without issue.

https://s3.amazonaws.com/tmm1/VasHD.mpg

Input #0, mpegts, from 'VasHD.mpg':
  Duration: 00:01:00.08, start: 39229.160467, bitrate: 9240 kb/s
  Program 5
Stream #0:0[0x208]: Video: h264 (High) ([27][0][0][0] / 0x001B),
yuv420p(tv, bt709, top first), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 50
tbr, 90k tbn, 50 tbc
Stream #0:1[0x212](tam): Audio: aac_latm (HE-AAC) ([17][0][0][0] /
0x0011), 48000 Hz, 5.1, fltp
Stream #0:2[0x213]: Audio: aac_latm (HE-AAC) ([17][0][0][0] / 0x0011),
48000 Hz, stereo, fltp
Stream #0:3[0x21c](eng): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006)
Stream #0:4[0x21f](tam): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006)
Stream #0:5[0x244]: Unknown: none ([5][0][0][0] / 0x0005)
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] avfilter/scale_vaapi: add support for basic height/width expressions

2017-01-31 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

Copied directly from vf_scale.c.

Implements the same expression logic, however not all the variables were copied 
over.
This patch was sufficient for my particular use-case 
`scale_vaapi=-2:min(ih\,720)`,
but perhaps it makes sense to add support for the remaining variables
and pull out shared code into a new vf_scale_common.c?
---
 libavfilter/vf_scale_vaapi.c | 98 ++--
 1 file changed, 95 insertions(+), 3 deletions(-)

diff --git a/libavfilter/vf_scale_vaapi.c b/libavfilter/vf_scale_vaapi.c
index d1cb246..0d1e1b3 100644
--- a/libavfilter/vf_scale_vaapi.c
+++ b/libavfilter/vf_scale_vaapi.c
@@ -22,6 +22,7 @@
 #include 
 
 #include "libavutil/avassert.h"
+#include "libavutil/eval.h"
 #include "libavutil/hwcontext.h"
 #include "libavutil/hwcontext_vaapi.h"
 #include "libavutil/mem.h"
@@ -32,6 +33,22 @@
 #include "formats.h"
 #include "internal.h"
 
+static const char *const var_names[] = {
+"in_w",   "iw",
+"in_h",   "ih",
+"out_w",  "ow",
+"out_h",  "oh",
+NULL
+};
+
+enum var_name {
+VAR_IN_W,   VAR_IW,
+VAR_IN_H,   VAR_IH,
+VAR_OUT_W,  VAR_OW,
+VAR_OUT_H,  VAR_OH,
+VARS_NB
+};
+
 typedef struct ScaleVAAPIContext {
 const AVClass *class;
 
@@ -50,9 +67,21 @@ typedef struct ScaleVAAPIContext {
 
 char *output_format_string;
 enum AVPixelFormat output_format;
+
+/**
+ * New dimensions. Special values are:
+ *   0 = original width/height
+ *  -1 = keep original aspect
+ *  -N = try to keep aspect but make sure it is divisible by N
+ */
+int w, h;
+
+char *w_expr;   ///< width  expression string
+char *h_expr;   ///< height expression string
+
+/* computed width/height */
 int output_width;
 int output_height;
-
 } ScaleVAAPIContext;
 
 
@@ -118,6 +147,14 @@ static int scale_vaapi_config_output(AVFilterLink *outlink)
 VAStatus vas;
 int err, i;
 
+AVFilterLink *inlink = outlink->src->inputs[0];
+ScaleVAAPIContext *scale = ctx;
+int64_t w, h;
+double var_values[VARS_NB], res;
+char *expr;
+int ret;
+int factor_w, factor_h;
+
 scale_vaapi_pipeline_uninit(ctx);
 
 ctx->device_ref = av_buffer_ref(ctx->input_frames->device_ref);
@@ -162,6 +199,61 @@ static int scale_vaapi_config_output(AVFilterLink *outlink)
 }
 }
 
+var_values[VAR_IN_W]  = var_values[VAR_IW] = inlink->w;
+var_values[VAR_IN_H]  = var_values[VAR_IH] = inlink->h;
+var_values[VAR_OUT_W] = var_values[VAR_OW] = NAN;
+var_values[VAR_OUT_H] = var_values[VAR_OH] = NAN;
+
+/* evaluate width and height */
+av_expr_parse_and_eval(, (expr = scale->w_expr),
+   var_names, var_values,
+   NULL, NULL, NULL, NULL, NULL, 0, ctx);
+scale->w = var_values[VAR_OUT_W] = var_values[VAR_OW] = res;
+if ((ret = av_expr_parse_and_eval(, (expr = scale->h_expr),
+  var_names, var_values,
+  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 
0)
+goto fail;
+scale->h = var_values[VAR_OUT_H] = var_values[VAR_OH] = res;
+/* evaluate again the width, as it may depend on the output height */
+if ((ret = av_expr_parse_and_eval(, (expr = scale->w_expr),
+  var_names, var_values,
+  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 
0)
+goto fail;
+scale->w = res;
+
+w = scale->w;
+h = scale->h;
+
+/* Check if it is requested that the result has to be divisible by a some
+ * factor (w or h = -n with n being the factor). */
+factor_w = 1;
+factor_h = 1;
+if (w < -1) {
+factor_w = -w;
+}
+if (h < -1) {
+factor_h = -h;
+}
+
+if (w < 0 && h < 0)
+scale->w = scale->h = 0;
+
+if (!(w = scale->w))
+w = inlink->w;
+if (!(h = scale->h))
+h = inlink->h;
+
+/* Make sure that the result is divisible by the factor we determined
+ * earlier. If no factor was set, it is nothing will happen as the default
+ * factor is 1 */
+if (w < 0)
+w = av_rescale(h, inlink->w, inlink->h * factor_w) * factor_w;
+if (h < 0)
+h = av_rescale(w, inlink->h, inlink->w * factor_h) * factor_h;
+
+ctx->output_width = w;
+ctx->output_height = h;
+
 if (ctx->output_width  < constraints->min_width  ||
 ctx->output_height < constraints->min_height ||
 ctx->output_width  > constraints->max_width  ||
@@ -414,9 +506,9 @@ static av_cold void scale_vaapi_uninit(AVFilterContext 
*avctx)
 #define FLA

[FFmpeg-devel] h264 bitstream corruption in videotoolbox encoder with a53cc=1

2017-02-06 Thread Aman Gupta
Last October, kernrj and I commited a series of patches to add a53cc
support to the videotoolbox encoder.

In using that feature over the past few months, I've discovered that the
generated streams can sometimes contain random/intermittent errors. This
only appears to occur on some Macs and not others.

These corrupted files cause errors when used with any of Apple's decoders,
including Safari, Quicktime, and mediastreamvalidator. The file can be
decoded with ffmpeg, although it prints out the following error when
encountering the corruption:

[NULL @ 0x7fbcce800600] sps_id 32 out of range
[h264 @ 0x7fbcd000] sps_id 32 out of range

Here are two sequential sample segments generated by the videotoolbox
encoder (when used with -f hls). They were generated one after the other
from the same source; the first is fine, but the second contains the
corruption.

https://s3.amazonaws.com/tmm1/stream57.ts
https://s3.amazonaws.com/tmm1/stream58.ts

I'd like to fix this bug, but have been stuck trying to narrow it down.
Hoping someone can point me in the right direction.

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


Re: [FFmpeg-devel] [PATCH v3] avfilter/scale: refactor common code for scaling height/width expressions

2017-02-04 Thread Aman Gupta
On Fri, Feb 3, 2017 at 3:04 PM, Michael Niedermayer <michae...@gmx.at>
wrote:

> On Wed, Feb 01, 2017 at 04:30:18PM -0800, Aman Gupta wrote:
> > From: Aman Gupta <a...@tmm1.net>
> >
> > Implements support for height/width expressions in vf_scale_vaapi,
> > by refactoring common code into a new libavfilter/scale.c
> > ---
> >  libavfilter/Makefile |   8 +--
> >  libavfilter/scale.c  | 152 ++
> +
> >  libavfilter/scale.h  |  28 
> >  libavfilter/vf_scale.c   | 109 +++
> >  libavfilter/vf_scale_npp.c   |  93 +++---
> >  libavfilter/vf_scale_vaapi.c |  19 --
> >  6 files changed, 216 insertions(+), 193 deletions(-)
> >  create mode 100644 libavfilter/scale.c
> >  create mode 100644 libavfilter/scale.h
> >
> > diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> > index 68a94be..3231f08 100644
> > --- a/libavfilter/Makefile
> > +++ b/libavfilter/Makefile
> > @@ -257,10 +257,10 @@ OBJS-$(CONFIG_REPEATFIELDS_FILTER)   +=
> vf_repeatfields.o
> >  OBJS-$(CONFIG_REVERSE_FILTER)+= f_reverse.o
> >  OBJS-$(CONFIG_ROTATE_FILTER) += vf_rotate.o
> >  OBJS-$(CONFIG_SAB_FILTER)+= vf_sab.o
> > -OBJS-$(CONFIG_SCALE_FILTER)  += vf_scale.o
> > -OBJS-$(CONFIG_SCALE_NPP_FILTER)  += vf_scale_npp.o
> > -OBJS-$(CONFIG_SCALE_VAAPI_FILTER)+= vf_scale_vaapi.o
> > -OBJS-$(CONFIG_SCALE2REF_FILTER)  += vf_scale.o
> > +OBJS-$(CONFIG_SCALE_FILTER)  += vf_scale.o scale.o
> > +OBJS-$(CONFIG_SCALE_NPP_FILTER)  += vf_scale_npp.o scale.o
> > +OBJS-$(CONFIG_SCALE_VAAPI_FILTER)+= vf_scale_vaapi.o
> scale.o
> > +OBJS-$(CONFIG_SCALE2REF_FILTER)  += vf_scale.o scale.o
> >  OBJS-$(CONFIG_SELECT_FILTER) += f_select.o
> >  OBJS-$(CONFIG_SELECTIVECOLOR_FILTER) += vf_selectivecolor.o
> >  OBJS-$(CONFIG_SENDCMD_FILTER)+= f_sendcmd.o
> > diff --git a/libavfilter/scale.c b/libavfilter/scale.c
> > new file mode 100644
> > index 000..50cd442
> > --- /dev/null
> > +++ b/libavfilter/scale.c
> > @@ -0,0 +1,152 @@
> > +/*
> > + * Copyright (c) 2007 Bobby Bingham
> > + *
> > + * This file is part of FFmpeg.
> > + *
> > + * FFmpeg is free software; you can redistribute it and/or
> > + * modify it under the terms of the GNU Lesser General Public
> > + * License as published by the Free Software Foundation; either
> > + * version 2.1 of the License, or (at your option) any later version.
> > + *
> > + * FFmpeg is distributed in the hope that it will be useful,
> > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> > + * Lesser General Public License for more details.
> > + *
> > + * You should have received a copy of the GNU Lesser General Public
> > + * License along with FFmpeg; if not, write to the Free Software
> > + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> 02110-1301 USA
> > + */
> > +
> > +#include 
> > +#include "scale.h"
> > +#include "libavutil/eval.h"
> > +#include "libavutil/mathematics.h"
> > +#include "libavutil/pixdesc.h"
> > +
> > +static const char *const var_names[] = {
> > +"PI",
> > +"PHI",
> > +"E",
> > +"in_w",   "iw",
> > +"in_h",   "ih",
> > +"out_w",  "ow",
> > +"out_h",  "oh",
> > +"a",
> > +"sar",
> > +"dar",
> > +"hsub",
> > +"vsub",
> > +"ohsub",
> > +"ovsub",
> > +NULL
> > +};
> > +
> > +enum var_name {
> > +VAR_PI,
> > +VAR_PHI,
> > +VAR_E,
> > +VAR_IN_W,   VAR_IW,
> > +VAR_IN_H,   VAR_IH,
> > +VAR_OUT_W,  VAR_OW,
> > +VAR_OUT_H,  VAR_OH,
> > +VAR_A,
> > +VAR_SAR,
> > +VAR_DAR,
> > +VAR_HSUB,
> > +VAR_VSUB,
> > +VAR_OHSUB,
> > +VAR_OVSUB,
> > +VARS_NB
> > +};
> > +
> > +int ff_scale_eval_dimensions(void *log_ctx,
> > +const char *w_expr, const char *h_expr,
> > +AVFilterLink *inlink

[FFmpeg-devel] [PATCH] avfilter/scale: use int64_t for height/width calculation to address overflow

2017-02-04 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

---
 libavfilter/scale.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavfilter/scale.c b/libavfilter/scale.c
index 50cd442..9725f1f 100644
--- a/libavfilter/scale.c
+++ b/libavfilter/scale.c
@@ -68,7 +68,7 @@ int ff_scale_eval_dimensions(void *log_ctx,
 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
 const AVPixFmtDescriptor *out_desc = av_pix_fmt_desc_get(outlink->format);
 const char *expr;
-int w, h;
+int64_t w, h;
 int factor_w, factor_h;
 int eval_w, eval_h;
 int ret;
@@ -138,8 +138,8 @@ int ff_scale_eval_dimensions(void *log_ctx,
 if (h < 0)
 h = av_rescale(w, inlink->h, inlink->w * factor_h) * factor_h;
 
-*ret_w = w;
-*ret_h = h;
+*ret_w = (int)w;
+*ret_h = (int)h;
 
 return 0;
 
-- 
2.10.1 (Apple Git-78)

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


[FFmpeg-devel] [PATCH v3] avformat/hlsenc: add hls_flag option to write segments to temporary file until complete

2017-02-04 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

Adds a `-hls_flags +temp_file` which will write segment data to
filename.tmp, and then rename to filename when the segment is complete.

This patch is similar in spirit to one used in Plex's ffmpeg fork, and
allows a transcoding webserver to ensure incomplete segment files are
never served up accidentally.
---
 doc/muxers.texi  |  5 +
 libavformat/hlsenc.c | 25 +
 2 files changed, 30 insertions(+)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index 4372078..0d98805 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -656,6 +656,11 @@ Makes it possible to use segment duration (calculated  in 
microseconds) as %%t i
 expression besides date/time values when use_localtime is on.
 To get fixed width numbers with trailing zeroes, %%0xt format is available 
where x is the required width.
 
+@item temp_file
+Write segment data to filename.tmp and rename to filename only once the 
segment is complete. A webserver
+serving up segments can be configured to reject requests to *.tmp to prevent 
access to in-progress segments
+before they have been added to the m3u8 playlist.
+
 @example
 ffmpeg -i sample.mpeg \
-f hls -hls_time 3 -hls_list_size 5 \
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index bd1e684..17d4fe4 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -76,6 +76,7 @@ typedef enum HLSFlags {
 HLS_SECOND_LEVEL_SEGMENT_INDEX = (1 << 8), // include segment index in 
segment filenames when use_localtime  e.g.: %%03d
 HLS_SECOND_LEVEL_SEGMENT_DURATION = (1 << 9), // include segment duration 
(microsec) in segment filenames when use_localtime  e.g.: %%09t
 HLS_SECOND_LEVEL_SEGMENT_SIZE = (1 << 10), // include segment size (bytes) 
in segment filenames when use_localtime  e.g.: %%014s
+HLS_TEMP_FILE = (1 << 11),
 } HLSFlags;
 
 typedef enum {
@@ -416,6 +417,7 @@ static int hls_mux_init(AVFormatContext *s)
 return ret;
 oc = hls->avf;
 
+oc->filename[0]= '\0';
 oc->oformat= hls->oformat;
 oc->interrupt_callback = s->interrupt_callback;
 oc->max_delay  = s->max_delay;
@@ -815,6 +817,15 @@ static int hls_start(AVFormatContext *s)
 char *filename, iv_string[KEYSIZE*2 + 1];
 int err = 0;
 
+if ((c->flags & HLS_TEMP_FILE) && oc->filename[0] != 0) {
+size_t len = strlen(oc->filename);
+char final_filename[sizeof(oc->filename)];
+av_strlcpy(final_filename, oc->filename, len);
+final_filename[len-4] = '\0';
+ff_rename(oc->filename, final_filename, s);
+oc->filename[len-4] = '\0';
+}
+
 if (c->flags & HLS_SINGLE_FILE) {
 av_strlcpy(oc->filename, c->basename,
sizeof(oc->filename));
@@ -915,6 +926,10 @@ static int hls_start(AVFormatContext *s)
 
 set_http_options(, c);
 
+if (c->flags & HLS_TEMP_FILE) {
+av_strlcat(oc->filename, ".tmp", sizeof(oc->filename));
+}
+
 if (c->key_info_file) {
 if ((err = hls_encryption_start(s)) < 0)
 goto fail;
@@ -1364,6 +1379,15 @@ static int hls_write_trailer(struct AVFormatContext *s)
  ff_rename(old_filename, hls->avf->filename, hls);
 }
 
+if ((hls->flags & HLS_TEMP_FILE) && oc->filename[0] != 0) {
+size_t len = strlen(oc->filename);
+char final_filename[sizeof(oc->filename)];
+av_strlcpy(final_filename, oc->filename, len);
+final_filename[len-4] = '\0';
+ff_rename(oc->filename, final_filename, s);
+oc->filename[len-4] = '\0';
+}
+
 if (vtt_oc) {
 if (vtt_oc->pb)
 av_write_trailer(vtt_oc);
@@ -1406,6 +1430,7 @@ static const AVOption options[] = {
 {"hls_subtitle_path", "set path of hls subtitles", 
OFFSET(subtitle_filename), AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,E},
 {"hls_flags", "set flags affecting HLS playlist and media file 
generation", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64 = 0 }, 0, UINT_MAX, E, 
"flags"},
 {"single_file",   "generate a single media file indexed with byte ranges", 
0, AV_OPT_TYPE_CONST, {.i64 = HLS_SINGLE_FILE }, 0, UINT_MAX,   E, "flags"},
+{"temp_file", "write segment to temporary file and rename when complete", 
0, AV_OPT_TYPE_CONST, {.i64 = HLS_TEMP_FILE }, 0, UINT_MAX,   E, "flags"},
 {"delete_segments", "delete segment files that are no longer part of the 
playlist", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_DELETE_SEGMENTS }, 0, UINT_MAX,   
E, "flags"},
 {"round_durations", "round durations in m3u8 to whole numbers", 0, 
AV_OPT_TYPE_CONST, {.i64 = HLS_ROUND_DURATIONS }, 0, UINT_MAX,   E, "flags"},
 {"discont_start", "start the playlist with a discontinuity tag", 0, 
AV_OPT_TYPE_CONST, {.i64 = HLS_DISCONT_START }, 0, UINT_MAX,   E, "flags"},
-- 
2.10.1 (Apple Git-78)

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


[FFmpeg-devel] [PATCH] avutil/hwcontext_vaapi: fix SEGV in vaTerminate when vaInitialize fails

2017-02-02 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

Program terminated with signal SIGSEGV, Segmentation fault.
opts=opts@entry=0x0, flags=flags@entry=0) at libavutil/hwcontext.c:494
---
 libavutil/hwcontext_vaapi.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index 6176bdc..0051acb 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -961,14 +961,13 @@ static int vaapi_device_create(AVHWDeviceContext *ctx, 
const char *device,
 return AVERROR(EINVAL);
 }
 
-hwctx->display = display;
-
 vas = vaInitialize(display, , );
 if (vas != VA_STATUS_SUCCESS) {
 av_log(ctx, AV_LOG_ERROR, "Failed to initialise VAAPI "
"connection: %d (%s).\n", vas, vaErrorStr(vas));
 return AVERROR(EIO);
 }
+hwctx->display = display;
 av_log(ctx, AV_LOG_VERBOSE, "Initialised VAAPI connection: "
"version %d.%d\n", major, minor);
 
-- 
2.10.1 (Apple Git-78)

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


[FFmpeg-devel] [PATCH] avformat/hlsenc: add hls_flag option to create segments atomically

2017-01-31 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

Adds a `-hls_flags +temp_file` which will write segment data to
filename.tmp, and then rename to filename when the segment is complete
and before the file is added to the m3u8 playlist.

This patch is similar in spirit to one used in Plex's ffmpeg fork, and
allows a transcoding webserver to ensure incomplete segment files are
never served up accidentally.
---
 libavformat/hlsenc.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index bd1e684..23b9011 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -76,6 +76,7 @@ typedef enum HLSFlags {
 HLS_SECOND_LEVEL_SEGMENT_INDEX = (1 << 8), // include segment index in 
segment filenames when use_localtime  e.g.: %%03d
 HLS_SECOND_LEVEL_SEGMENT_DURATION = (1 << 9), // include segment duration 
(microsec) in segment filenames when use_localtime  e.g.: %%09t
 HLS_SECOND_LEVEL_SEGMENT_SIZE = (1 << 10), // include segment size (bytes) 
in segment filenames when use_localtime  e.g.: %%014s
+HLS_TEMP_FILE = (1 << 11),
 } HLSFlags;
 
 typedef enum {
@@ -915,6 +916,10 @@ static int hls_start(AVFormatContext *s)
 
 set_http_options(, c);
 
+if (c->flags & HLS_TEMP_FILE) {
+av_strlcat(oc->filename, ".tmp", sizeof(oc->filename));
+}
+
 if (c->key_info_file) {
 if ((err = hls_encryption_start(s)) < 0)
 goto fail;
@@ -1276,6 +1281,15 @@ static int hls_write_packet(AVFormatContext *s, AVPacket 
*pkt)
 
 av_write_frame(oc, NULL); /* Flush any buffered data */
 
+if (hls->flags & HLS_TEMP_FILE) {
+size_t len = strlen(oc->filename);
+char final_filename[sizeof(oc->filename)];
+av_strlcpy(final_filename, oc->filename, len);
+final_filename[len-4] = '\0';
+ff_rename(oc->filename, final_filename, s);
+oc->filename[len-4] = '\0';
+}
+
 new_start_pos = avio_tell(hls->avf->pb);
 hls->size = new_start_pos - hls->start_pos;
 ret = hls_append_segment(s, hls, hls->duration, hls->start_pos, 
hls->size);
@@ -1406,6 +1420,7 @@ static const AVOption options[] = {
 {"hls_subtitle_path", "set path of hls subtitles", 
OFFSET(subtitle_filename), AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,E},
 {"hls_flags", "set flags affecting HLS playlist and media file 
generation", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64 = 0 }, 0, UINT_MAX, E, 
"flags"},
 {"single_file",   "generate a single media file indexed with byte ranges", 
0, AV_OPT_TYPE_CONST, {.i64 = HLS_SINGLE_FILE }, 0, UINT_MAX,   E, "flags"},
+{"temp_file", "write segment to temporary file and rename when complete", 
0, AV_OPT_TYPE_CONST, {.i64 = HLS_TEMP_FILE }, 0, UINT_MAX,   E, "flags"},
 {"delete_segments", "delete segment files that are no longer part of the 
playlist", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_DELETE_SEGMENTS }, 0, UINT_MAX,   
E, "flags"},
 {"round_durations", "round durations in m3u8 to whole numbers", 0, 
AV_OPT_TYPE_CONST, {.i64 = HLS_ROUND_DURATIONS }, 0, UINT_MAX,   E, "flags"},
 {"discont_start", "start the playlist with a discontinuity tag", 0, 
AV_OPT_TYPE_CONST, {.i64 = HLS_DISCONT_START }, 0, UINT_MAX,   E, "flags"},
-- 
2.10.1 (Apple Git-78)

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


Re: [FFmpeg-devel] [PATCH] avfilter/scale_vaapi: add support for basic height/width expressions

2017-01-31 Thread Aman Gupta
On Tue, Jan 31, 2017 at 12:26 PM, Mark Thompson <s...@jkqxz.net> wrote:

> On 31/01/17 19:14, Aman Gupta wrote:
> > From: Aman Gupta <a...@tmm1.net>
> >
> > Copied directly from vf_scale.c.
> >
> > Implements the same expression logic, however not all the variables were
> copied over.
> > This patch was sufficient for my particular use-case
> `scale_vaapi=-2:min(ih\,720)`,
> > but perhaps it makes sense to add support for the remaining variables
> > and pull out shared code into a new vf_scale_common.c?
>
> I would prefer the code fragment not to be copied again, yes.
>
> (Implementing this and removing the duplication between scale, scale_npp,
> scale_qsv and scale_vaapi has been on my to-maybe-do-at-some-point list for
> quite a while, but I've never actually had a use-case for it to push me
> into actually doing it :)
>

Ok, I'll see if I can refactor things to avoid duplication.

You mentioned scale_qsv, and I see the git commit in the history that added
it. But vf_scale_qsv.c is no where to be found on master. Do you know what
happened to it? I'd like to implement the same logic there too if I'm
refactoring things..


>
> If you can't be bothered, then the patch looks mostly sensible to me (some
> issues below, I think mainly coming from it being copied).
>
> > ---
> >  libavfilter/vf_scale_vaapi.c | 98 ++
> --
> >  1 file changed, 95 insertions(+), 3 deletions(-)
> >
> > diff --git a/libavfilter/vf_scale_vaapi.c b/libavfilter/vf_scale_vaapi.c
> > index d1cb246..0d1e1b3 100644
> > --- a/libavfilter/vf_scale_vaapi.c
> > +++ b/libavfilter/vf_scale_vaapi.c
> > @@ -22,6 +22,7 @@
> >  #include 
> >
> >  #include "libavutil/avassert.h"
> > +#include "libavutil/eval.h"
> >  #include "libavutil/hwcontext.h"
> >  #include "libavutil/hwcontext_vaapi.h"
> >  #include "libavutil/mem.h"
> > @@ -32,6 +33,22 @@
> >  #include "formats.h"
> >  #include "internal.h"
> >
> > +static const char *const var_names[] = {
> > +"in_w",   "iw",
> > +"in_h",   "ih",
> > +"out_w",  "ow",
> > +"out_h",  "oh",
> > +NULL
> > +};
> > +
> > +enum var_name {
> > +VAR_IN_W,   VAR_IW,
> > +VAR_IN_H,   VAR_IH,
> > +VAR_OUT_W,  VAR_OW,
> > +VAR_OUT_H,  VAR_OH,
> > +VARS_NB
> > +};
> > +
> >  typedef struct ScaleVAAPIContext {
> >  const AVClass *class;
> >
> > @@ -50,9 +67,21 @@ typedef struct ScaleVAAPIContext {
> >
> >  char *output_format_string;
> >  enum AVPixelFormat output_format;
> > +
> > +/**
> > + * New dimensions. Special values are:
> > + *   0 = original width/height
> > + *  -1 = keep original aspect
> > + *  -N = try to keep aspect but make sure it is divisible by N
> > + */
> > +int w, h;
>
> Why do these exist in addition to output_width and output_height?  They
> only seem to be used as temporaries duplicating w and h in
> scale_vaapi_config_output().
>
> > +
> > +char *w_expr;   ///< width  expression string
> > +char *h_expr;   ///< height expression string
> > +
> > +/* computed width/height */
> >  int output_width;
> >  int output_height;
> > -
> >  } ScaleVAAPIContext;
> >
> >
> > @@ -118,6 +147,14 @@ static int scale_vaapi_config_output(AVFilterLink
> *outlink)
> >  VAStatus vas;
> >  int err, i;
> >
> > +AVFilterLink *inlink = outlink->src->inputs[0];
> > +ScaleVAAPIContext *scale = ctx;
>
> Just use the ctx variable?
>
> > +int64_t w, h;
> > +double var_values[VARS_NB], res;
> > +char *expr;
>
> This variable is write-only.
>
> > +int ret;
>
> Just use err (because of the difference you aren't setting the correct
> error return if one of the evaluation operations fails).
>
> > +int factor_w, factor_h;
> > +
> >  scale_vaapi_pipeline_uninit(ctx);
> >
> >  ctx->device_ref = av_buffer_ref(ctx->input_frames->device_ref);
> > @@ -162,6 +199,61 @@ static int scale_vaapi_config_output(AVFilterLink
> *outlink)
> >  }
> >  }
> >
> > +var_values[VAR_IN_W]  = var_values[VAR_IW] = inlink->w;
> > +var_values[VAR_IN_H]  = var_values[VAR_IH] = inlink->h;
> > +var_values[

Re: [FFmpeg-devel] [PATCH] avformat/hlsenc: fix hls_flags temp_file bug

2017-02-21 Thread Aman Gupta
On Tue, Feb 21, 2017 at 7:13 AM, Steven Liu  wrote:

> refer to ticket id: #6170
>
> rename file from temp to origin name after complete current segment
>
> Signed-off-by: Steven Liu 
> ---
>  libavformat/hlsenc.c | 40 ++--
>  1 file changed, 22 insertions(+), 18 deletions(-)
>
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index e673f59..712a01b 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -691,6 +691,17 @@ static void write_m3u8_head_block(HLSContext *hls,
> AVIOContext *out, int version
>  av_log(hls, AV_LOG_VERBOSE, "EXT-X-MEDIA-SEQUENCE:%"PRId64"\n",
> sequence);
>  }
>
> +static void hls_rename_temp_file(AVFormatContext *s, AVFormatContext *oc)
> +{
> +size_t len = strlen(oc->filename);
> +char final_filename[sizeof(oc->filename)];
> +
> +av_strlcpy(final_filename, oc->filename, len);
> +final_filename[len-4] = '\0';
> +ff_rename(oc->filename, final_filename, s);
> +oc->filename[len-4] = '\0';
> +}
> +
>

Thanks, I should have made a helper function in my original patch.


>  static int hls_window(AVFormatContext *s, int last)
>  {
>  HLSContext *hls = s->priv_data;
> @@ -833,15 +844,6 @@ static int hls_start(AVFormatContext *s)
>  char *filename, iv_string[KEYSIZE*2 + 1];
>  int err = 0;
>
> -if ((c->flags & HLS_TEMP_FILE) && oc->filename[0] != 0) {
> -size_t len = strlen(oc->filename);
> -char final_filename[sizeof(oc->filename)];
> -av_strlcpy(final_filename, oc->filename, len);
> -final_filename[len-4] = '\0';
> -ff_rename(oc->filename, final_filename, s);
> -oc->filename[len-4] = '\0';
> -}
> -
>  if (c->flags & HLS_SINGLE_FILE) {
>  av_strlcpy(oc->filename, c->basename,
> sizeof(oc->filename));
> @@ -962,6 +964,7 @@ static int hls_start(AVFormatContext *s)
>  av_strlcat(oc->filename, ".tmp", sizeof(oc->filename));
>  }
>
> +
>

Unnecessary whitespace?


>  if (c->key_info_file) {
>  if ((err = hls_encryption_start(s)) < 0)
>  goto fail;
> @@ -1325,6 +1328,11 @@ static int hls_write_packet(AVFormatContext *s,
> AVPacket *pkt)
>
>  new_start_pos = avio_tell(hls->avf->pb);
>  hls->size = new_start_pos - hls->start_pos;
> +
> +if ((hls->flags & HLS_TEMP_FILE) && oc->filename[0] != 0) {
> +hls_rename_temp_file(s, oc);
> +}
> +
>

I think this will break on windows, because you cannot rename a file while
it is still open.


>  ret = hls_append_segment(s, hls, hls->duration, hls->start_pos,
> hls->size);
>  hls->start_pos = new_start_pos;
>  if (ret < 0) {
> @@ -1402,6 +1410,11 @@ static int hls_write_trailer(struct AVFormatContext
> *s)
>  if (oc->pb) {
>  hls->size = avio_tell(hls->avf->pb) - hls->start_pos;
>  ff_format_io_close(s, >pb);
> +
> +if ((hls->flags & HLS_TEMP_FILE) && oc->filename[0] != 0) {
> +hls_rename_temp_file(s, oc);
> +}
> +
>  /* after av_write_trailer, then duration + 1 duration per packet
> */
>  hls_append_segment(s, hls, hls->duration + hls->dpp,
> hls->start_pos, hls->size);
>  }
> @@ -1411,15 +1424,6 @@ static int hls_write_trailer(struct AVFormatContext
> *s)
>   ff_rename(old_filename, hls->avf->filename, hls);
>  }
>
> -if ((hls->flags & HLS_TEMP_FILE) && oc->filename[0] != 0) {
> -size_t len = strlen(oc->filename);
> -char final_filename[sizeof(oc->filename)];
> -av_strlcpy(final_filename, oc->filename, len);
> -final_filename[len-4] = '\0';
> -ff_rename(oc->filename, final_filename, s);
> -oc->filename[len-4] = '\0';
> -}
> -
>  if (vtt_oc) {
>  if (vtt_oc->pb)
>  av_write_trailer(vtt_oc);
> --
> 2.10.1.382.ga23ca1b.dirty
>
>
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avcodec/h264, videotoolbox: fix use-after-free of AVFrame buffer when VT decoder fails

2017-02-21 Thread Aman Gupta
On Mon, Feb 13, 2017 at 6:04 PM, Aman Gupta <ffm...@tmm1.net> wrote:

> From: Aman Gupta <a...@tmm1.net>
>
> The videotoolbox hwaccel returns a dummy frame with a 1-byte buffer from
> alloc_frame(). In end_frame(), this buffer is replaced with the actual
> decoded data from VTDecompressionSessionDecodeFrame(). This is hacky,
> but works well enough, as long as the VT decoder returns a valid frame on
> every end_frame() call.
>
> In the case of errors, things get more interesting. Before
> 9747219958060d8c4f697df62e7f172c2a77e6c7, the dummy 1-byte frame would
> accidentally be returned all the way up to the user. After that commit,
> the dummy frame was properly unref'd so the user received an error.
>
> However, since that commit, VT hwaccel failures started causing random
> segfaults in the h264 decoder. This happened more often on iOS where the
> VT implementation is more likely to throw errors on bitstream anomolies.
> A recent report of this issue can be see in
> http://ffmpeg.org/pipermail/libav-user/2016-November/009831.html
>
> The root cause here is that between the calls to alloc_frame() and
> end_frame(), the h264 decoder will reference the dummy 1-byte frame in
> its ref_list. When the end_frame() call fails, the dummy frame is
> unref'd but still referenced in the h264 decoder. This eventually causes
> a NULL deference and segmentation fault.
>
> This patch fixes the issue by properly discarding references to the
> dummy frame in the H264Context after the frame has been unref'd.
> ---
>  libavcodec/h264_picture.c |  3 +++
>  libavcodec/h264_refs.c| 20 ++--
>  libavcodec/h264dec.h  |  1 +
>  3 files changed, 22 insertions(+), 2 deletions(-)
>
> diff --git a/libavcodec/h264_picture.c b/libavcodec/h264_picture.c
> index f634d2a..702ca12 100644
> --- a/libavcodec/h264_picture.c
> +++ b/libavcodec/h264_picture.c
> @@ -177,6 +177,9 @@ int ff_h264_field_end(H264Context *h, H264SliceContext
> *sl, int in_setup)
>  if (err < 0)
>  av_log(avctx, AV_LOG_ERROR,
> "hardware accelerator failed to decode picture\n");
> +
> +if (err < 0 && avctx->hwaccel->pix_fmt == AV_PIX_FMT_VIDEOTOOLBOX)
> +ff_h264_remove_cur_pic_ref(h);
>

This patch fixed the crash I was seeing pretty often, but now another
assert() can trip (albeit less frequently):

Assertion h->cur_pic_ptr->f->buf[0] failed at
src/libavcodec/h264_slice.c:1340

I will try wm4's suggestion of leaving the dummy 1-byte frame in-place, but
ignoring it when it's time to return a frame to the user.


>  }
>
>  #if FF_API_CAP_VDPAU
> diff --git a/libavcodec/h264_refs.c b/libavcodec/h264_refs.c
> index 97bf588..9c77bc7 100644
> --- a/libavcodec/h264_refs.c
> +++ b/libavcodec/h264_refs.c
> @@ -560,6 +560,23 @@ static H264Picture *remove_long(H264Context *h, int
> i, int ref_mask)
>  return pic;
>  }
>
> +void ff_h264_remove_cur_pic_ref(H264Context *h)
> +{
> +int j;
> +
> +if (h->short_ref[0] == h->cur_pic_ptr) {
> +remove_short_at_index(h, 0);
> +}
> +
> +if (h->cur_pic_ptr->long_ref) {
> +for (j = 0; j < FF_ARRAY_ELEMS(h->long_ref); j++) {
> +if (h->long_ref[j] == h->cur_pic_ptr) {
> +remove_long(h, j, 0);
> +}
> +}
> +}
> +}
> +
>  void ff_h264_remove_all_refs(H264Context *h)
>  {
>  int i;
> @@ -571,8 +588,7 @@ void ff_h264_remove_all_refs(H264Context *h)
>
>  if (h->short_ref_count && !h->last_pic_for_ec.f->data[0]) {
>  ff_h264_unref_picture(h, >last_pic_for_ec);
> -if (h->short_ref[0]->f->buf[0])
> -ff_h264_ref_picture(h, >last_pic_for_ec, h->short_ref[0]);
> +ff_h264_ref_picture(h, >last_pic_for_ec, h->short_ref[0]);
>  }
>
>  for (i = 0; i < h->short_ref_count; i++) {
> diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h
> index 5f868b7..063afed 100644
> --- a/libavcodec/h264dec.h
> +++ b/libavcodec/h264dec.h
> @@ -569,6 +569,7 @@ int ff_h264_alloc_tables(H264Context *h);
>  int ff_h264_decode_ref_pic_list_reordering(H264SliceContext *sl, void
> *logctx);
>  int ff_h264_build_ref_list(H264Context *h, H264SliceContext *sl);
>  void ff_h264_remove_all_refs(H264Context *h);
> +void ff_h264_remove_cur_pic_ref(H264Context *h);
>
>  /**
>   * Execute the reference picture marking (memory management control
> operations).
> --
> 2.10.1 (Apple Git-78)
>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH v2] avcodec/h264, videotoolbox: fix crash after VT decoder fails

2017-02-21 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

The way videotoolbox hooks in as a hwaccel is pretty hacky. The VT decode
API is not invoked until end_frame(), so alloc_frame() returns a dummy
frame with a 1-byte buffer. When end_frame() is eventually called, the
dummy buffer is replaced with the actual decoded data from
VTDecompressionSessionDecodeFrame().

When the VT decoder fails, the frame returned to the h264 decoder from
alloc_frame() remains invalid and should not be used. Before
9747219958060d8c4f697df62e7f172c2a77e6c7, it was accidentally being
returned all the way up to the API user. After that commit, the dummy
frame was unref'd so the user received an error.

However, since that commit, VT hwaccel failures started causing random
segfaults in the h264 decoder. This happened more often on iOS where the
VT implementation is more likely to throw errors on bitstream anomolies.
A recent report of this issue can be see in
http://ffmpeg.org/pipermail/libav-user/2016-November/009831.html

The issue here is that the dummy frame is still referenced internally by the
h264 decoder, as part of the reflist and cur_pic_ptr. Deallocating the
frame causes assertions like this one to trip later on during decoding:

  Assertion h->cur_pic_ptr->f->buf[0] failed at src/libavcodec/h264_slice.c:1340

With this commit, we leave the dummy 1-byte frame intact, but avoid returning it
to the user.

This reverts commit 9747219958060d8c4f697df62e7f172c2a77e6c7.
---
 libavcodec/h264_refs.c| 3 +--
 libavcodec/h264dec.c  | 7 ++-
 libavcodec/videotoolbox.c | 2 --
 3 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/libavcodec/h264_refs.c b/libavcodec/h264_refs.c
index 97bf588b51..ad296753c3 100644
--- a/libavcodec/h264_refs.c
+++ b/libavcodec/h264_refs.c
@@ -571,8 +571,7 @@ void ff_h264_remove_all_refs(H264Context *h)
 
 if (h->short_ref_count && !h->last_pic_for_ec.f->data[0]) {
 ff_h264_unref_picture(h, >last_pic_for_ec);
-if (h->short_ref[0]->f->buf[0])
-ff_h264_ref_picture(h, >last_pic_for_ec, h->short_ref[0]);
+ff_h264_ref_picture(h, >last_pic_for_ec, h->short_ref[0]);
 }
 
 for (i = 0; i < h->short_ref_count; i++) {
diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index 41c0964392..a0ae632fed 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -850,7 +850,12 @@ static int output_frame(H264Context *h, AVFrame *dst, 
H264Picture *srcp)
 AVFrame *src = srcp->f;
 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(src->format);
 int i;
-int ret = av_frame_ref(dst, src);
+int ret;
+
+if (src->format == AV_PIX_FMT_VIDEOTOOLBOX && src->buf[0]->size == 1)
+return AVERROR_INVALIDDATA;
+
+ret = av_frame_ref(dst, src);
 if (ret < 0)
 return ret;
 
diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
index 1288aa5087..d931dbd5f9 100644
--- a/libavcodec/videotoolbox.c
+++ b/libavcodec/videotoolbox.c
@@ -351,8 +351,6 @@ static int videotoolbox_common_end_frame(AVCodecContext 
*avctx, AVFrame *frame)
 AVVideotoolboxContext *videotoolbox = avctx->hwaccel_context;
 VTContext *vtctx = avctx->internal->hwaccel_priv_data;
 
-av_buffer_unref(>buf[0]);
-
 if (!videotoolbox->session || !vtctx->bitstream)
 return AVERROR_INVALIDDATA;
 
-- 
2.11.0 (Apple Git-80)

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


Re: [FFmpeg-devel] [PATCH v2] avcodec/h264, videotoolbox: fix crash after VT decoder fails

2017-02-21 Thread Aman Gupta
On Tue, Feb 21, 2017 at 1:04 PM, Ronald S. Bultje <rsbul...@gmail.com>
wrote:

> Hi,
>
> On Tue, Feb 21, 2017 at 1:48 PM, Aman Gupta <ffm...@tmm1.net> wrote:
>
>> diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
>> index 41c0964392..a0ae632fed 100644
>> --- a/libavcodec/h264dec.c
>> +++ b/libavcodec/h264dec.c
>> @@ -850,7 +850,12 @@ static int output_frame(H264Context *h, AVFrame
>> *dst, H264Picture *srcp)
>>  AVFrame *src = srcp->f;
>>  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(src->format);
>>  int i;
>> -int ret = av_frame_ref(dst, src);
>> +int ret;
>> +
>> +if (src->format == AV_PIX_FMT_VIDEOTOOLBOX && src->buf[0]->size == 1)
>> +return AVERROR_INVALIDDATA;
>> +
>> +ret = av_frame_ref(dst, src);
>>  if (ret < 0)
>>  return ret;
>
>
> This is a total hack :) Is there a way to hide this into VT-specific code
> outside h264*.[ch]?
>

The way the VT hwaccel works is a total hack, as noted in my commit message.

AFAICT, given how the hwaccel APIs work, there's no way to do this outside
the h264 decoder. But I'm happy to try fixing this a different way if
anyone has a suggestion.


>
> Ronald
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] avcodec/h264, videotoolbox: fix use-after-free of AVFrame buffer when VT decoder fails

2017-02-13 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

The videotoolbox hwaccel returns a dummy frame with a 1-byte buffer from
alloc_frame(). In end_frame(), this buffer is replaced with the actual
decoded data from VTDecompressionSessionDecodeFrame(). This is hacky,
but works well enough, as long as the VT decoder returns a valid frame on
every end_frame() call.

In the case of errors, things get more interesting. Before
9747219958060d8c4f697df62e7f172c2a77e6c7, the dummy 1-byte frame would
accidentally be returned all the way up to the user. After that commit,
the dummy frame was properly unref'd so the user received an error.

However, since that commit, VT hwaccel failures started causing random
segfaults in the h264 decoder. This happened more often on iOS where the
VT implementation is more likely to throw errors on bitstream anomolies.
A recent report of this issue can be see in
http://ffmpeg.org/pipermail/libav-user/2016-November/009831.html

The root cause here is that between the calls to alloc_frame() and
end_frame(), the h264 decoder will reference the dummy 1-byte frame in
its ref_list. When the end_frame() call fails, the dummy frame is
unref'd but still referenced in the h264 decoder. This eventually causes
a NULL deference and segmentation fault.

This patch fixes the issue by properly discarding references to the
dummy frame in the H264Context after the frame has been unref'd.
---
 libavcodec/h264_picture.c |  3 +++
 libavcodec/h264_refs.c| 20 ++--
 libavcodec/h264dec.h  |  1 +
 3 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/libavcodec/h264_picture.c b/libavcodec/h264_picture.c
index f634d2a..702ca12 100644
--- a/libavcodec/h264_picture.c
+++ b/libavcodec/h264_picture.c
@@ -177,6 +177,9 @@ int ff_h264_field_end(H264Context *h, H264SliceContext *sl, 
int in_setup)
 if (err < 0)
 av_log(avctx, AV_LOG_ERROR,
"hardware accelerator failed to decode picture\n");
+
+if (err < 0 && avctx->hwaccel->pix_fmt == AV_PIX_FMT_VIDEOTOOLBOX)
+ff_h264_remove_cur_pic_ref(h);
 }
 
 #if FF_API_CAP_VDPAU
diff --git a/libavcodec/h264_refs.c b/libavcodec/h264_refs.c
index 97bf588..9c77bc7 100644
--- a/libavcodec/h264_refs.c
+++ b/libavcodec/h264_refs.c
@@ -560,6 +560,23 @@ static H264Picture *remove_long(H264Context *h, int i, int 
ref_mask)
 return pic;
 }
 
+void ff_h264_remove_cur_pic_ref(H264Context *h)
+{
+int j;
+
+if (h->short_ref[0] == h->cur_pic_ptr) {
+remove_short_at_index(h, 0);
+}
+
+if (h->cur_pic_ptr->long_ref) {
+for (j = 0; j < FF_ARRAY_ELEMS(h->long_ref); j++) {
+if (h->long_ref[j] == h->cur_pic_ptr) {
+remove_long(h, j, 0);
+}
+}
+}
+}
+
 void ff_h264_remove_all_refs(H264Context *h)
 {
 int i;
@@ -571,8 +588,7 @@ void ff_h264_remove_all_refs(H264Context *h)
 
 if (h->short_ref_count && !h->last_pic_for_ec.f->data[0]) {
 ff_h264_unref_picture(h, >last_pic_for_ec);
-if (h->short_ref[0]->f->buf[0])
-ff_h264_ref_picture(h, >last_pic_for_ec, h->short_ref[0]);
+ff_h264_ref_picture(h, >last_pic_for_ec, h->short_ref[0]);
 }
 
 for (i = 0; i < h->short_ref_count; i++) {
diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h
index 5f868b7..063afed 100644
--- a/libavcodec/h264dec.h
+++ b/libavcodec/h264dec.h
@@ -569,6 +569,7 @@ int ff_h264_alloc_tables(H264Context *h);
 int ff_h264_decode_ref_pic_list_reordering(H264SliceContext *sl, void *logctx);
 int ff_h264_build_ref_list(H264Context *h, H264SliceContext *sl);
 void ff_h264_remove_all_refs(H264Context *h);
+void ff_h264_remove_cur_pic_ref(H264Context *h);
 
 /**
  * Execute the reference picture marking (memory management control 
operations).
-- 
2.10.1 (Apple Git-78)

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


[FFmpeg-devel] [PATCH] avcodec/h264, videotoolbox: handle streams with multiple/changing PPS

2017-02-14 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

The videotoolbox hwaccel only receives SLICE and IDR_SLICE NALUs. This
works fine most of the time, but some streams fail to decode because
changes in PPS are not propagated to the VT decoder.

The failures in this case are incredibly annoying, as VTDecodeFrame()
still returns noErr. Simiarly the decoder callback is invoked with noErr,
and a NULL imageBuffer. Even though all the VT apis indicate success, no
frames are actually decoded.

When running ffmpeg via lldb however, some internal VT errors and
warnings show up all of a sudden. These suggest that the bitstream is
failing some internal consistency checks.

$ ffmpeg -y -loglevel error -threads 1 -hwaccel videotoolbox \
 -i http://tmm1.s3.amazonaws.com/h264.ts -map v -f null /dev/null
...
[h264 @ 0x7fdadc00] hardware accelerator failed to decode picture
Error while decoding stream #0:0: Unknown error occurred
vt decoder cb: output image buffer is null
...

$ lldb -- ffmpeg ...
...
ffmpeg[49384:2009219] GVA error: AVC_RBSP::parseSliceHeader error
ffmpeg[49384:2009219] GVA error: pushPicture parseSliceHeader
vt decoder cb: output image buffer is null
ffmpeg[49384:2009219] GVA warning: OutputQueueReadyCallback status = 1, 
buffer == 0x0
[h264 @ 0x10300a200] hardware accelerator failed to decode picture: Unknown 
error occurred
Error while decoding stream #0:0: Unknown error occurred
...

After this patch, there are no more errors and the sample decodes as
expected.
---
 libavcodec/h264dec.c  | 7 +++
 libavcodec/videotoolbox.c | 8 +---
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index 41c0964..af8b256 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -755,6 +755,13 @@ FF_ENABLE_DEPRECATION_WARNINGS
nal->size_bits);
 if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))
 goto end;
+if (avctx->hwaccel && avctx->hwaccel->pix_fmt == 
AV_PIX_FMT_VIDEOTOOLBOX) {
+ret = avctx->hwaccel->decode_slice(avctx,
+   nal->raw_data,
+   nal->raw_size);
+if (ret < 0)
+goto end;
+}
 break;
 case H264_NAL_AUD:
 case H264_NAL_END_SEQUENCE:
diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
index 1288aa5..1b5dffd 100644
--- a/libavcodec/videotoolbox.c
+++ b/libavcodec/videotoolbox.c
@@ -138,8 +138,6 @@ int ff_videotoolbox_h264_start_frame(AVCodecContext *avctx,
 VTContext *vtctx = avctx->internal->hwaccel_priv_data;
 H264Context *h  = avctx->priv_data;
 
-vtctx->bitstream_size = 0;
-
 if (h->is_avc == 1) {
 return videotoolbox_buffer_copy(vtctx, buffer, size);
 }
@@ -373,8 +371,12 @@ static int videotoolbox_h264_end_frame(AVCodecContext 
*avctx)
 {
 H264Context *h = avctx->priv_data;
 AVFrame *frame = h->cur_pic_ptr->f;
+VTContext *vtctx = avctx->internal->hwaccel_priv_data;
+int ret;
 
-return videotoolbox_common_end_frame(avctx, frame);
+ret = videotoolbox_common_end_frame(avctx, frame);
+vtctx->bitstream_size = 0;
+return ret;
 }
 
 static int videotoolbox_mpeg_start_frame(AVCodecContext *avctx,
-- 
2.10.1 (Apple Git-78)

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


[FFmpeg-devel] [PATCH 2/3] avcodec/videotoolbox: cosmetic change to simplify code with early return

2017-02-16 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

---
 libavcodec/videotoolbox.c | 15 ---
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
index 1288aa5..9be7bee 100644
--- a/libavcodec/videotoolbox.c
+++ b/libavcodec/videotoolbox.c
@@ -590,15 +590,16 @@ static int videotoolbox_default_init(AVCodecContext 
*avctx)
 static void videotoolbox_default_free(AVCodecContext *avctx)
 {
 AVVideotoolboxContext *videotoolbox = avctx->hwaccel_context;
+if (!videotoolbox)
+return;
 
-if (videotoolbox) {
-if (videotoolbox->cm_fmt_desc)
-CFRelease(videotoolbox->cm_fmt_desc);
+if (videotoolbox->cm_fmt_desc)
+CFRelease(videotoolbox->cm_fmt_desc);
 
-if (videotoolbox->session) {
-VTDecompressionSessionInvalidate(videotoolbox->session);
-CFRelease(videotoolbox->session);
-}
+if (videotoolbox->session) {
+VTDecompressionSessionInvalidate(videotoolbox->session);
+CFRelease(videotoolbox->session);
+videotoolbox->session = NULL;
 }
 }
 
-- 
2.10.1 (Apple Git-78)

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


[FFmpeg-devel] [PATCH 3/3] avcodec/videotoolbox: restart decompression session on bad data errors

2017-02-16 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

On some platforms (observed on macOS Sierra with 12" macbook), the VT
decoder will start returning errors when encountering an SPS change in
the h264 bitstream. With this patch, the kVTVideoDecoderBadDataErr
response from the decoder is caught and the decompression session is
recreated with a new avcC. The "bad data" is then fed into the new
decompression session so that it can be decoded correctly.

I discovered the underlying issue here by running ffmpeg with lldb,
which causes macOS to display debug information from the VT hardware
decoder on stderr. The following errors were shown, which indicated the
need to restart the decoder session with a new SPS/avcC:

  ffmpeg[15127:4094995] GVA error: SPS mismatch ...
  ffmpeg[15127:4094995] GVA error: AVF_PushMetaData, first field 
kAVF_QT0_SPSPPSBoundaryMarker
  ffmpeg[15127:4094995] GVA error: pushMetaData, submitNewJobs
  ffmpeg[15127:4094995] GVA warning: OutputQueueReadyCallback status = 1, 
buffer == 0x0

Tested with the following sample, which contains an SPS change midstream:
http://tmm1.s3.amazonaws.com/videotoolbox/spschange.ts
---
 libavcodec/videotoolbox.c | 28 
 1 file changed, 24 insertions(+), 4 deletions(-)

diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
index 9be7bee..159d98d 100644
--- a/libavcodec/videotoolbox.c
+++ b/libavcodec/videotoolbox.c
@@ -38,6 +38,9 @@
 
 #define VIDEOTOOLBOX_ESDS_EXTRADATA_PADDING  12
 
+static void videotoolbox_stop(AVCodecContext *avctx);
+static int videotoolbox_start(AVCodecContext *avctx);
+
 static void videotoolbox_buffer_release(void *opaque, uint8_t *data)
 {
 CVPixelBufferRef cv_buffer = (CVImageBufferRef)data;
@@ -350,13 +353,25 @@ static int videotoolbox_common_end_frame(AVCodecContext 
*avctx, AVFrame *frame)
 int status;
 AVVideotoolboxContext *videotoolbox = avctx->hwaccel_context;
 VTContext *vtctx = avctx->internal->hwaccel_priv_data;
+int retry;
 
 av_buffer_unref(>buf[0]);
 
 if (!videotoolbox->session || !vtctx->bitstream)
 return AVERROR_INVALIDDATA;
 
-status = videotoolbox_session_decode_frame(avctx);
+for (retry = 0; retry < 2; retry++) {
+status = videotoolbox_session_decode_frame(avctx);
+
+if (status == kVTVideoDecoderBadDataErr) {
+av_log(avctx, AV_LOG_DEBUG, "vt decoder got bad data error, 
restarting..\n");
+videotoolbox_stop(avctx);
+videotoolbox_start(avctx);
+continue;
+} else {
+break;
+}
+}
 
 if (status) {
 av_log(avctx, AV_LOG_ERROR, "Failed to decode frame (%d)\n", status);
@@ -506,7 +521,7 @@ static CMVideoFormatDescriptionRef 
videotoolbox_format_desc_create(CMVideoCodecT
 return cm_fmt_desc;
 }
 
-static int videotoolbox_default_init(AVCodecContext *avctx)
+static int videotoolbox_start(AVCodecContext *avctx)
 {
 AVVideotoolboxContext *videotoolbox = avctx->hwaccel_context;
 OSStatus status;
@@ -587,7 +602,12 @@ static int videotoolbox_default_init(AVCodecContext *avctx)
 }
 }
 
-static void videotoolbox_default_free(AVCodecContext *avctx)
+static int videotoolbox_default_init(AVCodecContext *avctx)
+{
+return videotoolbox_start(avctx);
+}
+
+static void videotoolbox_stop(AVCodecContext *avctx)
 {
 AVVideotoolboxContext *videotoolbox = avctx->hwaccel_context;
 if (!videotoolbox)
@@ -696,7 +716,7 @@ int av_videotoolbox_default_init2(AVCodecContext *avctx, 
AVVideotoolboxContext *
 void av_videotoolbox_default_free(AVCodecContext *avctx)
 {
 
-videotoolbox_default_free(avctx);
+videotoolbox_stop(avctx);
 av_freep(>hwaccel_context);
 }
 #endif /* CONFIG_VIDEOTOOLBOX */
-- 
2.10.1 (Apple Git-78)

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


Re: [FFmpeg-devel] aac_latm: SSR is not implemented

2017-02-16 Thread Aman Gupta
On Wed, Feb 1, 2017 at 9:12 AM Carl Eugen Hoyos <ceffm...@gmail.com> wrote:

> 2017-02-01 5:06 GMT+01:00 Aman Gupta <ffm...@tmm1.net>:
> > I have a mpegts file with a HE-AAC audio track that cannot be decoded by
> > ffmpeg. I have uploaded a sample at the link below, as requested by the
> > decoder.
>
> Maybe ticket #4544, thank you for the sample!
>

Looks like that ticket was a separate issue, but I ended up leaving some
comments in there accidentally about SSR support.

Not sure if this list is the best place to ask, but I would be interested
in financially sponsoring the development of this feature. There is a
partial implementation availabile already in the gsoc svn repo that would
need to be rebased on to master.

If anyone is interested and has time, contact me off-list with a quote.

Thanks,
Aman


> Carl Eugen
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] lavc/videotoolboxenc: implement a53cc

2016-09-08 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

---
 libavcodec/videotoolboxenc.c | 76 ++--
 1 file changed, 67 insertions(+), 9 deletions(-)

diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index 4345ca3..859dde9 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -32,6 +32,7 @@
 #include "libavutil/pixdesc.h"
 #include "internal.h"
 #include 
+#include "h264.h"
 
 #if !CONFIG_VT_BT2020
 # define kCVImageBufferColorPrimaries_ITU_R_2020   CFSTR("ITU_R_2020")
@@ -55,8 +56,14 @@ typedef enum VTH264Entropy{
 
 static const uint8_t start_code[] = { 0, 0, 0, 1 };
 
+typedef struct ExtraSEI {
+  void *data;
+  size_t size;
+} ExtraSEI;
+
 typedef struct BufNode {
 CMSampleBufferRef cm_buffer;
+ExtraSEI *sei;
 struct BufNode* next;
 int error;
 } BufNode;
@@ -94,6 +101,7 @@ typedef struct VTEncContext {
 bool flushing;
 bool has_b_frames;
 bool warned_color_range;
+bool a53_cc;
 } VTEncContext;
 
 static int vtenc_populate_extradata(AVCodecContext   *avctx,
@@ -136,7 +144,7 @@ static void set_async_error(VTEncContext *vtctx, int err)
 pthread_mutex_unlock(>lock);
 }
 
-static int vtenc_q_pop(VTEncContext *vtctx, bool wait, CMSampleBufferRef *buf)
+static int vtenc_q_pop(VTEncContext *vtctx, bool wait, CMSampleBufferRef *buf, 
ExtraSEI **sei)
 {
 BufNode *info;
 
@@ -173,6 +181,12 @@ static int vtenc_q_pop(VTEncContext *vtctx, bool wait, 
CMSampleBufferRef *buf)
 pthread_mutex_unlock(>lock);
 
 *buf = info->cm_buffer;
+if (sei && *buf) {
+*sei = info->sei;
+} else if (info->sei) {
+if (info->sei->data) av_free(info->sei->data);
+av_free(info->sei);
+}
 av_free(info);
 
 vtctx->frame_ct_out++;
@@ -180,7 +194,7 @@ static int vtenc_q_pop(VTEncContext *vtctx, bool wait, 
CMSampleBufferRef *buf)
 return 0;
 }
 
-static void vtenc_q_push(VTEncContext *vtctx, CMSampleBufferRef buffer)
+static void vtenc_q_push(VTEncContext *vtctx, CMSampleBufferRef buffer, 
ExtraSEI *sei)
 {
 BufNode *info = av_malloc(sizeof(BufNode));
 if (!info) {
@@ -190,6 +204,7 @@ static void vtenc_q_push(VTEncContext *vtctx, 
CMSampleBufferRef buffer)
 
 CFRetain(buffer);
 info->cm_buffer = buffer;
+info->sei = sei;
 info->next = NULL;
 
 pthread_mutex_lock(>lock);
@@ -420,6 +435,7 @@ static void vtenc_output_callback(
 {
 AVCodecContext *avctx = ctx;
 VTEncContext   *vtctx = avctx->priv_data;
+ExtraSEI *sei = sourceFrameCtx;
 
 if (vtctx->async_error) {
 if(sample_buffer) CFRelease(sample_buffer);
@@ -440,7 +456,7 @@ static void vtenc_output_callback(
 }
 }
 
-vtenc_q_push(vtctx, sample_buffer);
+vtenc_q_push(vtctx, sample_buffer, sei);
 }
 
 static int get_length_code_size(
@@ -1258,7 +1274,8 @@ static int copy_replace_length_codes(
 static int vtenc_cm_to_avpacket(
 AVCodecContext*avctx,
 CMSampleBufferRef sample_buffer,
-AVPacket  *pkt)
+AVPacket  *pkt,
+ExtraSEI  *sei)
 {
 VTEncContext *vtctx = avctx->priv_data;
 
@@ -1269,6 +1286,7 @@ static int vtenc_cm_to_avpacket(
 size_t  header_size = 0;
 size_t  in_buf_size;
 size_t  out_buf_size;
+size_t  sei_nalu_size = 0;
 int64_t dts_delta;
 int64_t time_base_num;
 int nalu_count;
@@ -1298,9 +1316,14 @@ static int vtenc_cm_to_avpacket(
 if(status)
 return status;
 
+if (sei) {
+sei_nalu_size = sizeof(start_code) + 3 + sei->size + 1;
+}
+
 in_buf_size = CMSampleBufferGetTotalSampleSize(sample_buffer);
 out_buf_size = header_size +
in_buf_size +
+   sei_nalu_size +
nalu_count * ((int)sizeof(start_code) - 
(int)length_code_size);
 
 status = ff_alloc_packet2(avctx, pkt, out_buf_size, out_buf_size);
@@ -1317,7 +1340,7 @@ static int vtenc_cm_to_avpacket(
 length_code_size,
 sample_buffer,
 pkt->data + header_size,
-pkt->size - header_size
+pkt->size - header_size - sei_nalu_size
 );
 
 if (status) {
@@ -1325,6 +1348,19 @@ static int vtenc_cm_to_avpacket(
 return status;
 }
 
+if (sei_nalu_size > 0) {
+uint8_t *sei_nalu = pkt->data + pkt->size - sei_nalu_size;
+memcpy(sei_nalu, start_code, sizeof(start_code));
+sei_nalu += sizeof(start_code);
+sei_nalu[0] = NAL_SEI;
+sei_nalu[1] = SEI_TYPE_USER_DATA_REGISTERED;
+sei_nalu[2] = sei->size;
+sei_nalu += 3;
+memcpy(sei_nalu, sei->data, sei->size);
+sei_nalu += sei->size;
+sei_nalu[0] = 1; // RBSP
+}
+
 if (is_key_frame) {
 pkt->flags |= AV_PKT_FLAG_KEY;
 }
@@ -1707,6 +1743,7 @@ static int vtenc_send_frame(AVCodecContext *avctx,
 CMTime

Re: [FFmpeg-devel] [PATCH] avformat/hlsenc: implement initial_offset

2016-09-08 Thread Aman Gupta
On Thu, Sep 8, 2016 at 2:55 AM, Steven Liu <lingjiujia...@gmail.com> wrote:

> 2016-09-08 17:46 GMT+08:00 Michael Niedermayer <mich...@niedermayer.cc>:
>
> > On Thu, Sep 08, 2016 at 10:47:42AM +0900, Aman Gupta wrote:
> > > From: Aman Gupta <a...@tmm1.net>
> > >
> > > ---
> > >  doc/muxers.texi  |  4 
> > >  libavformat/hlsenc.c | 13 +++--
> > >  2 files changed, 15 insertions(+), 2 deletions(-)
> >
> > Isnt this redundant with
> > -output_ts_offset
> > ?
> > or how do they differ ?
> >
> > [...]
> > --
> > Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
> >
> > Into a blind darkness they enter who follow after the Ignorance,
> > they as if into a greater darkness enter who devote themselves
> > to the Knowledge alone. -- Isha Upanishad
> >
> >
> >
> Maybe just copy the code from segment.c to hlsenc.c .
>

Yes, I copied directly from segment.c because I wanted the same feature in
the hls encoder.

Was not aware of -output_ts_offset. Perhaps that supersedes the
-initial_offset option?

Aman



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


Re: [FFmpeg-devel] [PATCH] lavc/videotoolboxenc: implement a53cc

2016-09-08 Thread Aman Gupta
On Thursday, September 8, 2016, Carl Eugen Hoyos <ceffm...@gmail.com> wrote:

> 2016-09-08 10:19 GMT+02:00 Aman Gupta <ffm...@tmm1.net <javascript:;>>:
>
> > +{ "a53cc", "Use A53 Closed Captions (if available)",
> OFFSET(a53_cc), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, VE },
>
> Why is this disabled by default?


I copied this from the libx264 and qsv encoders, which also disable by
default. Not sure why.


>
> Carl Eugen
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org <javascript:;>
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] HLS Segmenter and the "hls_time" option

2016-08-30 Thread Aman Gupta
On Fri, Aug 26, 2016 at 2:06 AM, Steven Liu  wrote:

> 2016-08-26 16:58 GMT+08:00 Ibrahim Tachijian :
>
> > Thanks this actually does what I expected it to do.
> > For me this option will help a lot, and we would really be interested in
> > this eventually reaching git.
> >
> > Thanks to Steven Liu's patch we will be able to use this to start live
> > streams faster. Great job!
> >
> > Below follows what command I ran and the output m3u8 playlist.
> >
> > /root/ffmpeg_patched -analyzeduration 100 -i udp://MCAST_ADDR:3301
> -map
> > 0:0 -map 0:1 -c:v libx264 -preset superfast -g 25 -b:v 900k -maxrate 900k
> > -bufsize 2000k -filter:v yadif -c:a libfdk_aac -b:a 64k -hls_time 5
> > *-hls_init_time
> > 1* -hls_list_size 10 -hls_allow_cache 0 -hls_flags delete_segments -f hls
> > /tmp/playlist.m3u8
> >
> > The output M3U8 of patched ffmpeg:
> >
> > #EXTM3U
> > #EXT-X-VERSION:3
> > #EXT-X-ALLOW-CACHE:NO
> > #EXT-X-TARGETDURATION:5
> > #EXT-X-MEDIA-SEQUENCE:3
> > #EXTINF:1.00,
> > playlist3.ts
> > #EXTINF:1.00,
> > playlist4.ts
> > #EXTINF:1.00,
> > playlist5.ts
> > #EXTINF:1.00,
> > playlist6.ts
> > #EXTINF:1.00,
> > playlist7.ts
> > #EXTINF:1.00,
> > playlist8.ts
> > #EXTINF:1.60,
> > playlist9.ts
> > #EXTINF:1.00,
> > playlist10.ts
> > #EXTINF:4.00,
> > playlist11.ts
> > #EXTINF:5.00,
> > playlist12.ts
> >
> >
> > On Fri, Aug 26, 2016 at 8:37 AM Steven Liu 
> > wrote:
> >
> > > 2016-08-26 14:00 GMT+08:00 Steven Liu :
> > >
> > > >
> > > >
> > > > 2016-08-26 10:34 GMT+08:00 Ibrahim Tachijian :
> > > >
> > > >> In my use case scenario I only need it for the very first couple of
> > > >> segments.
> > > >> After 5 segments it is not a problem anymore to have 5 second
> segments
> > > >> only.
> > > >>
> > > >>
> > > >>
> > > >> On Fri, Aug 26, 2016 at 4:25 AM Steven Liu  >
> > > >> wrote:
> > > >>
> > > >> > 2016-08-26 10:10 GMT+08:00 Ibrahim Tachijian :
> > > >> >
> > > >> > > yes that is correct Steven.
> > > >> > >
> > > >> > > On Fri, Aug 26, 2016 at 3:41 AM Steven Liu <
> > lingjiujia...@gmail.com
> > > >
> > > >> > > wrote:
> > > >> > >
> > > >> > > > 2016-08-26 8:17 GMT+08:00 Ibrahim Tachijian  >:
> > > >> > > >
> > > >> > > > > Steven, I am not sure you understood me correctly or
> perhaps I
> > > did
> > > >> > not
> > > >> > > > > explain myself optimally.
> > > >> > > > >
> > > >> > > > > We still want to split by keyframe in a normal fashion. But,
> > for
> > > >> > > example,
> > > >> > > > > would like the first 5 segments to have an "hls_time" of 1s
> > and
> > > >> the
> > > >> > > rest
> > > >> > > > of
> > > >> > > > > the segments after the first 5 to have an "hls_time" of 5s.
> > > >> > > > >
> > > >> > > > > An made up option would be (hls_time_initial Seconds,Number)
> > > >> > > > >
> > > >> > > > >- "-hls_time_initial 1,5 -hls_time 5"
> > > >> > > > >
> > > >> > > > > The output playlist would contain segments (split at
> > keyframes)
> > > 5
> > > >> > > > segments
> > > >> > > > > of length 1s and then any segment after the initial 5
> segment
> > > >> would
> > > >> > be
> > > >> > > > 5s.
> > > >> > > > >
> > > >> > > > > Is it clear what I am trying to explain?
> > > >> > > > >
> > > >> > > > > What do you think? Do you know how this can be achieved?
> > > >> > > > >
> > > >> > > > > Thanks,
> > > >> > > > >
> > > >> > > > > On Fri, Aug 26, 2016 at 2:06 AM Steven Liu <
> > > >> lingjiujia...@gmail.com>
> > > >> > > > > wrote:
> > > >> > > > >
> > > >> > > > > > 2016-08-26 7:39 GMT+08:00 Ibrahim Tachijian <
> > bar...@netsat.se
> > > >:
> > > >> > > > > >
> > > >> > > > > > > Hello,
> > > >> > > > > > >
> > > >> > > > > > > I've been thinking about an option for "hls_time" that
> is
> > > not
> > > >> > > > currently
> > > >> > > > > > > supported by FFMpeg and I would like feedback to if some
> > of
> > > >> you
> > > >> > may
> > > >> > > > > think
> > > >> > > > > > > this is useful or utterly unnecessary.
> > > >> > > > > > >
> > > >> > > > > > > I find scenarios where we sometimes want to create an
> HLS
> > > >> output
> > > >> > > and
> > > >> > > > > > would
> > > >> > > > > > > like the *first couple of segments* to be shorter than
> the
> > > >> *rest
> > > >> > of
> > > >> > > > the
> > > >> > > > > > > segments.*
> > > >> > > > > > >
> > > >> > > > > > > For example starting off with 1s segments up to N
> segments
> > > >> then
> > > >> > > > switch
> > > >> > > > > to
> > > >> > > > > > > 5s segments.
> > > >> > > > > > >
> > > >> > > > > > > The reasoning is simply to have the playlist.m3u8 and
> > first
> > > >> > segment
> > > >> > > > > > > available *asap.*
> > > >> > > > > > >
> > > >> > > > > > > What do you think? Do you know how this can be achieved?
> > > >> > > > > > >
> > > >> > > > > > > Thanks,
> > > >> > > > > > >
> > > >> > > > > >
> > > 

[FFmpeg-devel] [PATCH] avformat/hlsenc: implement initial_offset

2016-09-07 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

---
 doc/muxers.texi  |  4 
 libavformat/hlsenc.c | 13 +++--
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index fd7ee50..e88dbf8 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -389,6 +389,10 @@ to @var{wrap}.
 Start the playlist sequence number from @var{number}. Default value is
 0.
 
+@item initial_offset @var{offset}
+Specify timestamp offset to apply to the output packet timestamps. The
+argument must be a time duration specification, and defaults to 0.
+
 @item hls_allow_cache @var{allowcache}
 Explicitly set whether the client MAY (1) or MUST NOT (0) cache media segments.
 
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 1846d9d..be58db8 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -90,6 +90,7 @@ typedef struct HLSContext {
 uint32_t pl_type;  // enum PlaylistType
 char *segment_filename;
 
+int64_t initial_offset; ///< initial timestamps offset, expressed in 
microseconds
 int use_localtime;  ///< flag to expand filename with localtime
 int use_localtime_mkdir;///< flag to mkdir dirname in timebased filename
 int allowcache;
@@ -795,7 +796,7 @@ static int hls_write_packet(AVFormatContext *s, AVPacket 
*pkt)
 HLSContext *hls = s->priv_data;
 AVFormatContext *oc = NULL;
 AVStream *st = s->streams[pkt->stream_index];
-int64_t end_pts = hls->recording_time * hls->number;
+int64_t end_pts = hls->recording_time * hls->number, offset;
 int is_ref_pkt = 1;
 int ret, can_split = 1;
 int stream_index = 0;
@@ -871,7 +872,14 @@ static int hls_write_packet(AVFormatContext *s, AVPacket 
*pkt)
 return ret;
 }
 
-ret = ff_write_chained(oc, stream_index, pkt, s, 0);
+/* compute new timestamps */
+offset = av_rescale_q(hls->initial_offset, AV_TIME_BASE_Q, st->time_base);
+if (pkt->pts != AV_NOPTS_VALUE)
+pkt->pts += offset;
+if (pkt->dts != AV_NOPTS_VALUE)
+pkt->dts += offset;
+
+ret = ff_write_chained(oc, stream_index, pkt, s, hls->initial_offset ? 1 : 
0);
 
 return ret;
 }
@@ -939,6 +947,7 @@ static const AVOption options[] = {
 {"event", "EVENT playlist", 0, AV_OPT_TYPE_CONST, {.i64 = 
PLAYLIST_TYPE_EVENT }, INT_MIN, INT_MAX, E, "pl_type" },
 {"vod", "VOD playlist", 0, AV_OPT_TYPE_CONST, {.i64 = PLAYLIST_TYPE_VOD }, 
INT_MIN, INT_MAX, E, "pl_type" },
 {"method", "set the HTTP method", OFFSET(method), AV_OPT_TYPE_STRING, 
{.str = NULL},  0, 0,E},
+{"initial_offset", "set initial timestamp offset", OFFSET(initial_offset), 
AV_OPT_TYPE_DURATION, {.i64 = 0}, -INT64_MAX, INT64_MAX, E },
 
 { NULL },
 };
-- 
2.8.1

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


[FFmpeg-devel] [PATCH] lavf/hlsenc: add -hls_start_time to emit EXT-X-START:TIME-OFFSET

2016-09-10 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

---
 doc/muxers.texi  | 3 +++
 libavformat/hlsenc.c | 5 +
 2 files changed, 8 insertions(+)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index ccf8ea1..e179c5a 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -533,6 +533,9 @@ Emit @code{#EXT-X-PLAYLIST-TYPE:EVENT} in the m3u8 header. 
Forces
 Emit @code{#EXT-X-PLAYLIST-TYPE:VOD} in the m3u8 header. Forces
 @option{hls_list_size} to 0; the playlist must not change.
 
+@item hls_start_time @var{offset}
+Emit @code{#EXT-X-START:TIME-OFFSET} in the m3u8 header.
+
 @item method
 Use the given HTTP method to create the hls files.
 @example
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index a376312..1344613d 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -79,6 +79,7 @@ typedef struct HLSContext {
 unsigned number;
 int64_t sequence;
 int64_t start_sequence;
+float start_offset;
 AVOutputFormat *oformat;
 AVOutputFormat *vtt_oformat;
 
@@ -511,6 +512,9 @@ static int hls_window(AVFormatContext *s, int last)
 } else if (hls->pl_type == PLAYLIST_TYPE_VOD) {
 avio_printf(out, "#EXT-X-PLAYLIST-TYPE:VOD\n");
 }
+if (hls->start_offset >= 0) {
+avio_printf(out, "#EXT-X-START:TIME-OFFSET=%f\n", hls->start_offset);
+}
 
 av_log(s, AV_LOG_VERBOSE, "EXT-X-MEDIA-SEQUENCE:%"PRId64"\n",
sequence);
@@ -1013,6 +1017,7 @@ static const AVOption options[] = {
 {"hls_list_size", "set maximum number of playlist entries",  
OFFSET(max_nb_segments),AV_OPT_TYPE_INT,{.i64 = 5}, 0, INT_MAX, E},
 {"hls_ts_options","set hls mpegts list of options for the container format 
used for hls", OFFSET(format_options_str), AV_OPT_TYPE_STRING, {.str = NULL},  
0, 0,E},
 {"hls_vtt_options","set hls vtt list of options for the container format 
used for hls", OFFSET(vtt_format_options_str), AV_OPT_TYPE_STRING, {.str = 
NULL},  0, 0,E},
+{"hls_start_time", "set EXT-X-START:TIME-OFFSET",   
OFFSET(start_offset),AV_OPT_TYPE_FLOAT,  {.dbl = -1}, -1, FLT_MAX, E},
 {"hls_wrap",  "set number after which the index wraps",  OFFSET(wrap), 
   AV_OPT_TYPE_INT,{.i64 = 0}, 0, INT_MAX, E},
 {"hls_allow_cache", "explicitly set whether the client MAY (1) or MUST NOT 
(0) cache media segments", OFFSET(allowcache), AV_OPT_TYPE_INT, {.i64 = -1}, 
INT_MIN, INT_MAX, E},
 {"hls_base_url",  "url to prepend to each playlist entry",   
OFFSET(baseurl), AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,   E},
-- 
2.8.1

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


Re: [FFmpeg-devel] [PATCH 1/2] avformat/segment: give a warning message for remove initial_offset option

2016-09-08 Thread Aman Gupta
I tried to switch from -initial_offset to -output_ts_offset, but it does
not work as expected. In Safari, the generated HLS stream stalls out and
stops playing after the first segment.

Aman

On Thu, Sep 8, 2016 at 5:54 PM, Michael Niedermayer 
wrote:

> On Fri, Sep 09, 2016 at 02:59:52AM +0800, Steven Liu wrote:
> > 2016-09-08 22:52 GMT+08:00 Carl Eugen Hoyos :
> >
> > > 2016-09-08 16:01 GMT+02:00 Steven Liu :
> > >
> > > > +if (seg->initial_offset > 0) {
> > > > +av_log(s, AV_LOG_WARNING, "NOTE: the option initial_offset
> will
> > > be
> > > > deprecated soon,"
> > >
> > > "is deprecated" even if you decide not to ignore the value set.
> > >
> > > Carl Eugen
> > >
> >
> > Sorry for my poor English,
>
> fixed the english and applied
>
>
> > What about "be removed"?
>
> that would have worked too
>
> the option is deprecated
> see https://en.wiktionary.org/wiki/deprecate#English
> "To declare something obsolescent; to recommend against a function,
> technique, command, etc. that still works but has been replaced. "
>
> [...]
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> Many things microsoft did are stupid, but not doing something just because
> microsoft did it is even more stupid. If everything ms did were stupid they
> would be bankrupt already.
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 1/2] avformat/segment: give a warning message for remove initial_offset option

2016-09-08 Thread Aman Gupta
Yea this doesn't work at all. I wish someone had bothered to check before
the patch was proposed or merged.

With "-ss 20 -i file -segment_time 2 -segment_start_number 10
-initial_offset 20":

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-ALLOW-CACHE:YES
#EXT-X-TARGETDURATION:3
#EXTINF:2.023344,
out10.ts
#EXTINF:2.002011,
out11.ts
#EXTINF:2.002011,
out12.ts


With "-ss 20 -i file -segment_time 2 -segment_start_number 10
-output_ts_offset 20":

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-ALLOW-CACHE:YES
#EXT-X-TARGETDURATION:21
#EXTINF:20.200211,
out10.ts
#EXTINF:0.200211,
out11.ts
#EXTINF:0.200211,
out12.ts


The TARGETDURATION as well as the duration of the segments themselves is
incorrect.

Aman

On Thu, Sep 8, 2016 at 6:48 PM, Aman Gupta <ffm...@tmm1.net> wrote:

> I tried to switch from -initial_offset to -output_ts_offset, but it does
> not work as expected. In Safari, the generated HLS stream stalls out and
> stops playing after the first segment.
>
> Aman
>
> On Thu, Sep 8, 2016 at 5:54 PM, Michael Niedermayer <
> mich...@niedermayer.cc> wrote:
>
>> On Fri, Sep 09, 2016 at 02:59:52AM +0800, Steven Liu wrote:
>> > 2016-09-08 22:52 GMT+08:00 Carl Eugen Hoyos <ceffm...@gmail.com>:
>> >
>> > > 2016-09-08 16:01 GMT+02:00 Steven Liu <lingjiujia...@gmail.com>:
>> > >
>> > > > +if (seg->initial_offset > 0) {
>> > > > +av_log(s, AV_LOG_WARNING, "NOTE: the option initial_offset
>> will
>> > > be
>> > > > deprecated soon,"
>> > >
>> > > "is deprecated" even if you decide not to ignore the value set.
>> > >
>> > > Carl Eugen
>> > >
>> >
>> > Sorry for my poor English,
>>
>> fixed the english and applied
>>
>>
>> > What about "be removed"?
>>
>> that would have worked too
>>
>> the option is deprecated
>> see https://en.wiktionary.org/wiki/deprecate#English
>> "To declare something obsolescent; to recommend against a function,
>> technique, command, etc. that still works but has been replaced. "
>>
>> [...]
>> --
>> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>>
>> Many things microsoft did are stupid, but not doing something just because
>> microsoft did it is even more stupid. If everything ms did were stupid
>> they
>> would be bankrupt already.
>>
>> ___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavc/videotoolboxenc: implement a53cc

2016-09-10 Thread Aman Gupta
On Sunday, September 11, 2016, Richard Kern <ker...@gmail.com> wrote:

>
> > On Sep 8, 2016, at 4:19 AM, Aman Gupta <ffm...@tmm1.net <javascript:;>>
> wrote:
> >
> > From: Aman Gupta <a...@tmm1.net <javascript:;>>
> >
> > ---
> > libavcodec/videotoolboxenc.c | 76 ++
> --
> > 1 file changed, 67 insertions(+), 9 deletions(-)
> >
> > diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
> > index 4345ca3..859dde9 100644
> > --- a/libavcodec/videotoolboxenc.c
> > +++ b/libavcodec/videotoolboxenc.c
> > @@ -32,6 +32,7 @@
> > #include "libavutil/pixdesc.h"
> > #include "internal.h"
> > #include 
> > +#include "h264.h"
> >
> > #if !CONFIG_VT_BT2020
> > # define kCVImageBufferColorPrimaries_ITU_R_2020   CFSTR("ITU_R_2020")
> > @@ -55,8 +56,14 @@ typedef enum VTH264Entropy{
> >
> > static const uint8_t start_code[] = { 0, 0, 0, 1 };
> >
> > +typedef struct ExtraSEI {
> > +  void *data;
> > +  size_t size;
> > +} ExtraSEI;
> > +
> > typedef struct BufNode {
> > CMSampleBufferRef cm_buffer;
> > +ExtraSEI *sei;
> > struct BufNode* next;
> > int error;
> > } BufNode;
> > @@ -94,6 +101,7 @@ typedef struct VTEncContext {
> > bool flushing;
> > bool has_b_frames;
> > bool warned_color_range;
> > +bool a53_cc;
> > } VTEncContext;
> >
> > static int vtenc_populate_extradata(AVCodecContext   *avctx,
> > @@ -136,7 +144,7 @@ static void set_async_error(VTEncContext *vtctx, int
> err)
> > pthread_mutex_unlock(>lock);
> > }
> >
> > -static int vtenc_q_pop(VTEncContext *vtctx, bool wait,
> CMSampleBufferRef *buf)
> > +static int vtenc_q_pop(VTEncContext *vtctx, bool wait,
> CMSampleBufferRef *buf, ExtraSEI **sei)
> > {
> > BufNode *info;
> >
> > @@ -173,6 +181,12 @@ static int vtenc_q_pop(VTEncContext *vtctx, bool
> wait, CMSampleBufferRef *buf)
> > pthread_mutex_unlock(>lock);
> >
> > *buf = info->cm_buffer;
> > +if (sei && *buf) {
> > +*sei = info->sei;
> > +} else if (info->sei) {
> > +if (info->sei->data) av_free(info->sei->data);
> > +av_free(info->sei);
> > +}
> > av_free(info);
> >
> > vtctx->frame_ct_out++;
> > @@ -180,7 +194,7 @@ static int vtenc_q_pop(VTEncContext *vtctx, bool
> wait, CMSampleBufferRef *buf)
> > return 0;
> > }
> >
> > -static void vtenc_q_push(VTEncContext *vtctx, CMSampleBufferRef buffer)
> > +static void vtenc_q_push(VTEncContext *vtctx, CMSampleBufferRef buffer,
> ExtraSEI *sei)
> > {
> > BufNode *info = av_malloc(sizeof(BufNode));
> > if (!info) {
> > @@ -190,6 +204,7 @@ static void vtenc_q_push(VTEncContext *vtctx,
> CMSampleBufferRef buffer)
> >
> > CFRetain(buffer);
> > info->cm_buffer = buffer;
> > +info->sei = sei;
> > info->next = NULL;
> >
> > pthread_mutex_lock(>lock);
> > @@ -420,6 +435,7 @@ static void vtenc_output_callback(
> > {
> > AVCodecContext *avctx = ctx;
> > VTEncContext   *vtctx = avctx->priv_data;
> > +ExtraSEI *sei = sourceFrameCtx;
> >
> > if (vtctx->async_error) {
> > if(sample_buffer) CFRelease(sample_buffer);
> > @@ -440,7 +456,7 @@ static void vtenc_output_callback(
> > }
> > }
> >
> > -vtenc_q_push(vtctx, sample_buffer);
> > +vtenc_q_push(vtctx, sample_buffer, sei);
> > }
> >
> > static int get_length_code_size(
> > @@ -1258,7 +1274,8 @@ static int copy_replace_length_codes(
> > static int vtenc_cm_to_avpacket(
> > AVCodecContext*avctx,
> > CMSampleBufferRef sample_buffer,
> > -AVPacket  *pkt)
> > +AVPacket  *pkt,
> > +ExtraSEI  *sei)
> > {
> > VTEncContext *vtctx = avctx->priv_data;
> >
> > @@ -1269,6 +1286,7 @@ static int vtenc_cm_to_avpacket(
> > size_t  header_size = 0;
> > size_t  in_buf_size;
> > size_t  out_buf_size;
> > +size_t  sei_nalu_size = 0;
> > int64_t dts_delta;
> > int64_t time_base_num;
> > int nalu_count;
> > @@ -1298,9 +1316,14 @@ static int vtenc_cm_to_avpacket(
> > if(status)
> > return status;
> >
> > +if (sei) {
> > +sei_nalu_si

Re: [FFmpeg-devel] [PATCH] lavc/videotoolboxenc: implement a53cc

2016-09-08 Thread Aman Gupta
On Thu, Sep 8, 2016 at 9:18 AM, Carl Eugen Hoyos <ceffm...@gmail.com> wrote:

> 2016-09-08 15:48 GMT+02:00 Aman Gupta <themastermi...@gmail.com>:
> > On Thursday, September 8, 2016, Carl Eugen Hoyos <ceffm...@gmail.com>
> wrote:
> >
> >> 2016-09-08 10:19 GMT+02:00 Aman Gupta <ffm...@tmm1.net <javascript:;>>:
> >>
> >> > +{ "a53cc", "Use A53 Closed Captions (if available)",
> >> OFFSET(a53_cc), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, VE },
> >>
> >> Why is this disabled by default?
> >
> > I copied this from the libx264 and qsv encoders, which also disable by
> > default. Not sure why.
>
> If you believe it should be enabled by default, please send a patch that
> enables the function by default.
> (If there is no issue, the others can be fixed.)
>

I don't have a good enough understanding of the possible consequences to
feel comfortable enabling it by default yet.


>
> Thank you, Carl Eugen
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avformat/segment: fix the duration error of use output_ts_offset

2016-09-09 Thread Aman Gupta
I confirmed your latest patch fixes the issue and is working as expected
now.

Thank you!

Aman

On Sat, Sep 10, 2016 at 7:00 AM, Steven Liu <lingjiujia...@gmail.com> wrote:

>
> Steven Liu <lingjiujia...@gmail.com>于2016年9月9日 周五下午7:59写道:
>
>> 2016-09-09 16:33 GMT+08:00 Steven Liu <lingjiujia...@gmail.com>:
>>
>>>
>>>
>>> 2016-09-09 16:10 GMT+08:00 Steven Liu <lingjiujia...@gmail.com>:
>>>
>>>>
>>>>
>>>> 2016-09-09 15:33 GMT+08:00 Steven Liu <lingjiujia...@gmail.com>:
>>>>
>>>>>
>>>>>
>>>>> 2016-09-09 15:28 GMT+08:00 Aman Gupta <a...@tmm1.net>:
>>>>>
>>>>>> I tried your patch and TARGETDURATION is fixed, but it is still
>>>>>> creating some segments which are only 0.2s instead of 2s.
>>>>>>
>>>>>> Aman
>>>>>>
>>>>>> On Thu, Sep 8, 2016 at 8:14 PM, Steven Liu <lingjiujia...@gmail.com>
>>>>>> wrote:
>>>>>>
>>>>>>> This patch can merge with 1da00be009aa74400042bf470b9a5ffbd82a1c5e
>>>>>>> i have checked this modify:
>>>>>>>
>>>>>>> ./ffmpeg -i ~/facebook.mp4 -c copy -f segment -segment_time 2
>>>>>>> -output_ts_offset 80 -segment_list output-test.m3u8 -v debug
>>>>>>> output-test-%03d.ts
>>>>>>>
>>>>>>> #EXTM3U
>>>>>>> #EXT-X-VERSION:3
>>>>>>> #EXT-X-MEDIA-SEQUENCE:0
>>>>>>> #EXT-X-ALLOW-CACHE:YES
>>>>>>> #EXT-X-TARGETDURATION:10
>>>>>>> #EXTINF:4.12,
>>>>>>> output-test-000.ts
>>>>>>> #EXTINF:7.84,
>>>>>>> output-test-001.ts
>>>>>>> #EXTINF:4.20,
>>>>>>> output-test-002.ts
>>>>>>> #EXTINF:2.92,
>>>>>>> output-test-003.ts
>>>>>>> #EXTINF:1.84,
>>>>>>> output-test-004.ts
>>>>>>> #EXTINF:2.24,
>>>>>>> output-test-005.ts
>>>>>>> #EXTINF:2.00,
>>>>>>> output-test-006.ts
>>>>>>> #EXTINF:3.56,
>>>>>>>
>>>>>>>
>>>>>>> [root@localhost linux]# ffmpeg -i output-test.m3u8
>>>>>>> ffmpeg version N-80917-ga1a240b Copyright (c) 2000-2016 the FFmpeg
>>>>>>> developers
>>>>>>>   built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-17)
>>>>>>>   configuration: --prefix=/usr/ --libdir=/usr/lib64 --enable-libx264
>>>>>>> --enable-libfaac --enable-gpl --enable-nonfree
>>>>>>>   libavutil  55. 28.100 / 55. 28.100
>>>>>>>   libavcodec 57. 48.102 / 57. 48.102
>>>>>>>   libavformat57. 41.100 / 57. 41.100
>>>>>>>   libavdevice57.  0.102 / 57.  0.102
>>>>>>>   libavfilter 6. 47.100 /  6. 47.100
>>>>>>>   libswscale  4.  1.100 /  4.  1.100
>>>>>>>   libswresample   2.  1.100 /  2.  1.100
>>>>>>>   libpostproc54.  0.100 / 54.  0.100
>>>>>>> Input #0, hls,applehttp, from 'output-test.m3u8':
>>>>>>>   Duration: 00:03:21.04, start: 81.40, bitrate: 0 kb/s
>>>>>>>   Program 0
>>>>>>> Metadata:
>>>>>>>   variant_bitrate : 0
>>>>>>> Stream #0:0: Video: h264 (High) ([27][0][0][0] / 0x001B),
>>>>>>> yuv420p, 720x528 [SAR 1:1 DAR 15:11], 25 fps, 25 tbr, 90k tbn, 50 tbc
>>>>>>> Stream #0:1: Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz,
>>>>>>> 5.1(side), fltp, 384 kb/s
>>>>>>> At least one output file must be specified
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> [root@localhost linux]# ffmpeg -i output-test-000.ts -i
>>>>>>> output-test-001.ts
>>>>>>> ffmpeg version N-80917-ga1a240b Copyright (c) 2000-2016 the FFmpeg
>>>>>>> developers
>>>>>>>   built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-17)
>>>>>>>   configuration: --prefix=/usr/ --libdir=/usr/lib64 --enable-libx264
>>>>>>> --enable-libfaac --enable-gpl --enable-nonfree
>>

Re: [FFmpeg-devel] [PATCH] lavc/videotoolboxenc: implement a53cc

2016-09-19 Thread Aman Gupta
On Monday, September 19, 2016, Richard Kern <ker...@gmail.com> wrote:

>
> On Sep 10, 2016, at 10:33 PM, Aman Gupta <ffm...@tmm1.net
> <javascript:_e(%7B%7D,'cvml','ffm...@tmm1.net');>> wrote:
>
>
>
> On Sunday, September 11, 2016, Richard Kern <ker...@gmail.com
> <javascript:_e(%7B%7D,'cvml','ker...@gmail.com');>> wrote:
>
>>
>> > On Sep 8, 2016, at 4:19 AM, Aman Gupta <ffm...@tmm1.net> wrote:
>> >
>> > From: Aman Gupta <a...@tmm1.net>
>> >
>> > ---
>> > libavcodec/videotoolboxenc.c | 76 ++
>> --
>> > 1 file changed, 67 insertions(+), 9 deletions(-)
>> >
>> > diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
>> > index 4345ca3..859dde9 100644
>> > --- a/libavcodec/videotoolboxenc.c
>> > +++ b/libavcodec/videotoolboxenc.c
>> > @@ -32,6 +32,7 @@
>> > #include "libavutil/pixdesc.h"
>> > #include "internal.h"
>> > #include 
>> > +#include "h264.h"
>> >
>> > #if !CONFIG_VT_BT2020
>> > # define kCVImageBufferColorPrimaries_ITU_R_2020   CFSTR("ITU_R_2020")
>> > @@ -55,8 +56,14 @@ typedef enum VTH264Entropy{
>> >
>> > static const uint8_t start_code[] = { 0, 0, 0, 1 };
>> >
>> > +typedef struct ExtraSEI {
>> > +  void *data;
>> > +  size_t size;
>> > +} ExtraSEI;
>> > +
>> > typedef struct BufNode {
>> > CMSampleBufferRef cm_buffer;
>> > +ExtraSEI *sei;
>> > struct BufNode* next;
>> > int error;
>> > } BufNode;
>> > @@ -94,6 +101,7 @@ typedef struct VTEncContext {
>> > bool flushing;
>> > bool has_b_frames;
>> > bool warned_color_range;
>> > +bool a53_cc;
>> > } VTEncContext;
>> >
>> > static int vtenc_populate_extradata(AVCodecContext   *avctx,
>> > @@ -136,7 +144,7 @@ static void set_async_error(VTEncContext *vtctx,
>> int err)
>> > pthread_mutex_unlock(>lock);
>> > }
>> >
>> > -static int vtenc_q_pop(VTEncContext *vtctx, bool wait,
>> CMSampleBufferRef *buf)
>> > +static int vtenc_q_pop(VTEncContext *vtctx, bool wait,
>> CMSampleBufferRef *buf, ExtraSEI **sei)
>> > {
>> > BufNode *info;
>> >
>> > @@ -173,6 +181,12 @@ static int vtenc_q_pop(VTEncContext *vtctx, bool
>> wait, CMSampleBufferRef *buf)
>> > pthread_mutex_unlock(>lock);
>> >
>> > *buf = info->cm_buffer;
>> > +if (sei && *buf) {
>> > +*sei = info->sei;
>> > +} else if (info->sei) {
>> > +if (info->sei->data) av_free(info->sei->data);
>> > +av_free(info->sei);
>> > +}
>> > av_free(info);
>> >
>> > vtctx->frame_ct_out++;
>> > @@ -180,7 +194,7 @@ static int vtenc_q_pop(VTEncContext *vtctx, bool
>> wait, CMSampleBufferRef *buf)
>> > return 0;
>> > }
>> >
>> > -static void vtenc_q_push(VTEncContext *vtctx, CMSampleBufferRef buffer)
>> > +static void vtenc_q_push(VTEncContext *vtctx, CMSampleBufferRef
>> buffer, ExtraSEI *sei)
>> > {
>> > BufNode *info = av_malloc(sizeof(BufNode));
>> > if (!info) {
>> > @@ -190,6 +204,7 @@ static void vtenc_q_push(VTEncContext *vtctx,
>> CMSampleBufferRef buffer)
>> >
>> > CFRetain(buffer);
>> > info->cm_buffer = buffer;
>> > +info->sei = sei;
>> > info->next = NULL;
>> >
>> > pthread_mutex_lock(>lock);
>> > @@ -420,6 +435,7 @@ static void vtenc_output_callback(
>> > {
>> > AVCodecContext *avctx = ctx;
>> > VTEncContext   *vtctx = avctx->priv_data;
>> > +ExtraSEI *sei = sourceFrameCtx;
>> >
>> > if (vtctx->async_error) {
>> > if(sample_buffer) CFRelease(sample_buffer);
>> > @@ -440,7 +456,7 @@ static void vtenc_output_callback(
>> > }
>> > }
>> >
>> > -vtenc_q_push(vtctx, sample_buffer);
>> > +vtenc_q_push(vtctx, sample_buffer, sei);
>> > }
>> >
>> > static int get_length_code_size(
>> > @@ -1258,7 +1274,8 @@ static int copy_replace_length_codes(
>> > static int vtenc_cm_to_avpacket(
>> > AVCodecContext*avctx,
>> > CMSampleBufferRef sample_b

[FFmpeg-devel] [PATCH] lavc/videotoolbox: fix avcc creation for h264 streams missing extradata

2016-10-19 Thread Aman Gupta
From: Aman Gupta <a...@tmm1.net>

ff_videotoolbox_avcc_extradata_create() was never being called if
avctx->extradata_size==0, even though the function does not need or use
the avctx->extradata.

This manifested itself only on h264 streams in specific containers, and
only on iOS. I guess the macOS version of VideoToolbox is more
forgiving, atleast on my specific combination of OS version and hardware.

I also added an error log message when VTDecompressionSessionCreate()
fails, to help the next poor soul who runs into a bug in this area of the
code. The native OSStatus error codes are much easier to google than
their AVERROR counterparts (especially in this case, with AVERROR_UNKNOWN).
---
 libavcodec/videotoolbox.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
index 1288aa5..b21eccb 100644
--- a/libavcodec/videotoolbox.c
+++ b/libavcodec/videotoolbox.c
@@ -413,7 +413,7 @@ static CFDictionaryRef 
videotoolbox_decoder_config_create(CMVideoCodecType codec
  
kVTVideoDecoderSpecification_RequireHardwareAcceleratedVideoDecoder,
  kCFBooleanTrue);
 
-if (avctx->extradata_size) {
+if (avctx->extradata_size || codec_type == kCMVideoCodecType_H264) {
 CFMutableDictionaryRef avc_info;
 CFDataRef data = NULL;
 
@@ -572,13 +572,16 @@ static int videotoolbox_default_init(AVCodecContext 
*avctx)
 if (buf_attr)
 CFRelease(buf_attr);
 
+if (status != 0)
+av_log(avctx, AV_LOG_ERROR, "Error creating videotoolbox decompression 
session: %d\n", status);
+
 switch (status) {
 case kVTVideoDecoderNotAvailableNowErr:
 case kVTVideoDecoderUnsupportedDataFormatErr:
 return AVERROR(ENOSYS);
 case kVTVideoDecoderMalfunctionErr:
 return AVERROR(EINVAL);
-case kVTVideoDecoderBadDataErr :
+case kVTVideoDecoderBadDataErr:
 return AVERROR_INVALIDDATA;
 case 0:
 return 0;
-- 
2.8.1

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


Re: [FFmpeg-devel] [PATCH] lavc/videotoolboxenc: implement a53cc

2016-10-24 Thread Aman Gupta
On Monday, September 19, 2016, Richard Kern <ker...@gmail.com> wrote:

>
> On Sep 10, 2016, at 10:33 PM, Aman Gupta <ffm...@tmm1.net
> <javascript:_e(%7B%7D,'cvml','ffm...@tmm1.net');>> wrote:
>
>
>
> On Sunday, September 11, 2016, Richard Kern <ker...@gmail.com
> <javascript:_e(%7B%7D,'cvml','ker...@gmail.com');>> wrote:
>
>>
>> > On Sep 8, 2016, at 4:19 AM, Aman Gupta <ffm...@tmm1.net> wrote:
>> >
>> > From: Aman Gupta <a...@tmm1.net>
>> >
>> > ---
>> > libavcodec/videotoolboxenc.c | 76 ++
>> --
>> > 1 file changed, 67 insertions(+), 9 deletions(-)
>> >
>> > diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
>> > index 4345ca3..859dde9 100644
>> > --- a/libavcodec/videotoolboxenc.c
>> > +++ b/libavcodec/videotoolboxenc.c
>> > @@ -32,6 +32,7 @@
>> > #include "libavutil/pixdesc.h"
>> > #include "internal.h"
>> > #include 
>> > +#include "h264.h"
>> >
>> > #if !CONFIG_VT_BT2020
>> > # define kCVImageBufferColorPrimaries_ITU_R_2020   CFSTR("ITU_R_2020")
>> > @@ -55,8 +56,14 @@ typedef enum VTH264Entropy{
>> >
>> > static const uint8_t start_code[] = { 0, 0, 0, 1 };
>> >
>> > +typedef struct ExtraSEI {
>> > +  void *data;
>> > +  size_t size;
>> > +} ExtraSEI;
>> > +
>> > typedef struct BufNode {
>> > CMSampleBufferRef cm_buffer;
>> > +ExtraSEI *sei;
>> > struct BufNode* next;
>> > int error;
>> > } BufNode;
>> > @@ -94,6 +101,7 @@ typedef struct VTEncContext {
>> > bool flushing;
>> > bool has_b_frames;
>> > bool warned_color_range;
>> > +bool a53_cc;
>> > } VTEncContext;
>> >
>> > static int vtenc_populate_extradata(AVCodecContext   *avctx,
>> > @@ -136,7 +144,7 @@ static void set_async_error(VTEncContext *vtctx,
>> int err)
>> > pthread_mutex_unlock(>lock);
>> > }
>> >
>> > -static int vtenc_q_pop(VTEncContext *vtctx, bool wait,
>> CMSampleBufferRef *buf)
>> > +static int vtenc_q_pop(VTEncContext *vtctx, bool wait,
>> CMSampleBufferRef *buf, ExtraSEI **sei)
>> > {
>> > BufNode *info;
>> >
>> > @@ -173,6 +181,12 @@ static int vtenc_q_pop(VTEncContext *vtctx, bool
>> wait, CMSampleBufferRef *buf)
>> > pthread_mutex_unlock(>lock);
>> >
>> > *buf = info->cm_buffer;
>> > +if (sei && *buf) {
>> > +*sei = info->sei;
>> > +} else if (info->sei) {
>> > +if (info->sei->data) av_free(info->sei->data);
>> > +av_free(info->sei);
>> > +}
>> > av_free(info);
>> >
>> > vtctx->frame_ct_out++;
>> > @@ -180,7 +194,7 @@ static int vtenc_q_pop(VTEncContext *vtctx, bool
>> wait, CMSampleBufferRef *buf)
>> > return 0;
>> > }
>> >
>> > -static void vtenc_q_push(VTEncContext *vtctx, CMSampleBufferRef buffer)
>> > +static void vtenc_q_push(VTEncContext *vtctx, CMSampleBufferRef
>> buffer, ExtraSEI *sei)
>> > {
>> > BufNode *info = av_malloc(sizeof(BufNode));
>> > if (!info) {
>> > @@ -190,6 +204,7 @@ static void vtenc_q_push(VTEncContext *vtctx,
>> CMSampleBufferRef buffer)
>> >
>> > CFRetain(buffer);
>> > info->cm_buffer = buffer;
>> > +info->sei = sei;
>> > info->next = NULL;
>> >
>> > pthread_mutex_lock(>lock);
>> > @@ -420,6 +435,7 @@ static void vtenc_output_callback(
>> > {
>> > AVCodecContext *avctx = ctx;
>> > VTEncContext   *vtctx = avctx->priv_data;
>> > +ExtraSEI *sei = sourceFrameCtx;
>> >
>> > if (vtctx->async_error) {
>> > if(sample_buffer) CFRelease(sample_buffer);
>> > @@ -440,7 +456,7 @@ static void vtenc_output_callback(
>> > }
>> > }
>> >
>> > -vtenc_q_push(vtctx, sample_buffer);
>> > +vtenc_q_push(vtctx, sample_buffer, sei);
>> > }
>> >
>> > static int get_length_code_size(
>> > @@ -1258,7 +1274,8 @@ static int copy_replace_length_codes(
>> > static int vtenc_cm_to_avpacket(
>> > AVCodecContext*avctx,
>> > CMSampleBufferRef sample_b

Re: [FFmpeg-devel] [PATCH] lavc/videotoolboxenc: implement a53cc

2016-10-17 Thread Aman Gupta
On Mon, Oct 17, 2016 at 6:35 AM, Richard Kern <ker...@gmail.com> wrote:

>
> On Sep 19, 2016, at 10:30 AM, Aman Gupta <ffm...@tmm1.net> wrote:
>
>
>
> On Monday, September 19, 2016, Richard Kern <ker...@gmail.com> wrote:
>
>>
>> On Sep 10, 2016, at 10:33 PM, Aman Gupta <ffm...@tmm1.net> wrote:
>>
>>
>>
>> On Sunday, September 11, 2016, Richard Kern <ker...@gmail.com> wrote:
>>
>>>
>>> > On Sep 8, 2016, at 4:19 AM, Aman Gupta <ffm...@tmm1.net> wrote:
>>> >
>>> > From: Aman Gupta <a...@tmm1.net>
>>> >
>>> > ---
>>> > libavcodec/videotoolboxenc.c | 76 ++
>>> --
>>> > 1 file changed, 67 insertions(+), 9 deletions(-)
>>> >
>>> > diff --git a/libavcodec/videotoolboxenc.c
>>> b/libavcodec/videotoolboxenc.c
>>> > index 4345ca3..859dde9 100644
>>> > --- a/libavcodec/videotoolboxenc.c
>>> > +++ b/libavcodec/videotoolboxenc.c
>>> > @@ -32,6 +32,7 @@
>>> > #include "libavutil/pixdesc.h"
>>> > #include "internal.h"
>>> > #include 
>>> > +#include "h264.h"
>>> >
>>> > #if !CONFIG_VT_BT2020
>>> > # define kCVImageBufferColorPrimaries_ITU_R_2020   CFSTR("ITU_R_2020")
>>> > @@ -55,8 +56,14 @@ typedef enum VTH264Entropy{
>>> >
>>> > static const uint8_t start_code[] = { 0, 0, 0, 1 };
>>> >
>>> > +typedef struct ExtraSEI {
>>> > +  void *data;
>>> > +  size_t size;
>>> > +} ExtraSEI;
>>> > +
>>> > typedef struct BufNode {
>>> > CMSampleBufferRef cm_buffer;
>>> > +ExtraSEI *sei;
>>> > struct BufNode* next;
>>> > int error;
>>> > } BufNode;
>>> > @@ -94,6 +101,7 @@ typedef struct VTEncContext {
>>> > bool flushing;
>>> > bool has_b_frames;
>>> > bool warned_color_range;
>>> > +bool a53_cc;
>>> > } VTEncContext;
>>> >
>>> > static int vtenc_populate_extradata(AVCodecContext   *avctx,
>>> > @@ -136,7 +144,7 @@ static void set_async_error(VTEncContext *vtctx,
>>> int err)
>>> > pthread_mutex_unlock(>lock);
>>> > }
>>> >
>>> > -static int vtenc_q_pop(VTEncContext *vtctx, bool wait,
>>> CMSampleBufferRef *buf)
>>> > +static int vtenc_q_pop(VTEncContext *vtctx, bool wait,
>>> CMSampleBufferRef *buf, ExtraSEI **sei)
>>> > {
>>> > BufNode *info;
>>> >
>>> > @@ -173,6 +181,12 @@ static int vtenc_q_pop(VTEncContext *vtctx, bool
>>> wait, CMSampleBufferRef *buf)
>>> > pthread_mutex_unlock(>lock);
>>> >
>>> > *buf = info->cm_buffer;
>>> > +if (sei && *buf) {
>>> > +*sei = info->sei;
>>> > +} else if (info->sei) {
>>> > +if (info->sei->data) av_free(info->sei->data);
>>> > +av_free(info->sei);
>>> > +}
>>> > av_free(info);
>>> >
>>> > vtctx->frame_ct_out++;
>>> > @@ -180,7 +194,7 @@ static int vtenc_q_pop(VTEncContext *vtctx, bool
>>> wait, CMSampleBufferRef *buf)
>>> > return 0;
>>> > }
>>> >
>>> > -static void vtenc_q_push(VTEncContext *vtctx, CMSampleBufferRef
>>> buffer)
>>> > +static void vtenc_q_push(VTEncContext *vtctx, CMSampleBufferRef
>>> buffer, ExtraSEI *sei)
>>> > {
>>> > BufNode *info = av_malloc(sizeof(BufNode));
>>> > if (!info) {
>>> > @@ -190,6 +204,7 @@ static void vtenc_q_push(VTEncContext *vtctx,
>>> CMSampleBufferRef buffer)
>>> >
>>> > CFRetain(buffer);
>>> > info->cm_buffer = buffer;
>>> > +info->sei = sei;
>>> > info->next = NULL;
>>> >
>>> > pthread_mutex_lock(>lock);
>>> > @@ -420,6 +435,7 @@ static void vtenc_output_callback(
>>> > {
>>> > AVCodecContext *avctx = ctx;
>>> > VTEncContext   *vtctx = avctx->priv_data;
>>> > +ExtraSEI *sei = sourceFrameCtx;
>>> >
>>> > if (vtctx->async_error) {
>>> > if(sample_buffer) CFRelease(sample_buffer);
>>> >

Re: [FFmpeg-devel] [PATCH] lavc/videotoolboxenc: implement a53cc

2016-10-17 Thread Aman Gupta
On Mon, Oct 17, 2016 at 5:51 PM, Richard Kern <ker...@gmail.com> wrote:

>
> On Oct 17, 2016, at 8:47 PM, Aman Gupta <ffm...@tmm1.net> wrote:
>
>
>
> On Mon, Oct 17, 2016 at 6:35 AM, Richard Kern <ker...@gmail.com> wrote:
>
>>
>> On Sep 19, 2016, at 10:30 AM, Aman Gupta <ffm...@tmm1.net> wrote:
>>
>>
>>
>> On Monday, September 19, 2016, Richard Kern <ker...@gmail.com> wrote:
>>
>>>
>>> On Sep 10, 2016, at 10:33 PM, Aman Gupta <ffm...@tmm1.net> wrote:
>>>
>>>
>>>
>>> On Sunday, September 11, 2016, Richard Kern <ker...@gmail.com> wrote:
>>>
>>>>
>>>> > On Sep 8, 2016, at 4:19 AM, Aman Gupta <ffm...@tmm1.net> wrote:
>>>> >
>>>> > From: Aman Gupta <a...@tmm1.net>
>>>> >
>>>> > ---
>>>> > libavcodec/videotoolboxenc.c | 76 ++
>>>> --
>>>> > 1 file changed, 67 insertions(+), 9 deletions(-)
>>>> >
>>>> > diff --git a/libavcodec/videotoolboxenc.c
>>>> b/libavcodec/videotoolboxenc.c
>>>> > index 4345ca3..859dde9 100644
>>>> > --- a/libavcodec/videotoolboxenc.c
>>>> > +++ b/libavcodec/videotoolboxenc.c
>>>> > @@ -32,6 +32,7 @@
>>>> > #include "libavutil/pixdesc.h"
>>>> > #include "internal.h"
>>>> > #include 
>>>> > +#include "h264.h"
>>>> >
>>>> > #if !CONFIG_VT_BT2020
>>>> > # define kCVImageBufferColorPrimaries_ITU_R_2020
>>>>  CFSTR("ITU_R_2020")
>>>> > @@ -55,8 +56,14 @@ typedef enum VTH264Entropy{
>>>> >
>>>> > static const uint8_t start_code[] = { 0, 0, 0, 1 };
>>>> >
>>>> > +typedef struct ExtraSEI {
>>>> > +  void *data;
>>>> > +  size_t size;
>>>> > +} ExtraSEI;
>>>> > +
>>>> > typedef struct BufNode {
>>>> > CMSampleBufferRef cm_buffer;
>>>> > +ExtraSEI *sei;
>>>> > struct BufNode* next;
>>>> > int error;
>>>> > } BufNode;
>>>> > @@ -94,6 +101,7 @@ typedef struct VTEncContext {
>>>> > bool flushing;
>>>> > bool has_b_frames;
>>>> > bool warned_color_range;
>>>> > +bool a53_cc;
>>>> > } VTEncContext;
>>>> >
>>>> > static int vtenc_populate_extradata(AVCodecContext   *avctx,
>>>> > @@ -136,7 +144,7 @@ static void set_async_error(VTEncContext *vtctx,
>>>> int err)
>>>> > pthread_mutex_unlock(>lock);
>>>> > }
>>>> >
>>>> > -static int vtenc_q_pop(VTEncContext *vtctx, bool wait,
>>>> CMSampleBufferRef *buf)
>>>> > +static int vtenc_q_pop(VTEncContext *vtctx, bool wait,
>>>> CMSampleBufferRef *buf, ExtraSEI **sei)
>>>> > {
>>>> > BufNode *info;
>>>> >
>>>> > @@ -173,6 +181,12 @@ static int vtenc_q_pop(VTEncContext *vtctx, bool
>>>> wait, CMSampleBufferRef *buf)
>>>> > pthread_mutex_unlock(>lock);
>>>> >
>>>> > *buf = info->cm_buffer;
>>>> > +if (sei && *buf) {
>>>> > +*sei = info->sei;
>>>> > +} else if (info->sei) {
>>>> > +if (info->sei->data) av_free(info->sei->data);
>>>> > +av_free(info->sei);
>>>> > +}
>>>> > av_free(info);
>>>> >
>>>> > vtctx->frame_ct_out++;
>>>> > @@ -180,7 +194,7 @@ static int vtenc_q_pop(VTEncContext *vtctx, bool
>>>> wait, CMSampleBufferRef *buf)
>>>> > return 0;
>>>> > }
>>>> >
>>>> > -static void vtenc_q_push(VTEncContext *vtctx, CMSampleBufferRef
>>>> buffer)
>>>> > +static void vtenc_q_push(VTEncContext *vtctx, CMSampleBufferRef
>>>> buffer, ExtraSEI *sei)
>>>> > {
>>>> > BufNode *info = av_malloc(sizeof(BufNode));
>>>> > if (!info) {
>>>> > @@ -190,6 +204,7 @@ static void vtenc_q_push(VTEncContext *vtctx,
>>>> CMSampleBufferRef buffer)
>>>> >
>>>> > CFRetain(buffer);
>>>> &g

  1   2   3   4   5   6   >