Re: [libav-devel] mpegtsenc: Random Access indicator take 2

2011-07-13 Thread Jindřich Makovička
On Mon, Jul 11, 2011 at 16:40, Tomas Härdin tomas.har...@codemill.se wrote:
 Looks OK to me. Have you tried playing the encoded files on some hardware
 like an STB though?

Yes, the main motivation for this fix was a STB with hard disk recording.

-- 
Jindrich Makovicka
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] mpegtsenc: Random Access indicator take 2

2011-07-11 Thread Tomas Härdin

Jindřich Makovička skrev 2011-06-29 15:04:

On Wed, Jun 29, 2011 at 12:06, Diego Biurrundi...@biurrun.de  wrote:

On Wed, Jun 29, 2011 at 07:35:30AM +, Gil Pedersen wrote:

It most likely breaks fate.


It does indeed - Jindrich, this needs to be addressed...

biurrun@passion:~/src/priv/libav $ make fate-lavf-ts
TESTacodec-aref
TESTvsynth1-vref
TESTvsynth2-vref
TESTlavf-ts
--- ./tests/ref/lavf/ts 2011-06-21 22:15:41.490730387 +0200
+++ tests/data/fate/lavf-ts 2011-06-29 12:05:41.926902303 +0200
@@ -1,3 +1,3 @@
-d260ac0534ff2e26b44b5192fd4fdc21 *./tests/data/lavf/lavf.ts
+9708011dd80212a0041a96da878122c2 *./tests/data/lavf/lavf.ts
  406644 ./tests/data/lavf/lavf.ts
  ./tests/data/lavf/lavf.ts CRC=0x133216c1
make: *** [fate-lavf-ts] Error 1


Patch including the FATE change attached.


Looks OK to me. Have you tried playing the encoded files on some 
hardware like an STB though?


/Tomas
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] mpegtsenc: Random Access indicator take 2

2011-06-29 Thread Gil Pedersen
On 29/06/2011, at 01.54, Diego Biurrun wrote:

 On Tue, Jun 28, 2011 at 10:21:07AM +0200, Jindřich Makovička wrote:
 On Thu, Jun 23, 2011 at 09:33, Tomas Härdin tomas.har...@codemill.se wrote:
 Jindřich Makovička skrev 2011-06-21 18:52:
 
 I am attaching another, hopefully cleaner, version of the Random
 Access indicator patch for mpeg-ts muxer.
 
 Random Access indicator can be used to mark keyframes, and is required
 by some DVB recorders to be able to index and replay the recorded
 stream.
 
 From 7c6a9d0618e045af2026218aff92b400e7b8ee0f Mon Sep 17 00:00:00 2001
 From: Jindrich Makovicka jindrich.makovi...@nangu.tv
 Date: Tue, 21 Jun 2011 18:50:58 +0200
 Subject: [PATCH] set Random Access indicator on keyframe start packets
 
 ---
  libavformat/mpegtsenc.c |   67
 +++---
  1 files changed, 56 insertions(+), 11 deletions(-)
 
 Looks OK AFAICT - I don't have the spec on hand to double-check the details.
 
 ping?
 
 Mans, can you confirm this is good to push?

It most likely breaks fate.

/Gil
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] mpegtsenc: Random Access indicator take 2

2011-06-29 Thread Diego Biurrun
On Wed, Jun 29, 2011 at 07:35:30AM +, Gil Pedersen wrote:
 On 29/06/2011, at 01.54, Diego Biurrun wrote:
 
  On Tue, Jun 28, 2011 at 10:21:07AM +0200, Jindřich Makovička wrote:
  On Thu, Jun 23, 2011 at 09:33, Tomas Härdin tomas.har...@codemill.se 
  wrote:
  Jindřich Makovička skrev 2011-06-21 18:52:
  
  I am attaching another, hopefully cleaner, version of the Random
  Access indicator patch for mpeg-ts muxer.
  
  Random Access indicator can be used to mark keyframes, and is required
  by some DVB recorders to be able to index and replay the recorded
  stream.
  
  From 7c6a9d0618e045af2026218aff92b400e7b8ee0f Mon Sep 17 00:00:00 2001
  From: Jindrich Makovicka jindrich.makovi...@nangu.tv
  Date: Tue, 21 Jun 2011 18:50:58 +0200
  Subject: [PATCH] set Random Access indicator on keyframe start packets
  
  ---
   libavformat/mpegtsenc.c |   67
  +++---
   1 files changed, 56 insertions(+), 11 deletions(-)
  
  Looks OK AFAICT - I don't have the spec on hand to double-check the 
  details.
  
  ping?
  
  Mans, can you confirm this is good to push?
 
 It most likely breaks fate.

