ffmpeg-download.ps1.in 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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"
  4. Write-Output ("=" * 120)
  5. try {
  6. Get-content -Path "$PSScriptRoot\@OPENCV_LICENSES_INSTALL_PATH@\ffmpeg-readme.txt" -ErrorAction 'Stop'
  7. } catch {
  8. Write-Output "Refer to OpenCV FFmpeg wrapper readme notes about library usage / licensing details."
  9. }
  10. Write-Output ("=" * 120)
  11. Write-Output ""
  12. if(![System.IO.File]::Exists($output)) {
  13. try {
  14. [io.file]::OpenWrite($output).close()
  15. } catch {
  16. Write-Warning "Unable to write: $output"
  17. if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
  18. Write-Warning "Launching with 'Administrator' elevated privileges..."
  19. Pause
  20. Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs
  21. exit
  22. } else {
  23. Write-Output "FATAL: Unable to write with elevated privileges: $output"
  24. Pause
  25. exit 1
  26. }
  27. }
  28. try {
  29. Write-Output ("Downloading: " + $output)
  30. Import-Module BitsTransfer
  31. $start_time = Get-Date
  32. Start-BitsTransfer -Source $url -Destination $output -ErrorAction 'Stop'
  33. Write-Output "Downloaded in $((Get-Date).Subtract($start_time).Seconds) seconds"
  34. } catch {
  35. $_ # Dump error
  36. try {
  37. Write-Output ("Downloading (second attempt): " + $output)
  38. $start_time = Get-Date
  39. Invoke-WebRequest -Uri $url -OutFile $output
  40. Write-Output "Downloaded in $((Get-Date).Subtract($start_time).Seconds) seconds"
  41. } catch {
  42. Write-Output ("Can't download file: " + $output)
  43. Write-Output ("URL: " + $url)
  44. Write-Output "You need to download this file manually. Stop"
  45. Pause
  46. Exit
  47. }
  48. }
  49. } else {
  50. Write-Output ("File exists: " + $output)
  51. Write-Output ("Downloading is skipped. Remove this file and re-run this script to force downloading.")
  52. }
  53. if(![System.IO.File]::Exists($output)) {
  54. Write-Output ("Destination file not found: " + $output)
  55. Write-Output "Stop"
  56. Pause
  57. Exit
  58. }
  59. try {
  60. $hash = Get-FileHash $output -Algorithm MD5 -ErrorAction 'Stop'
  61. if($hash.Hash -eq $expected_md5) {
  62. Write-Output "MD5 check passed"
  63. } else {
  64. Write-Output ("MD5 : " + $hash.Hash.toLower())
  65. Write-Output ("Expected: " + $expected_md5)
  66. Write-Output "MD5 hash mismatch"
  67. }
  68. } catch {
  69. $_ # Dump error
  70. Write-Output "Can't check MD5 hash (requires PowerShell 4+)"
  71. }
  72. Pause
  73. Write-Output "Exit"