Advertisement
Guest User

Untitled

a guest
May 17th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. ### Options __________________________________________________________________________________________________________
  2. $ffmpeg = "E:\OneDrive\ffmpeg\bin\ffmpeg.exe" # Set path to your ffmpeg.exe; Build Version: git-45581ed (2014-02-16)
  3. $folder = "E:\CutBlacks\*" # Set path to your video folder; '\*' must be appended
  4. $filter = @("*.mov","*.mp4") # Set which file extensions should be processed
  5. $dur = 4 # Set the minimum detected black duration (in seconds)
  6. $pic = 0.98 # Set the threshold for considering a picture as "black" (in percent)
  7. $pix = 0.15 # Set the threshold for considering a pixel "black" (in luminance)
  8.  
  9. ### Main Program ______________________________________________________________________________________________________
  10.  
  11. foreach ($video in dir $folder -include $filter -exclude "*_???.*" -r){
  12.  
  13. ### Set path to logfile
  14. $logfile = "$($video.FullName)_ffmpeg.log"
  15.  
  16. ### analyse each video with ffmpeg and search for black scenes
  17. & $ffmpeg -i $video -vf blackdetect=d=`"$dur`":pic_th=`"$pic`":pix_th=`"$pix`" -an -f null - 2> $logfile
  18.  
  19. ### Use regex to extract timings from logfile
  20. $report = @()
  21. Select-String 'black_start:.*black_end:' $logfile | % {
  22. $black = "" | Select start, end, cut
  23.  
  24. # extract start time of black scene
  25. $start_s = $_.line -match '(?<=black_start:)\S*(?= black_end:)' | % {$matches[0]}
  26. $start_ts = [timespan]::fromseconds($start_s)
  27. $black.start = "{0:HH:mm:ss.fff}" -f ([datetime]$start_ts.Ticks)
  28.  
  29. # extract duration of black scene
  30. $end_s = $_.line -match '(?<=black_end:)\S*(?= black_duration:)' | % {$matches[0]}
  31. $end_ts = [timespan]::fromseconds($end_s)
  32. $black.end = "{0:HH:mm:ss.fff}" -f ([datetime]$end_ts.Ticks)
  33.  
  34. # calculate cut point: black start time + black duration / 2
  35. $cut_s = ([double]$start_s + [double]$end_s) / 2
  36. $cut_ts = [timespan]::fromseconds($cut_s)
  37. $black.cut = "{0:HH:mm:ss.fff}" -f ([datetime]$cut_ts.Ticks)
  38.  
  39. $report += $black
  40. }
  41.  
  42. ### Write start time, duration and the cut point for each black scene to a seperate CSV
  43. $report | Export-Csv -path "$($video.FullName)_cutpoints.csv" –NoTypeInformation
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement