--- /mod/webif/plugin/detectads/detectads_orig.jim
+++ /mod/webif/plugin/detectads/detectads.jim
@@ -152,7 +152,8 @@
admaxsec 65
padsec 0
makethm 0
- thmoffset 0}
+ thmoffset 0
+ padout 0}
# Override default from settings DB
foreach {key defvalue} [array get optarray] {
@@ -467,6 +468,7 @@
$queue_db close
}
+# Manual
proc ::detectads::run {ts} {
set file [$ts get file]
@@ -479,7 +481,11 @@
log "Cannot acquire exclusive lock $file, terminating." 0
return {"DEFER" "Cannot acquire exclusive lock"}
}
-
+ set stime [$ts get start]
+ set etime [$ts get end]
+ set durn $($etime-$stime)
+ set theend 0
+ set padding 0
set size [$ts size]
set numAdBreaks 0
set bname [file rootname [file tail $file]]
@@ -495,7 +501,14 @@
foreach {key value} [array get ::opts] {
set $key $value
}
-
+
+ if {$padsec} {
+ set padout 0
+ }
+ if {$padout} {
+ log "Padding out points by $padout secs and ignoring program end bookmark" 0
+ }
+
set tailPid 0; # unused (for killing head of pipe on timeout - useful with tail -f recording.ts | ffmpeg ... | silence...)
set silenceArgs "\
@@ -547,7 +560,23 @@
endSeconds]} {
set totalStartSeconds [expr {$startMinutes * 60 + $startSeconds}]
- set totalEndSeconds [expr {$endMinutes * 60 + $endSeconds}]
+ if {$cropcmd eq " " && $totalStartSeconds < 10 && $padout} {
+ set padding 3
+ } elseif {$padout} {
+ set padding $padout
+ }
+ set totalEndSeconds [expr {$endMinutes * 60 + $endSeconds - $padding}]
+ if {$totalEndSeconds < 0} {
+ set totalEndSeconds 0
+ }
+ set endMinutes [expr int($totalEndSeconds / 60)]
+ set endSeconds [expr ($totalEndSeconds % 60)]
+ if { [expr {$totalEndSeconds + 10}] > $durn} {
+ set totalEndSeconds [expr {$totalEndSeconds + $padding}]
+ if {$padout} {
+ set theend 1
+ }
+ }
log " ad break found $startMinutes:$startSeconds-$endMinutes:$endSeconds ($totalStartSeconds - $totalEndSeconds)" 0
@@ -565,7 +594,11 @@
ladd bookmarks 0 $totalStartSeconds $totalEndSeconds
}
} else {
- ladd bookmarks $totalStartSeconds $totalEndSeconds
+ if {$theend == 0} {
+ ladd bookmarks $totalStartSeconds $totalEndSeconds
+ } else {
+ ladd bookmarks $totalStartSeconds
+ }
}
}
# Update bookmarks and build up crop cmd line as each break is detected.- mymsman 150408
@@ -660,7 +693,11 @@
set elapsedTime [clock format $(round($elapsedSeconds)) -format "%H:%M:%S"]
log "ad detection.processed in ${elapsedSeconds}s $elapsedTime - $numAdBreaks ad breaks bookmarked, crop starting" 0
-
+ # calculate post crop edit point bookmarks
+ set len [$ts duration 1]
+ set newbookmark [editpointbm $bookmarks $len]
+ set originalused 0
+
# copy & paste from crop/execute.jim - mymsman 150407
set rfile $file
set dir [file dirname $rfile]
@@ -720,6 +757,7 @@
set cfile "$tgtpath/$shname-crop.ts"
if {![system inuse $cfile]} { # Rename crop file to original if not in use
ts renamegroup "$cfile" "$shname"
+ set originalused 1
}
} else {
log "$file safe_delete failed" 0
@@ -734,6 +772,11 @@
set elapsedTime [clock format $(round($elapsedSeconds)) -format "%H:%M:%S"]
log "done...processed in ${elapsedSeconds}s $elapsedTime - $numAdBreaks ad breaks cropped out" 0
set retcode [list "OK" "$numAdBreaks ad breaks cropped out" ]
+ # save post crop edit point bookmarks
+ if { !$originalused } {
+ set ts [ts fetch "$tgtpath/$shname-crop.ts"]
+ }
+ $ts setbookmarks $newbookmark
} else {
set elapsedSeconds [elapsed $start]
set elapsedTime [clock format $(round($elapsedSeconds)) -format "%H:%M:%S"]
@@ -746,6 +789,7 @@
return $retcode
}
+# Chaserun
proc ::detectads::chaserun {ts {Qid 0} {retrynumb 0}} {
# run ad detection against currently recording program using dlna helper - mymsman 150505
# creates decrypted, cropped and shrunk copy of file in video root directory.
@@ -768,12 +812,23 @@
}
set statustok [system startop -multiple detectads $file]
set size [$ts size]
+ set stime [$ts get start]
+ set etime [$ts get end]
+ set durn $($etime-$stime)
+ set theend 0
+ set padding 0
set numAdBreaks 0
# set each option from settings/overrides
foreach {key value} [array get ::opts] {
set $key $value
- }
+ }
+ if {$padsec} {
+ set padout 0
+ }
+ if {$padout} {
+ log "Padding out points by $padout secs and ignoring program end bookmark" 0
+ }
set tailPid 0; # unused (for killing head of pipe on timeout - useful with tail -f recording.ts | ffmpeg ... | silence...)
set silenceArgs "\
@@ -788,6 +843,7 @@
set stime [$ts get start]
set etime [$ts get end]
set ctime [clock seconds]
+ set len [$ts duration 1]
# Check file sharing enabled
if {[system param DMS_START_ON]} {
@@ -954,9 +1010,24 @@
startSeconds \
endMinutes \
endSeconds]} {
-
set totalStartSeconds [expr {$startMinutes * 60 + $startSeconds}]
- set totalEndSeconds [expr {$endMinutes * 60 + $endSeconds}]
+ if {$cropcmd eq " " && $totalStartSeconds < 10 && $padout} {
+ set padding 3
+ } elseif {$padout} {
+ set padding $padout
+ }
+ set totalEndSeconds [expr {$endMinutes * 60 + $endSeconds - $padding}]
+ if {$totalEndSeconds < 0} {
+ set totalEndSeconds 0
+ }
+ set endMinutes [expr int($totalEndSeconds / 60)]
+ set endSeconds [expr ($totalEndSeconds % 60)]
+ if { [expr {$totalEndSeconds + 10}] > $durn} {
+ set totalEndSeconds [expr {$totalEndSeconds + $padding}]
+ if {$padout} {
+ set theend 1
+ }
+ }
log " ad break found $startMinutes:$startSeconds-$endMinutes:$endSeconds ($totalStartSeconds - $totalEndSeconds) Frames: $startFrame - $endFrame" 0
@@ -976,7 +1047,11 @@
ladd bookmarks 0 $totalStartSeconds $totalEndSeconds
}
} else {
- ladd bookmarks $totalStartSeconds $totalEndSeconds
+ if {$theend == 0} {
+ ladd bookmarks $totalStartSeconds $totalEndSeconds
+ } else {
+ ladd bookmarks $totalStartSeconds
+ }
}
}
# Update bookmarks and build up crop cmd line as each break is detected.- mymsman 150408
@@ -1140,7 +1216,7 @@
set newtitle "$title -Len err ([clock format $misdetect -format %T])"
}
}
-
+ set originalused 0
if {$lengtherr == 0} {
# All OK (as far as we can tell)
set newtitle "Done"
@@ -1155,6 +1231,7 @@
if {![system inuse $cfile]} { # Rename crop file to original if not in use
exec hmt "+settitle=$title" "$cpath/$cname.hmt"
ts renamegroup "$cfile" "$bname"
+ set originalused 1
}
if {![system inuse $tfile]} { # Delete decrypt file no longer needed
$tts delete
@@ -1196,7 +1273,18 @@
}
close $recording
}
-
+
+ if { $crop } {
+
+ set newbookmark [ editpointbm $bookmarks $len ]
+
+ # save post crop edit point bookmarks
+ if { !$originalused } {
+ set ts [ts fetch "$tgtpath/$cname.ts"]
+ }
+ $ts setbookmarks $newbookmark
+ }
+
if {$tempQid} {
# remove temporary entryt from the queue
log "Removing item $tempQid ($file) from the queue" 1
@@ -1212,13 +1300,17 @@
set elapsedTime [clock format $(round($elapsedSeconds)) -format "%H:%M:%S"]
log "done...processed $file in ${elapsedSeconds}s $elapsedTime - $numAdBreaks ad breaks detected" 0
set retmsg "$numAdBreaks ad breaks detected, $warning"
-
+ if { $crop && $numAdBreaks && $retcode != "FAILED" } {
+ set retmsg "$numAdBreaks ad breaks cropped out. $warning"
+ }
+
system endop $statustok
release_lock $file
log "=============================================================" 1
set ::auto::loglevel ::autologlevel
return [list $retcode $retmsg $qtime]
-}
+}
+## proc detectads::chaserun end
proc set_HMT_durn {hmtfn start durn} {
# Update recording end & stored recording time in hmt file
@@ -1226,3 +1318,45 @@
exec hmt "+patch32=0x288:$durn" "$hmtfn.hmt"
}
+
+# calculate post crop edit point bookmarks
+proc editpointbm {bookmarks len} {
+ set keeping 0
+ set start -1
+ set newbookmark "0 "
+ set i -1
+ foreach b $bookmarks {
+ if {$start < 0} {
+ set start $b
+ set removing $b
+ continue
+ }
+ if {$i == 0} {
+ set start $b
+ set endad $($b - $removing)
+ incr removing $($endad - $startad)
+ set i -1
+ continue
+ }
+ set end $b
+ incr keeping $($end - $start)
+ set startad $($b - $removing)
+ append newbookmark "$($startad +3) "
+ set i 0
+ }
+ if {$i < 0 && $start > 0} {
+ incr keeping $($len - $start)
+ }
+ set n $([llength $newbookmark] - 1)
+ if {[lindex $newbookmark end] > [expr $keeping - 8] && $n > 0} {
+ set newbookmark [lreplace $newbookmark $n $n]
+ append newbookmark " $($keeping - 8)"
+ } elseif {$n == 0 && $keeping > 0} {
+ append newbookmark " $($keeping - 8)"
+ }
+ if {[lindex $newbookmark end] < [expr $keeping - 60]} {
+ append newbookmark " $($keeping - 8)"
+ }
+
+ return $newbookmark
+}