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
2a546fb7
Commit
2a546fb7
authored
Sep 30, 2019
by
Paul B Mahol
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avfilter/setpts: switch to activate
Also properly handle EOF timestamps. Fixes #6833.
parent
61dd2e07
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
19 deletions
+61
-19
setpts.c
libavfilter/setpts.c
+61
-19
No files found.
libavfilter/setpts.c
View file @
2a546fb7
...
...
@@ -33,6 +33,7 @@
#include "libavutil/time.h"
#include "audio.h"
#include "avfilter.h"
#include "filters.h"
#include "internal.h"
#include "video.h"
...
...
@@ -154,6 +155,28 @@ static inline char *double2int64str(char *buf, double v)
return
buf
;
}
static
double
eval_pts
(
SetPTSContext
*
setpts
,
AVFilterLink
*
inlink
,
AVFrame
*
frame
,
int64_t
pts
)
{
if
(
isnan
(
setpts
->
var_values
[
VAR_STARTPTS
]))
{
setpts
->
var_values
[
VAR_STARTPTS
]
=
TS2D
(
pts
);
setpts
->
var_values
[
VAR_STARTT
]
=
TS2T
(
pts
,
inlink
->
time_base
);
}
setpts
->
var_values
[
VAR_PTS
]
=
TS2D
(
pts
);
setpts
->
var_values
[
VAR_T
]
=
TS2T
(
pts
,
inlink
->
time_base
);
setpts
->
var_values
[
VAR_POS
]
=
!
frame
||
frame
->
pkt_pos
==
-
1
?
NAN
:
frame
->
pkt_pos
;
setpts
->
var_values
[
VAR_RTCTIME
]
=
av_gettime
();
if
(
frame
)
{
if
(
inlink
->
type
==
AVMEDIA_TYPE_VIDEO
)
{
setpts
->
var_values
[
VAR_INTERLACED
]
=
frame
->
interlaced_frame
;
}
else
if
(
inlink
->
type
==
AVMEDIA_TYPE_AUDIO
)
{
setpts
->
var_values
[
VAR_S
]
=
frame
->
nb_samples
;
setpts
->
var_values
[
VAR_NB_SAMPLES
]
=
frame
->
nb_samples
;
}
}
return
av_expr_eval
(
setpts
->
expr
,
setpts
->
var_values
,
NULL
);
}
#define d2istr(v) double2int64str((char[BUF_SIZE]){0}, v)
static
int
filter_frame
(
AVFilterLink
*
inlink
,
AVFrame
*
frame
)
...
...
@@ -162,23 +185,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
int64_t
in_pts
=
frame
->
pts
;
double
d
;
if
(
isnan
(
setpts
->
var_values
[
VAR_STARTPTS
]))
{
setpts
->
var_values
[
VAR_STARTPTS
]
=
TS2D
(
frame
->
pts
);
setpts
->
var_values
[
VAR_STARTT
]
=
TS2T
(
frame
->
pts
,
inlink
->
time_base
);
}
setpts
->
var_values
[
VAR_PTS
]
=
TS2D
(
frame
->
pts
);
setpts
->
var_values
[
VAR_T
]
=
TS2T
(
frame
->
pts
,
inlink
->
time_base
);
setpts
->
var_values
[
VAR_POS
]
=
frame
->
pkt_pos
==
-
1
?
NAN
:
frame
->
pkt_pos
;
setpts
->
var_values
[
VAR_RTCTIME
]
=
av_gettime
();
if
(
inlink
->
type
==
AVMEDIA_TYPE_VIDEO
)
{
setpts
->
var_values
[
VAR_INTERLACED
]
=
frame
->
interlaced_frame
;
}
else
if
(
inlink
->
type
==
AVMEDIA_TYPE_AUDIO
)
{
setpts
->
var_values
[
VAR_S
]
=
frame
->
nb_samples
;
setpts
->
var_values
[
VAR_NB_SAMPLES
]
=
frame
->
nb_samples
;
}
d
=
av_expr_eval
(
setpts
->
expr
,
setpts
->
var_values
,
NULL
);
d
=
eval_pts
(
setpts
,
inlink
,
frame
,
frame
->
pts
);
frame
->
pts
=
D2TS
(
d
);
av_log
(
inlink
->
dst
,
AV_LOG_TRACE
,
...
...
@@ -216,6 +223,41 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
return
ff_filter_frame
(
inlink
->
dst
->
outputs
[
0
],
frame
);
}
static
int
activate
(
AVFilterContext
*
ctx
)
{
SetPTSContext
*
setpts
=
ctx
->
priv
;
AVFilterLink
*
inlink
=
ctx
->
inputs
[
0
];
AVFilterLink
*
outlink
=
ctx
->
outputs
[
0
];
AVFrame
*
in
;
int
status
;
int64_t
pts
;
int
ret
;
FF_FILTER_FORWARD_STATUS_BACK
(
outlink
,
inlink
);
ret
=
ff_inlink_consume_frame
(
inlink
,
&
in
);
if
(
ret
<
0
)
return
ret
;
if
(
ret
>
0
)
return
filter_frame
(
inlink
,
in
);
if
(
ff_inlink_acknowledge_status
(
inlink
,
&
status
,
&
pts
))
{
double
d
=
eval_pts
(
setpts
,
inlink
,
NULL
,
pts
);
av_log
(
ctx
,
AV_LOG_TRACE
,
"N:EOF PTS:%s T:%f POS:%s -> PTS:%s T:%f
\n
"
,
d2istr
(
setpts
->
var_values
[
VAR_PTS
]),
setpts
->
var_values
[
VAR_T
],
d2istr
(
setpts
->
var_values
[
VAR_POS
]),
d2istr
(
d
),
TS2T
(
d
,
inlink
->
time_base
));
ff_outlink_set_status
(
outlink
,
status
,
D2TS
(
d
));
return
0
;
}
FF_FILTER_FORWARD_WANTED
(
outlink
,
inlink
);
return
FFERROR_NOT_READY
;
}
static
av_cold
void
uninit
(
AVFilterContext
*
ctx
)
{
SetPTSContext
*
setpts
=
ctx
->
priv
;
...
...
@@ -239,7 +281,6 @@ static const AVFilterPad avfilter_vf_setpts_inputs[] = {
.
name
=
"default"
,
.
type
=
AVMEDIA_TYPE_VIDEO
,
.
config_props
=
config_input
,
.
filter_frame
=
filter_frame
,
},
{
NULL
}
};
...
...
@@ -256,6 +297,7 @@ AVFilter ff_vf_setpts = {
.
name
=
"setpts"
,
.
description
=
NULL_IF_CONFIG_SMALL
(
"Set PTS for the output video frame."
),
.
init
=
init
,
.
activate
=
activate
,
.
uninit
=
uninit
,
.
priv_size
=
sizeof
(
SetPTSContext
),
...
...
@@ -276,7 +318,6 @@ static const AVFilterPad asetpts_inputs[] = {
.
name
=
"default"
,
.
type
=
AVMEDIA_TYPE_AUDIO
,
.
config_props
=
config_input
,
.
filter_frame
=
filter_frame
,
},
{
NULL
}
};
...
...
@@ -293,6 +334,7 @@ AVFilter ff_af_asetpts = {
.
name
=
"asetpts"
,
.
description
=
NULL_IF_CONFIG_SMALL
(
"Set PTS for the output audio frame."
),
.
init
=
init
,
.
activate
=
activate
,
.
uninit
=
uninit
,
.
priv_size
=
sizeof
(
SetPTSContext
),
.
priv_class
=
&
asetpts_class
,
...
...
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