It does indeed - Jindrich, this needs to be addressed...

biurrun@passion:~/src/priv/libav $ make fate-lavf-ts
TESTacodec-aref
TESTvsynth1-vref
TESTvsynth2-vref
TESTlavf-ts
--- ./tests/ref/lavf/ts 2011-06-21 22:15:41.490730387 +0200
+++ tests/data/fate/lavf-ts 2011-06-29 12:05:41.926902303 +0200
@@ -1,3 +1,3 @@
-d260ac0534ff2e26b44b5192fd4fdc21 *./tests/data/lavf/lavf.ts
+9708011dd80212a0041a96da878122c2 *./tests/data/lavf/lavf.ts
 406644 ./tests/data/lavf/lavf.ts
 ./tests/data/lavf/lavf.ts CRC=0x133216c1
make: *** [fate-lavf-ts] Error 1

Diego
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] mpegtsenc: Random Access indicator take 2

2011-06-29 Thread Jindřich Makovička
On Wed, Jun 29, 2011 at 12:06, Diego Biurrun di...@biurrun.de wrote:
 On Wed, Jun 29, 2011 at 07:35:30AM +, Gil Pedersen wrote:
 It most likely breaks fate.

 It does indeed - Jindrich, this needs to be addressed...

 biurrun@passion:~/src/priv/libav $ make fate-lavf-ts
 TEST    acodec-aref
 TEST    vsynth1-vref
 TEST    vsynth2-vref
 TEST    lavf-ts
 --- ./tests/ref/lavf/ts 2011-06-21 22:15:41.490730387 +0200
 +++ tests/data/fate/lavf-ts     2011-06-29 12:05:41.926902303 +0200
 @@ -1,3 +1,3 @@
 -d260ac0534ff2e26b44b5192fd4fdc21 *./tests/data/lavf/lavf.ts
 +9708011dd80212a0041a96da878122c2 *./tests/data/lavf/lavf.ts
  406644 ./tests/data/lavf/lavf.ts
  ./tests/data/lavf/lavf.ts CRC=0x133216c1
 make: *** [fate-lavf-ts] Error 1

Patch including the FATE change attached.

-- 
Jindrich Makovicka
From 8be6d6b7c1a50ae5cb62b0bbae6fb54254969dc7 Mon Sep 17 00:00:00 2001
From: Jindrich Makovicka jindrich.makovi...@nangu.tv
Date: Wed, 29 Jun 2011 15:01:39 +0200
Subject: [PATCH] set Random Access indicator on keyframe start packets

Signed-off-by: Jindrich Makovicka jindrich.makovi...@nangu.tv
---
 libavformat/mpegtsenc.c |   67 +++---
 tests/ref/lavf/ts   |2 +-
 2 files changed, 57 insertions(+), 12 deletions(-)

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 26d2cb2..e75bce0 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -203,6 +203,7 @@ typedef struct MpegTSWriteStream {
 int first_pts_check; /// first pts check needed
 int64_t payload_pts;
 int64_t payload_dts;
+int payload_flags;
 uint8_t payload[DEFAULT_PES_PAYLOAD_SIZE];
 ADTSContext *adts;
 } MpegTSWriteStream;
@@ -620,7 +621,7 @@ static int64_t get_pcr(const MpegTSWrite *ts, AVIOContext *pb)
ts-first_pcr;
 }
 
-static uint8_t* write_pcr_bits(uint8_t *buf, int64_t pcr)
+static int write_pcr_bits(uint8_t *buf, int64_t pcr)
 {
 int64_t pcr_low = pcr % 300, pcr_high = pcr / 300;
 
@@ -631,7 +632,7 @@ static uint8_t* write_pcr_bits(uint8_t *buf, int64_t pcr)
 *buf++ = pcr_high  7 | pcr_low  8 | 0x7e;
 *buf++ = pcr_low;
 
-return buf;
+return 6;
 }
 
 /* Write a single null transport stream packet */
@@ -667,7 +668,7 @@ static void mpegts_insert_pcr_only(AVFormatContext *s, AVStream *st)
 *q++ = 0x10;   /* Adaptation flags: PCR present */
 
 /* PCR coded into 6 bytes */
-q = write_pcr_bits(q, get_pcr(ts, s-pb));
+q += write_pcr_bits(q, get_pcr(ts, s-pb));
 
 /* stuffing bytes */
 memset(q, 0xFF, TS_PACKET_SIZE - (q - buf));
@@ -688,6 +689,39 @@ static void write_pts(uint8_t *q, int fourbits, int64_t pts)
 *q++ = val;
 }
 
