Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
F
ffmpeg.wasm-core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
ffmpeg.wasm-core
Commits
e5babccf
Commit
e5babccf
authored
May 31, 2016
by
Timo Rothenpieler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avcodec/nvenc: Refactor timestamp generation logic
Directly adapted from libav
parent
69c25c0a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
15 deletions
+37
-15
nvenc.c
libavcodec/nvenc.c
+33
-14
nvenc.h
libavcodec/nvenc.h
+4
-1
No files found.
libavcodec/nvenc.c
View file @
e5babccf
...
...
@@ -828,8 +828,6 @@ static av_cold int nvenc_setup_encoder(AVCodecContext *avctx)
int
res
=
0
;
int
dw
,
dh
;
ctx
->
last_dts
=
AV_NOPTS_VALUE
;
ctx
->
encode_config
.
version
=
NV_ENC_CONFIG_VER
;
ctx
->
init_encode_params
.
version
=
NV_ENC_INITIALIZE_PARAMS_VER
;
...
...
@@ -897,9 +895,8 @@ static av_cold int nvenc_setup_encoder(AVCodecContext *avctx)
ctx
->
encode_config
.
gopLength
=
1
;
}
/* when there're b frames, set dts offset */
if
(
ctx
->
encode_config
.
frameIntervalP
>=
2
)
ctx
->
last_dts
=
-
2
;
ctx
->
initial_pts
[
0
]
=
AV_NOPTS_VALUE
;
ctx
->
initial_pts
[
1
]
=
AV_NOPTS_VALUE
;
nvenc_setup_rate_control
(
avctx
);
...
...
@@ -1419,19 +1416,30 @@ static int nvenc_set_timestamp(AVCodecContext *avctx,
pkt
->
pts
=
params
->
outputTimeStamp
;
pkt
->
duration
=
params
->
outputDuration
;
pkt
->
dts
=
timestamp_queue_dequeue
(
ctx
->
timestamp_list
);
/* when there're b frame(s), set dts offset */
if
(
ctx
->
encode_config
.
frameIntervalP
>=
2
)
pkt
->
dts
-=
1
;
/* generate the first dts by linearly extrapolating the
* first two pts values to the past */
if
(
avctx
->
max_b_frames
>
0
&&
!
ctx
->
first_packet_output
&&
ctx
->
initial_pts
[
1
]
!=
AV_NOPTS_VALUE
)
{
int64_t
ts0
=
ctx
->
initial_pts
[
0
],
ts1
=
ctx
->
initial_pts
[
1
];
int64_t
delta
;
if
((
ts0
<
0
&&
ts1
>
INT64_MAX
+
ts0
)
||
(
ts0
>
0
&&
ts1
<
INT64_MIN
+
ts0
))
return
AVERROR
(
ERANGE
);
delta
=
ts1
-
ts0
;
if
(
pkt
->
dts
>
pkt
->
pts
)
pkt
->
dts
=
pkt
->
pts
;
if
((
delta
<
0
&&
ts0
>
INT64_MAX
+
delta
)
||
(
delta
>
0
&&
ts0
<
INT64_MIN
+
delta
))
return
AVERROR
(
ERANGE
);
pkt
->
dts
=
ts0
-
delta
;
ctx
->
first_packet_output
=
1
;
return
0
;
}
if
(
ctx
->
last_dts
!=
AV_NOPTS_VALUE
&&
pkt
->
dts
<=
ctx
->
last_dts
)
pkt
->
dts
=
ctx
->
last_dts
+
1
;
pkt
->
dts
=
timestamp_queue_dequeue
(
ctx
->
timestamp_list
);
ctx
->
last_dts
=
pkt
->
dts
;
return
0
;
}
...
...
@@ -1551,6 +1559,12 @@ static int output_ready(AVCodecContext *avctx, int flush)
NvencContext
*
ctx
=
avctx
->
priv_data
;
int
nb_ready
,
nb_pending
;
/* when B-frames are enabled, we wait for two initial timestamps to
* calculate the first dts */
if
(
!
flush
&&
avctx
->
max_b_frames
>
0
&&
(
ctx
->
initial_pts
[
0
]
==
AV_NOPTS_VALUE
||
ctx
->
initial_pts
[
1
]
==
AV_NOPTS_VALUE
))
return
0
;
nb_ready
=
av_fifo_size
(
ctx
->
output_surface_ready_queue
)
/
sizeof
(
NvencSurface
*
);
nb_pending
=
av_fifo_size
(
ctx
->
output_surface_queue
)
/
sizeof
(
NvencSurface
*
);
if
(
flush
)
...
...
@@ -1617,6 +1631,11 @@ int ff_nvenc_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
if
(
frame
)
{
av_fifo_generic_write
(
ctx
->
output_surface_queue
,
&
inSurf
,
sizeof
(
inSurf
),
NULL
);
timestamp_queue_enqueue
(
ctx
->
timestamp_list
,
frame
->
pts
);
if
(
ctx
->
initial_pts
[
0
]
==
AV_NOPTS_VALUE
)
ctx
->
initial_pts
[
0
]
=
frame
->
pts
;
else
if
(
ctx
->
initial_pts
[
1
]
==
AV_NOPTS_VALUE
)
ctx
->
initial_pts
[
1
]
=
frame
->
pts
;
}
/* all the pending buffers are now ready for output */
...
...
libavcodec/nvenc.h
View file @
e5babccf
...
...
@@ -157,7 +157,10 @@ typedef struct NvencContext
* AVCodecContext.pix_fmt when using hwaccel frames on input */
enum
AVPixelFormat
data_pix_fmt
;
int64_t
last_dts
;
/* timestamps of the first two frames, for computing the first dts
* when B-frames are present */
int64_t
initial_pts
[
2
];
int
first_packet_output
;
void
*
nvencoder
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment