1 $url = "https://raw.githubusercontent.com/opencv/opencv_3rdparty/@FFMPEG_BINARIES_COMMIT@/ffmpeg/opencv_videoio_ffmpeg_64.dll"
2 $expected_md5 = "@FFMPEG_FILE_HASH_BIN64@"
3 $output = "$PSScriptRoot\@OPENCV_BIN_INSTALL_PATH@\opencv_videoio_ffmpeg@OPENCV_DLLVERSION@_64.dll"
5 Write-Output ("=" * 120)
7 Get-content -Path "$PSScriptRoot\@OPENCV_LICENSES_INSTALL_PATH@\ffmpeg-readme.txt" -ErrorAction 'Stop'
9 Write-Output "Refer to OpenCV FFmpeg wrapper readme notes about library usage / licensing details."
11 Write-Output ("=" * 120)
14 if(![System.IO.File]::Exists($output)) {
16 [io.file]::OpenWrite($output).close()
18 Write-Warning "Unable to write: $output"
19 if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
20 Write-Warning "Launching with 'Administrator' elevated privileges..."
22 Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs
25 Write-Output "FATAL: Unable to write with elevated privileges: $output"
32 Write-Output ("Downloading: " + $output)
33 Import-Module BitsTransfer
34 $start_time = Get-Date
35 Start-BitsTransfer -Source $url -Destination $output -ErrorAction 'Stop'
36 Write-Output "Downloaded in $((Get-Date).Subtract($start_time).Seconds) seconds"
40 Write-Output ("Downloading (second attempt): " + $output)
41 $start_time = Get-Date
42 Invoke-WebRequest -Uri $url -OutFile $output
43 Write-Output "Downloaded in $((Get-Date).Subtract($start_time).Seconds) seconds"
45 Write-Output ("Can't download file: " + $output)
46 Write-Output ("URL: " + $url)
47 Write-Output "You need to download this file manually. Stop"
53 Write-Output ("File exists: " + $output)
54 Write-Output ("Downloading is skipped. Remove this file and re-run this script to force downloading.")
57 if(![System.IO.File]::Exists($output)) {
58 Write-Output ("Destination file not found: " + $output)
65 $hash = Get-FileHash $output -Algorithm MD5 -ErrorAction 'Stop'
67 if($hash.Hash -eq $expected_md5) {
68 Write-Output "MD5 check passed"
70 Write-Output ("MD5 : " + $hash.Hash.toLower())
71 Write-Output ("Expected: " + $expected_md5)
72 Write-Output "MD5 hash mismatch"
76 Write-Output "Can't check MD5 hash (requires PowerShell 4+)"