Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FFmpeg
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
libremedia
Tethys
FFmpeg
Commits
54ca198e
Commit
54ca198e
authored
6 years ago
by
Paul B Mahol
Browse files
Options
Downloads
Patches
Plain Diff
avfilter/vf_threshold: add slice threading
parent
4b003322
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
libavfilter/vf_threshold.c
+55
-19
55 additions, 19 deletions
libavfilter/vf_threshold.c
with
55 additions
and
19 deletions
libavfilter/vf_threshold.c
+
55
−
19
View file @
54ca198e
...
@@ -68,12 +68,59 @@ static int query_formats(AVFilterContext *ctx)
...
@@ -68,12 +68,59 @@ static int query_formats(AVFilterContext *ctx)
return
ff_set_common_formats
(
ctx
,
ff_make_format_list
(
pix_fmts
));
return
ff_set_common_formats
(
ctx
,
ff_make_format_list
(
pix_fmts
));
}
}
typedef
struct
ThreadData
{
AVFrame
*
in
;
AVFrame
*
threshold
;
AVFrame
*
min
;
AVFrame
*
max
;
AVFrame
*
out
;
}
ThreadData
;
static
int
filter_slice
(
AVFilterContext
*
ctx
,
void
*
arg
,
int
jobnr
,
int
nb_jobs
)
{
ThresholdContext
*
s
=
ctx
->
priv
;
ThreadData
*
td
=
arg
;
AVFrame
*
min
=
td
->
min
;
AVFrame
*
max
=
td
->
max
;
AVFrame
*
threshold
=
td
->
threshold
;
AVFrame
*
in
=
td
->
in
;
AVFrame
*
out
=
td
->
out
;
for
(
int
p
=
0
;
p
<
s
->
nb_planes
;
p
++
)
{
const
int
h
=
s
->
height
[
p
];
const
int
slice_start
=
(
h
*
jobnr
)
/
nb_jobs
;
const
int
slice_end
=
(
h
*
(
jobnr
+
1
))
/
nb_jobs
;
if
(
!
(
s
->
planes
&
(
1
<<
p
)))
{
av_image_copy_plane
(
out
->
data
[
p
]
+
slice_start
*
out
->
linesize
[
p
],
out
->
linesize
[
p
],
in
->
data
[
p
]
+
slice_start
*
in
->
linesize
[
p
],
in
->
linesize
[
p
],
s
->
width
[
p
]
*
s
->
bpc
,
slice_end
-
slice_start
);
continue
;
}
s
->
threshold
(
in
->
data
[
p
]
+
slice_start
*
in
->
linesize
[
p
],
threshold
->
data
[
p
]
+
slice_start
*
threshold
->
linesize
[
p
],
min
->
data
[
p
]
+
slice_start
*
min
->
linesize
[
p
],
max
->
data
[
p
]
+
slice_start
*
max
->
linesize
[
p
],
out
->
data
[
p
]
+
slice_start
*
out
->
linesize
[
p
],
in
->
linesize
[
p
],
threshold
->
linesize
[
p
],
min
->
linesize
[
p
],
max
->
linesize
[
p
],
out
->
linesize
[
p
],
s
->
width
[
p
],
slice_end
-
slice_start
);
}
return
0
;
}
static
int
process_frame
(
FFFrameSync
*
fs
)
static
int
process_frame
(
FFFrameSync
*
fs
)
{
{
AVFilterContext
*
ctx
=
fs
->
parent
;
AVFilterContext
*
ctx
=
fs
->
parent
;
ThresholdContext
*
s
=
fs
->
opaque
;
ThresholdContext
*
s
=
fs
->
opaque
;
AVFilterLink
*
outlink
=
ctx
->
outputs
[
0
];
AVFilterLink
*
outlink
=
ctx
->
outputs
[
0
];
AVFrame
*
out
,
*
in
,
*
threshold
,
*
min
,
*
max
;
AVFrame
*
out
,
*
in
,
*
threshold
,
*
min
,
*
max
;
ThreadData
td
;
int
ret
;
int
ret
;
if
((
ret
=
ff_framesync_get_frame
(
&
s
->
fs
,
0
,
&
in
,
0
))
<
0
||
if
((
ret
=
ff_framesync_get_frame
(
&
s
->
fs
,
0
,
&
in
,
0
))
<
0
||
...
@@ -87,29 +134,18 @@ static int process_frame(FFFrameSync *fs)
...
@@ -87,29 +134,18 @@ static int process_frame(FFFrameSync *fs)
if
(
!
out
)
if
(
!
out
)
return
AVERROR
(
ENOMEM
);
return
AVERROR
(
ENOMEM
);
}
else
{
}
else
{
int
p
;
out
=
ff_get_video_buffer
(
outlink
,
outlink
->
w
,
outlink
->
h
);
out
=
ff_get_video_buffer
(
outlink
,
outlink
->
w
,
outlink
->
h
);
if
(
!
out
)
if
(
!
out
)
return
AVERROR
(
ENOMEM
);
return
AVERROR
(
ENOMEM
);
av_frame_copy_props
(
out
,
in
);
av_frame_copy_props
(
out
,
in
);
for
(
p
=
0
;
p
<
s
->
nb_planes
;
p
++
)
{
td
.
out
=
out
;
if
(
!
(
s
->
planes
&
(
1
<<
p
)))
{
td
.
in
=
in
;
av_image_copy_plane
(
out
->
data
[
p
],
out
->
linesize
[
p
],
td
.
threshold
=
threshold
;
in
->
data
[
p
],
in
->
linesize
[
p
],
td
.
min
=
min
;
s
->
width
[
p
]
*
s
->
bpc
,
td
.
max
=
max
;
s
->
height
[
p
]);
ctx
->
internal
->
execute
(
ctx
,
filter_slice
,
&
td
,
NULL
,
continue
;
FFMIN
(
s
->
height
[
2
],
ff_filter_get_nb_threads
(
ctx
)));
}
s
->
threshold
(
in
->
data
[
p
],
threshold
->
data
[
p
],
min
->
data
[
p
],
max
->
data
[
p
],
out
->
data
[
p
],
in
->
linesize
[
p
],
threshold
->
linesize
[
p
],
min
->
linesize
[
p
],
max
->
linesize
[
p
],
out
->
linesize
[
p
],
s
->
width
[
p
],
s
->
height
[
p
]);
}
}
}
out
->
pts
=
av_rescale_q
(
s
->
fs
.
pts
,
s
->
fs
.
time_base
,
outlink
->
time_base
);
out
->
pts
=
av_rescale_q
(
s
->
fs
.
pts
,
s
->
fs
.
time_base
,
outlink
->
time_base
);
...
@@ -324,5 +360,5 @@ AVFilter ff_vf_threshold = {
...
@@ -324,5 +360,5 @@ AVFilter ff_vf_threshold = {
.
activate
=
activate
,
.
activate
=
activate
,
.
inputs
=
inputs
,
.
inputs
=
inputs
,
.
outputs
=
outputs
,
.
outputs
=
outputs
,
.
flags
=
AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
,
.
flags
=
AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
|
AVFILTER_FLAG_SLICE_THREADS
,
};
};
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment