summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Stebbins <[email protected]>2019-05-02 12:56:02 -0600
committerJohn Stebbins <[email protected]>2019-05-02 12:58:39 -0600
commit9be711f822e4458d4d4edda1d00a6b752fc4e7b8 (patch)
treefe708e0b8ec432d9c2aa81e80893c7ecf2beebd2
parent63f8bd872eda9457c0fe63af98cfd6ba334c6658 (diff)
libhb: pass AV_PKT_FLAG_DISCARD through to decoder
Edit list cuts are not always on keyframe boundaries and therefore sometimes require dropping frames after decoding them. AV_PKT_FLAG_DISCARD tells us when to do this. Fixes https://github.com/HandBrake/HandBrake/issues/1900
-rw-r--r--libhb/decavcodec.c7
-rw-r--r--libhb/internal.h1
-rw-r--r--libhb/stream.c6
3 files changed, 13 insertions, 1 deletions
diff --git a/libhb/decavcodec.c b/libhb/decavcodec.c
index 6fcdefa9d..610f9ecfa 100644
--- a/libhb/decavcodec.c
+++ b/libhb/decavcodec.c
@@ -82,6 +82,7 @@ typedef struct
int frametype;
int scr_sequence;
int new_chap;
+ int discard;
} packet_info_t;
typedef struct reordered_data_s reordered_data_t;
@@ -489,6 +490,7 @@ static int decavcodecaWork( hb_work_object_t * w, hb_buffer_t ** buf_in,
pv->packet_info.scr_sequence = in->s.scr_sequence;
pv->packet_info.new_chap = in->s.new_chap;
pv->packet_info.frametype = in->s.frametype;
+ pv->packet_info.discard = !!(in->s.flags & HB_FLAG_DISCARD);
}
for (pos = 0; pos < in->size; pos += len)
{
@@ -522,6 +524,7 @@ static int decavcodecaWork( hb_work_object_t * w, hb_buffer_t ** buf_in,
// decodeAudio that is now finished. The next packet is associated
// with the input buffer, so set it's chapter and scr info.
pv->packet_info.scr_sequence = in->s.scr_sequence;
+ pv->packet_info.discard = !!(in->s.flags & HB_FLAG_DISCARD);
pv->unfinished = 0;
}
if (len > 0 && pout_len <= 0)
@@ -1319,6 +1322,7 @@ static int decodeFrame( hb_work_private_t * pv, packet_info_t * packet_info )
{
avp.flags |= AV_PKT_FLAG_KEY;
}
+ avp.flags |= packet_info->discard * AV_PKT_FLAG_DISCARD;
}
else
{
@@ -1748,6 +1752,7 @@ static int decavcodecvWork( hb_work_object_t * w, hb_buffer_t ** buf_in,
pv->packet_info.scr_sequence = in->s.scr_sequence;
pv->packet_info.new_chap = in->s.new_chap;
pv->packet_info.frametype = in->s.frametype;
+ pv->packet_info.discard = !!(in->s.flags & HB_FLAG_DISCARD);
}
for (pos = 0; pos < in->size; pos += len)
{
@@ -1802,6 +1807,7 @@ static int decavcodecvWork( hb_work_object_t * w, hb_buffer_t ** buf_in,
pv->packet_info.scr_sequence = in->s.scr_sequence;
pv->packet_info.new_chap = in->s.new_chap;
pv->packet_info.frametype = in->s.frametype;
+ pv->packet_info.discard = !!(in->s.flags & HB_FLAG_DISCARD);
pv->unfinished = 0;
}
if (len > 0 && pout_len <= 0)
@@ -2168,6 +2174,7 @@ static void decodeAudio(hb_work_private_t *pv, packet_info_t * packet_info)
avp.size = packet_info->size;
avp.pts = packet_info->pts;
avp.dts = AV_NOPTS_VALUE;
+ avp.flags |= packet_info->discard * AV_PKT_FLAG_DISCARD;
}
else
{
diff --git a/libhb/internal.h b/libhb/internal.h
index 1e9138a3f..49e081169 100644
--- a/libhb/internal.h
+++ b/libhb/internal.h
@@ -102,6 +102,7 @@ struct hb_buffer_settings_s
#define HB_BUF_FLAG_EOS 0x0800
#define HB_FLAG_FRAMETYPE_KEY 0x1000
#define HB_FLAG_FRAMETYPE_REF 0x2000
+#define HB_FLAG_DISCARD 0x4000
uint16_t flags;
#define HB_COMB_NONE 0
diff --git a/libhb/stream.c b/libhb/stream.c
index 0c86f2a8b..ca8739190 100644
--- a/libhb/stream.c
+++ b/libhb/stream.c
@@ -5946,6 +5946,10 @@ hb_buffer_t * hb_ffmpeg_read( hb_stream_t *stream )
memcpy( buf->palette->data, palette, size );
}
}
+ if (stream->ffmpeg_pkt.flags & AV_PKT_FLAG_DISCARD)
+ {
+ buf->s.flags |= HB_FLAG_DISCARD;
+ }
buf->s.id = stream->ffmpeg_pkt.stream_index;
// compute a conversion factor to go from the ffmpeg
@@ -5975,7 +5979,7 @@ hb_buffer_t * hb_ffmpeg_read( hb_stream_t *stream )
*/
if (stream->ffmpeg_pkt.flags & AV_PKT_FLAG_KEY)
{
- buf->s.flags = HB_FLAG_FRAMETYPE_KEY;
+ buf->s.flags |= HB_FLAG_FRAMETYPE_KEY;
buf->s.frametype = HB_FRAME_I;
}
break;