Skip to content

Commit 390f0a5

Browse files
committed
cmake: generate and install ffmpeg-download.ps1
64-bit only
1 parent 0614ee3 commit 390f0a5

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ org.eclipse.jdt.core.prefs -text whitespace=cr-at-eol merge=union
8181
*.cmd text eol=crlf
8282
*.cmd.tmpl text eol=crlf
8383
*.dsp text eol=crlf -whitespace
84+
*.ps1 text eol=crlf
85+
*.ps1.in text eol=crlf
8486
*.sln text eol=crlf -whitespace
8587
*.vcproj text eol=crlf -whitespace merge=union
8688
*.vcxproj text eol=crlf -whitespace merge=union
+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
$url = "https://raw.githubusercontent.com/opencv/opencv_3rdparty/@FFMPEG_BINARIES_COMMIT@/ffmpeg/opencv_ffmpeg_64.dll"
2+
$expected_md5 = "@FFMPEG_FILE_HASH_BIN64@"
3+
$output = "$PSScriptRoot\@OPENCV_BIN_INSTALL_PATH@\opencv_ffmpeg@OPENCV_DLLVERSION@_64.dll"
4+
5+
Write-Output ("=" * 120)
6+
try {
7+
Get-content -Path "$PSScriptRoot\etc\licenses\ffmpeg-readme.txt" -ErrorAction 'Stop'
8+
} catch {
9+
Write-Output "Refer to OpenCV FFmpeg wrapper readme notes about library usage / licensing details."
10+
}
11+
Write-Output ("=" * 120)
12+
Write-Output ""
13+
14+
if(![System.IO.File]::Exists($output)) {
15+
try {
16+
Write-Output ("Downloading: " + $output)
17+
Import-Module BitsTransfer
18+
$start_time = Get-Date
19+
Start-BitsTransfer -Source $url -Destination $output -ErrorAction 'Stop'
20+
Write-Output "Downloaded in $((Get-Date).Subtract($start_time).Seconds) seconds"
21+
} catch {
22+
$_ # Dump error
23+
try {
24+
Write-Output ("Downloading (second attempt): " + $output)
25+
$start_time = Get-Date
26+
Invoke-WebRequest -Uri $url -OutFile $output
27+
Write-Output "Downloaded in $((Get-Date).Subtract($start_time).Seconds) seconds"
28+
} catch {
29+
Write-Output ("Can't download file: " + $output)
30+
Write-Output ("URL: " + $url)
31+
Write-Output "You need to download this file manually. Stop"
32+
Pause
33+
Exit
34+
}
35+
}
36+
} else {
37+
Write-Output ("File exists: " + $output)
38+
Write-Output ("Downloading is skipped. Remove this file and re-run this script to force downloading.")
39+
}
40+
41+
if(![System.IO.File]::Exists($output)) {
42+
Write-Output ("Destination file not found: " + $output)
43+
Write-Output "Stop"
44+
Pause
45+
Exit
46+
}
47+
48+
try {
49+
$hash = Get-FileHash $output -Algorithm MD5 -ErrorAction 'Stop'
50+
51+
if($hash.Hash -eq $expected_md5) {
52+
Write-Output "MD5 check passed"
53+
} else {
54+
Write-Output ("MD5 : " + $hash.Hash.toLower())
55+
Write-Output ("Expected: " + $expected_md5)
56+
Write-Output "MD5 hash mismatch"
57+
}
58+
} catch {
59+
$_ # Dump error
60+
Write-Output "Can't check MD5 hash (requires PowerShell 4+)"
61+
}
62+
Pause
63+
Write-Output "Exit"

3rdparty/ffmpeg/ffmpeg.cmake

+5
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,8 @@ function(download_win_ffmpeg script_var)
3535
set(${script_var} "${FFMPEG_DOWNLOAD_DIR}/ffmpeg_version.cmake" PARENT_SCOPE)
3636
endif()
3737
endfunction()
38+
39+
if(OPENCV_INSTALL_FFMPEG_DOWNLOAD_SCRIPT)
40+
configure_file("${CMAKE_CURRENT_LIST_DIR}/ffmpeg-download.ps1.in" "${CMAKE_BINARY_DIR}/win-install/ffmpeg-download.ps1" @ONLY)
41+
install(FILES "${CMAKE_BINARY_DIR}/win-install/ffmpeg-download.ps1" DESTINATION "." COMPONENT libs)
42+
endif()

0 commit comments

Comments
 (0)