This repository has been archived by the owner on Feb 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
0057-lavc-vaapi_hevc-add-skip_frame-invalid-to-skip-inval.patch
86 lines (77 loc) · 4.29 KB
/
0057-lavc-vaapi_hevc-add-skip_frame-invalid-to-skip-inval.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
From a1c51a92f6ade9e61c95c9694ad193298cfd967b Mon Sep 17 00:00:00 2001
From: Linjie Fu <[email protected]>
Date: Tue, 14 Jul 2020 14:56:25 +0800
Subject: [PATCH] lavc/vaapi_hevc: add -skip_frame invalid to skip invalid
nalus
Works in single thread mode:
$ ffmpeg -threads 1 -hwaccel vaapi -i input-100frames.h265 -f null -
For multi thread, add '-skip_frame invalid' option to skip the invalid
nalus before an IRAP:
$ ffmpeg -skip_frame invalid -hwaccel vaapi -i input-100frames.h265 -f null -
Signed-off-by: Linjie Fu <[email protected]>
---
libavcodec/avcodec.h | 1 +
libavcodec/hevcdec.c | 6 +++++-
libavcodec/options_table.h | 1 +
libavcodec/pthread_frame.c | 1 +
4 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index c91b2fd169..01cdfdf37f 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -229,6 +229,7 @@ enum AVDiscard{
* keyframes for intra-only or drop just some bidir frames). */
AVDISCARD_NONE =-16, ///< discard nothing
AVDISCARD_DEFAULT = 0, ///< discard useless packets like 0 size packets in avi
+ AVDISCARD_INVALID = 1, ///< discard invalid packets like NALs before IRAP
AVDISCARD_NONREF = 8, ///< discard all non reference
AVDISCARD_BIDIR = 16, ///< discard all bidirectional frames
AVDISCARD_NONINTRA= 24, ///< discard all non intra frames
diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index b77df8d89f..9ec5b419da 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -539,8 +539,11 @@ static int hls_slice_header(HEVCContext *s)
ff_hevc_clear_refs(s);
}
sh->no_output_of_prior_pics_flag = 0;
- if (IS_IRAP(s))
+ if (IS_IRAP(s)) {
sh->no_output_of_prior_pics_flag = get_bits1(gb);
+ if (s->avctx->skip_frame == AVDISCARD_INVALID)
+ s->avctx->skip_frame = AVDISCARD_DEFAULT;
+ }
sh->pps_id = get_ue_golomb_long(gb);
if (sh->pps_id >= HEVC_MAX_PPS_COUNT || !s->ps.pps_list[sh->pps_id]) {
@@ -3005,6 +3008,7 @@ static int decode_nal_unit(HEVCContext *s, const H2645NAL *nal)
if (
(s->avctx->skip_frame >= AVDISCARD_BIDIR && s->sh.slice_type == HEVC_SLICE_B) ||
(s->avctx->skip_frame >= AVDISCARD_NONINTRA && s->sh.slice_type != HEVC_SLICE_I) ||
+ (s->avctx->skip_frame >= AVDISCARD_INVALID && !IS_IRAP(s)) ||
(s->avctx->skip_frame >= AVDISCARD_NONKEY && !IS_IRAP(s))) {
break;
}
diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h
index 1d0db1b5a4..c5673a9085 100644
--- a/libavcodec/options_table.h
+++ b/libavcodec/options_table.h
@@ -306,6 +306,7 @@ static const AVOption avcodec_options[] = {
{"skip_frame" , "skip decoding for the selected frames", OFFSET(skip_frame), AV_OPT_TYPE_INT, {.i64 = AVDISCARD_DEFAULT }, INT_MIN, INT_MAX, V|D, "avdiscard"},
{"none" , "discard no frame", 0, AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_NONE }, INT_MIN, INT_MAX, V|D, "avdiscard"},
{"default" , "discard useless frames", 0, AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_DEFAULT }, INT_MIN, INT_MAX, V|D, "avdiscard"},
+{"invalid" , "discard NALUs before IRAP", 0, AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_INVALID }, INT_MIN, INT_MAX, V|D, "avdiscard"},
{"noref" , "discard all non-reference frames", 0, AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_NONREF }, INT_MIN, INT_MAX, V|D, "avdiscard"},
{"bidir" , "discard all bidirectional frames", 0, AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_BIDIR }, INT_MIN, INT_MAX, V|D, "avdiscard"},
{"nokey" , "discard all frames except keyframes", 0, AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_NONKEY }, INT_MIN, INT_MAX, V|D, "avdiscard"},
diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c
index 3255aa9337..302e6149ac 100644
--- a/libavcodec/pthread_frame.c
+++ b/libavcodec/pthread_frame.c
@@ -259,6 +259,7 @@ static int update_context_from_thread(AVCodecContext *dst, AVCodecContext *src,
dst->has_b_frames = src->has_b_frames;
dst->idct_algo = src->idct_algo;
+ dst->skip_frame = src->skip_frame;
dst->bits_per_coded_sample = src->bits_per_coded_sample;
dst->sample_aspect_ratio = src->sample_aspect_ratio;
--
2.25.1