History

TOOLS: make autodeint detect telecine in parallel

This avoids having to rewind the video for a second telecine detection pass.

Kevin Mitchell committed 11 years ago

Commit ebdbb4f1 parent 968bd3d1 file · +26 −45Browse files

Unified · Split

TOOLS/lua/autodeint.lua+26−45
@@ -2,21 +2,16 @@ · 1 unmodified line
22 -- appropriate deinterlacing filter based on a short section of the
33 -- currently playing video.
44 --
5−-- It registers the key-binding ctrl+d, which when pressed, inserts
6−-- the filter vf=lavfi=idet. After 4 second, it examines the results
7−-- to determine whether the content progressive or interlaced and the
8−-- interlacing field dominance. It immediately sets the latter within
9−-- mpv.
5+-- It registers the key-binding ctrl+d, which when pressed, inserts the filters
6+-- ``vf=lavfi=idet,pullup,vf=lavfi=idet``. After 4 seconds, it removes these
7+-- filters and decides whether the content is progressive, interlaced, or
8+-- telecined and the interlacing field dominance.
109 --
11−-- If the content is judged not to be progressive, it may be either
12−-- interlaced or telecined. To determine which one, the video is
13−-- seeked back to the detection starting point with the "pullup"
14−-- filter inserted. After another four seconds, if idet thinks that
15−-- the pulled up viedo is "progressive", then pullup is the correct
16−-- filter and this script leaves it in places while removing the idet
17−-- filter. Otherwise, the content plain interlaced and mpv's deinterlace
18−-- property is set. This will usually insert the yadif deinterlacing filter.
10+-- Based on this information, it may set mpv's ``deinterlace`` property (which
11+-- usually inserts the yadif filter), or insert the ``pullup`` filter if the
12+-- content is telecined. It also sets mpv's ``field-dominance`` property.
1913 --
14+-- OPTIONS:
2015 -- The default detection time may be overridden by adding
2116 --
2217 -- --script-opts=autodeint.detect_seconds=<number of seconds>
@@ -37,6 +32,7 @@ require "mp.msg" · 14 unmodified lines
3732 script_name = mp.get_script_name()
3833 detect_label = string.format("%s-detect", script_name)
3934 pullup_label = string.format("%s", script_name)
35+ivtc_detect_label = string.format("%s-ivtc-detect", script_name)
4036
4137 -- number of seconds to gather cropdetect data
4238 detect_seconds = tonumber(mp.get_opt(string.format("%s.detect_seconds", script_name)))
@@ -69,30 +65,29 @@ function start_detect() · 26 unmodified lines
6965 mp.set_property("deinterlace","no")
7066 del_filter_if_present(pullup_label)
7167
72− percent_pos = mp.get_property("percent-pos")
73−
7468 -- insert the detection filter
75− local cmd = string.format('vf add @%s:lavfi=graph="idet"', detect_label)
69+ local cmd = string.format('vf add @%s:lavfi=graph="idet",@%s:pullup,@%s:lavfi=graph="idet"',
70+ detect_label, pullup_label, ivtc_detect_label)
7671 if not mp.command(cmd) then
77− mp.msg.error("failed to insert detection filter")
72+ mp.msg.error("failed to insert detection filters")
7873 return
7974 end
8075
8176 -- wait to gather data
82− timer = mp.add_timeout(detect_seconds, judge_field_dominance)
77+ timer = mp.add_timeout(detect_seconds, select_filter)
8378 end
8479
8580 function stop_detect()
8681 del_filter_if_present(detect_label)
82+ del_filter_if_present(ivtc_detect_label)
8783 timer = nil
88− mp.set_property("playback-pos", percent_pos)
8984 end
9085
9186 progressive, interlaced_tff, interlaced_bff, interlaced = 0, 1, 2, 3, 4
9287
93−function judge()
88+function judge(label)
9489 -- get the metadata
95− local result = mp.get_property_native(string.format("vf-metadata/%s", detect_label))
90+ local result = mp.get_property_native(string.format("vf-metadata/%s", label))
9691 num_tff = tonumber(result["lavfi.idet.multiple.tff"])
9792 num_bff = tonumber(result["lavfi.idet.multiple.bff"])
9893 num_progressive = tonumber(result["lavfi.idet.multiple.progressive"])
@@ -100,10 +95,10 @@ function judge() · 1 unmodified line
10095 num_interlaced = num_tff + num_bff
10196 num_determined = num_interlaced + num_progressive
10297
103− mp.msg.verbose("progressive = "..num_progressive)
104− mp.msg.verbose("interlaced-tff = "..num_tff)
105− mp.msg.verbose("interlaced-bff = "..num_bff)
106− mp.msg.verbose("undetermined = "..num_undetermined)
98+ mp.msg.verbose(label.." progressive = "..num_progressive)
99+ mp.msg.verbose(label.." interlaced-tff = "..num_tff)
100+ mp.msg.verbose(label.." interlaced-bff = "..num_bff)
101+ mp.msg.verbose(label.." undetermined = "..num_undetermined)
107102
108103 if num_determined < num_undetermined then
109104 mp.msg.warn("majority undetermined frames")
@@ -119,11 +114,12 @@ function judge() · 9 unmodified lines
119114 end
120115 end
121116
122−function judge_field_dominance()
123− verdict = judge()
117+function select_filter()
118+ -- handle the first detection filter results
119+ verdict = judge(detect_label)
124120 if verdict == progressive then
125− stop_detect()
126121 mp.msg.info("progressive: doing nothing")
122+ stop_detect()
127123 return
128124 elseif verdict == interlaced_tff then
129125 mp.set_property("field-dominance", "top")
@@ -133,21 +129,8 @@ function judge_field_dominance() · 3 unmodified lines
133129 mp.set_property("field-dominance", "auto")
134130 end
135131
136− local cmd = string.format("vf pre @%s:pullup", pullup_label)
137− if not mp.command(cmd) then
138− mp.msg.error("failed to insert pullup filter")
139− stop_detect()
140− return
141− end
142−
143− -- redo the detection with the pullup filter to see if it's telecined
144− mp.set_property("percent-pos", percent_pos)
145− timer = mp.add_timeout(detect_seconds, judge_ivtc)
146−end
147−
148−function judge_ivtc()
149− verdict = judge()
150−
132+ -- handle the ivtc detection filter results
133+ verdict = judge(ivtc_detect_label)
151134 if verdict == progressive then
152135 mp.msg.info(string.format("telecinied with %s field dominance: using pullup", mp.get_property("field-dominance")))
153136 stop_detect()
@@ -157,8 +140,6 @@ function judge_ivtc() · 3 unmodified lines
157140 mp.set_property("deinterlace","yes")
158141 stop_detect()
159142 end
160−
161− return
162143 end
163144
164145 mp.add_key_binding("ctrl+d", script_name, start_detect)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t