Use existing video thumbnail image if present instead of generating a new one.

Ideas for improvements and requests for new features in XnView MP

Moderators: XnTriq, helmut, xnview

grimatoma
Posts: 2
Joined: Wed Sep 27, 2023 1:43 am

Use existing video thumbnail image if present instead of generating a new one.

Post by grimatoma »

Using an alternative program I can embed a thumbnail into my video files but XnView still generates a new one. Please make it so that it checks if there is an existing one and reuses that instead.

Code that can be used to merge thumbnails with a video

Code: Select all

 ffmpeg -hide_banner -i video.mp4 -i thumbnail.jpg -map 0 -map 1 -c copy -disposition:v:1 attached_pic videoWithThumbnai.mp4
Also code to search for video files and make thumbnail grids of videos

Code: Select all

param (
    [Parameter(Mandatory=$true)]
    [string]$directoryPath,

    [Parameter(Mandatory=$true)]
    [string]$outputDirectoryPath,

    [Parameter(Mandatory=$false)]
    [int]$height = 576,

    [Parameter(Mandatory=$false)]
    [int]$gridX = 4,

    [Parameter(Mandatoryl=$false)]
    [int]$gridY = 3
)

# Ensure the output directory exists
if (!(Test-Path -Path $outputDirectoryPath)) {
    New-Item -ItemType Directory -Force -Path $outputDirectoryPath
}

$videoExtensions = '*.mp4', '*.avi', '*.mkv', '*.mpg'
$videoFiles = Get-ChildItem -Path $directoryPath -Include $videoExtensions -Recurse -File | Where-Object { !($_.Extension -eq ".jpg") }
$totalVideos = $videoFiles.Count
$startDateTime = Get-Date

for ($i = 0; $i -lt $totalVideos; $i++) {
    $videoStartTime = Get-Date
    $videoFile = $videoFiles[$i]
    $videoFilePath = $videoFile.FullName
    $baseName = $videoFile.BaseName

    $duration = $(ffprobe -v error -select_streams v:0 -show_entries stream=duration -of default=noprint_wrappers=1:nokey=1 $videoFilePath)

    $framesToSkip = [Math]::Round($duration / ($gridX * $gridY))

    # Construct output file path within the provided output directory.
    $outputFilePath = Join-Path -Path $outputDirectoryPath -ChildPath "$baseName-grid.jpg"
    $vfArgument = "fps=fps=1/$framesToSkip,scale=-1:$height,tile=$($gridX)x$($gridY)"

    ffmpeg -n -hide_banner -loglevel panic -i $videoFilePath -vf $vfArgument -frames:v 1 -q:v 1 -update 1 $outputFilePath

    $videoEndTime = Get-Date
    $videoProcessingTime = $videoEndTime - $videoStartTime
    $estimatedRemainingTime = $videoProcessingTime.TotalSeconds * ($totalVideos - $i - 1)

    Write-Progress -Activity ("Processed {0} of {1}" -f ($i + 1), $totalVideos) -Status ("Estimated time remaining: {0:N2} seconds" -f $estimatedRemainingTime) -PercentComplete (($i + 1) / $totalVideos * 100)
}