DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: Run software on GPU to compress images?  (Read 7,332 times)

nickodemos

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 144
    • Military Service Badge - US Army
    • Military Service Badge - US Marine Corp
Run software on GPU to compress images?
« on: January 10, 2023, 04:50 PM »
I compress PNG images with GitHub - fhanau/Efficient-Compression-Tool: Fast and effective C++ file optimizer as this is the best compressor I have found. As with any software that compresses a file, it takes time. I was wondering if there was a way to offload the compressing to the GPU to see if there is an increase in speed.

« Last Edit: January 10, 2023, 07:35 PM by Deozaan »

4wd

  • Pedantic Old Bastard
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,652
    • Coding Snacks
Re: Run software on GPU to compress images?
« Reply #1 on: January 11, 2023, 01:51 AM »
You'd probably have to find a program that uses OpenCL.

ECT doesn't seem to cause much CPU load, typically less than %20 on my machine so you could speed things up by running concurrent tasks.

Example:
Code: (text)
.\timeit.exe .\ect.exe -9 .\20221224-topaz-denoise.png
Processed 1 file
Saved 1.95MB out of 12.34MB (15.7650%)

Version Number:   Windows NT 6.2 (Build 9200)
Exit Time:        12:32 am, Wednesday, January 11 2023
Elapsed Time:     0:01:28.952
Process Time:     0:01:28.937

Five concurrent processes on the same file, (five different names):
Code: (text)
.\timeit.exe .\ect.exe -9 .\20221224-topaz-denoise(x).png
Processed 1 file
Saved 1.95MB out of 12.34MB (15.7650%)

Version Number:   Windows NT 6.2 (Build 9200)
Exit Time:        12:39 am, Wednesday, January 11 2023
Elapsed Time:     0:01:42.891
Process Time:     0:01:42.703

Time to process increased by 14 seconds, (this was the same for all processes give or take a few ms), CPU utilization was still under 60% so still plenty left for doing other things.

So for the cost of an extra 14 seconds I got a 5 fold increase in files processed, files had the same properties of course but it should still scale similarly.
"I will not follow where the path may lead, but I will go where there is no path, and I will leave a trail." - Muriel Strode, 1903

nickodemos

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 144
    • Military Service Badge - US Army
    • Military Service Badge - US Marine Corp
Re: Run software on GPU to compress images?
« Reply #2 on: January 11, 2023, 04:38 AM »
The issue is that I can not script so if you are willing to help with a script to process all png files in the current directory with ECT then it would be appreciated.

4wd

  • Pedantic Old Bastard
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,652
    • Coding Snacks
Re: Run software on GPU to compress images?
« Reply #3 on: January 11, 2023, 11:31 AM »
The below tested ok on my machine, there's a lot of comments which should make it easy to understand.

Basically:
  • Grabs list of PNGs in directory
  • Splits list into number of cmd files along with formatting for ect.exe
  • Executes cmd files

NOTES:
  1. Edit in the full path to ect.exe - see comments
  2. Edit in your ect.exe options - see comments
  3. I only run PowerShell 7+ so that's what I tested it on

You'll see a CLI window open for each cmd file running along with output from ect.exe in each, they close as each cmd file finishes.

Code: ( powershell)
<#
RunEct.ps1

Open a PowerShell console:

path\to\RunEct.ps1 <path of PNG files> [-Threads <x>]

Default number of threads is 4

Examples:

.\RunEct.ps1 d:\png-images
d:\RunEct.ps1 "f:\png images" -Threads 8

#>

param(
  [Parameter(Mandatory=$true)][string]$Path,
  [int]$Threads = 4
)

# Full path to ect.exe
$ectPath = "R:\ect.exe"
# Options for ect.exe
$ectOpts = "-9"

# Get the system TEMP path
$tempPath = [System.IO.Path]::GetTempPath()

# Get all PNG files within the directory
$files = (Get-ChildItem "$($Path)/*" -Include *.png)

# Collect the file names into a list
$fileNames = $files.Name
# Get the number of files
$numberOfFiles = $fileNames.Count
# Set the number of cmd files to the number of required threads to run
# and set number of files per list
$numberOfLists = $Threads
$filesPerList = [Math]::Ceiling($numberOfFiles / $numberOfLists)

# Create a list to hold the cmd file names
$cmdFiles = @()
# Split the number of files between the number of lists
for ($i = 0; $i -lt $numberOfLists; $i++) {
  $startIndex = $i * $filesPerList
  $endIndex = $startIndex + $filesPerList - 1
  $list = $fileNames[$startIndex..$endIndex]
# Create a temp cmd file
  $filePath = [System.IO.Path]::Combine($tempPath, "ectTempFile$($i).cmd")
  New-Item -Path $filePath -ItemType File -Force
# Add it to the cmd file list
  $cmdFiles += $filePath
# Output that list of files to the cmd file with formatting to run ect.exe on each
  $list | ForEach-Object {
    "$($ectPath) $($ectOpts) `"$($_)`""
  } | Set-Content -Path $filePath
}

# Change current location to input path
Push-Location $Path

# Execute each cmd file
$cmdFiles | ForEach-Object {
# Remove the hash (#) in the line below to have all output to the PowerShell console
    Start-Process cmd.exe -ArgumentList "/c $($_)" #-NoNewWindow
}

# Jump back to original path
Pop-Location

Each ECT process causes ~10% CPU load on my Ryzen 5 5600X.
2023-01-12 13_08_30-Task Manager.png
"I will not follow where the path may lead, but I will go where there is no path, and I will leave a trail." - Muriel Strode, 1903
« Last Edit: January 12, 2023, 02:12 AM by 4wd »

Original address: https://www.donationcoder.com/forum/index.php?topic=53002.0