+/* Set an adaptation field flag in an MPEG-TS packet*/
+static void set_af_flag(uint8_t *pkt, int flag)
+{
+// expect at least one flag to set
+assert(flag);
+
+if ((pkt[3]  0x20) == 0) {
+// no AF yet, set adaptation field flag
+pkt[3] |= 0x20;
+// 1 byte length, no flags
+pkt[4] = 1;
+pkt[5] = 0;
+}
+pkt[5] |= flag;
+}
+
+/* Extend the adaptation field by size bytes */
+static void extend_af(uint8_t *pkt, int size)
+{
+// expect already existing adaptation field
+assert(pkt[3]  0x20);
+pkt[4] += size;
+}
+
+/* Get a pointer to MPEG-TS payload (right after TS packet header) */
+static uint8_t *get_ts_payload_start(uint8_t *pkt)
+{
+if (pkt[3]  0x20)
+return pkt + 5 + pkt[4];
+else
+return pkt + 4;
+}
+
 /* Add a pes header to the front of payload, and segment into an integer number of
  * ts packets. The final ts packet is padded using an over-sized adaptation header
  * to exactly fill the last ts packet.
@@ -695,7 +729,7 @@ static void write_pts(uint8_t *q, int fourbits, int64_t pts)
  */
 static void mpegts_write_pes(AVFormatContext *s, AVStream *st,
  const uint8_t *payload, int payload_size,
- int64_t pts, int64_t dts)
+ int64_t pts, int64_t dts, int key)
 {
 MpegTSWriteStream *ts_st = st-priv_data;
 MpegTSWrite *ts = s-priv_data;
@@ -740,8 +774,17 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st,
 *q++ = val;
 *q++ = ts_st-pid;
 ts_st-cc = (ts_st-cc + 1)  0xf;
-*q++ = 0x10 | ts_st-cc | (write_pcr ? 0x20 : 0);
+*q++ = 0x10 | ts_st-cc; // payload indicator + CC
+if (key  is_start  pts != AV_NOPTS_VALUE) {
+// set Random Access for key frames
+if (ts_st-pid == ts_st-service-pcr_pid)
+write_pcr = 1;
+set_af_flag(buf, 0x40);
+q = get_ts_payload_start(buf);
+}
 if (write_pcr) {
+set_af_flag(buf, 0x10);
+q = get_ts_payload_start(buf);
 // add 11, pcr references the last byte of program clock reference base
 if (ts-mux_rate  1)
 pcr = get_pcr(ts, s-pb);
@@ -749,9 

Re: [libav-devel] mpegtsenc: Random Access indicator take 2

2011-06-28 Thread Diego Biurrun
On Tue, Jun 28, 2011 at 10:21:07AM +0200, Jindřich Makovička wrote:
 On Thu, Jun 23, 2011 at 09:33, Tomas Härdin tomas.har...@codemill.se wrote:
  Jindřich Makovička skrev 2011-06-21 18:52:
 
  I am attaching another, hopefully cleaner, version of the Random
  Access indicator patch for mpeg-ts muxer.
 
  Random Access indicator can be used to mark keyframes, and is required
  by some DVB recorders to be able to index and replay the recorded
  stream.
 
  From 7c6a9d0618e045af2026218aff92b400e7b8ee0f Mon Sep 17 00:00:00 2001
  From: Jindrich Makovicka jindrich.makovi...@nangu.tv
  Date: Tue, 21 Jun 2011 18:50:58 +0200
  Subject: [PATCH] set Random Access indicator on keyframe start packets
 
  ---
   libavformat/mpegtsenc.c |   67
  +++---
   1 files changed, 56 insertions(+), 11 deletions(-)
 
  Looks OK AFAICT - I don't have the spec on hand to double-check the details.
 
 ping?

Mans, can you confirm this is good to push?

Diego
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] mpegtsenc: Random Access indicator take 2

2011-06-23 Thread Tomas Härdin

Jindřich Makovička skrev 2011-06-21 18:52:

Hi,

I am attaching another, hopefully cleaner, version of the Random
Access indicator patch for mpeg-ts muxer.

Random Access indicator can be used to mark keyframes, and is required
by some DVB recorders to be able to index and replay the recorded
stream.

From 7c6a9d0618e045af2026218aff92b400e7b8ee0f Mon Sep 17 00:00:00 2001
From: Jindrich Makovicka jindrich.makovi...@nangu.tv
Date: Tue, 21 Jun 2011 18:50:58 +0200
Subject: [PATCH] set Random Access indicator on keyframe start packets

---
 libavformat/mpegtsenc.c |   67 +++---
 1 files changed, 56 insertions(+), 11 deletions(-)


Looks OK AFAICT - I don't have the spec on hand to double-check the details.

/Tomas
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel