Имя пользователя:
Пароль:  
Помощь | Регистрация | Забыли пароль?  

Показать сообщение отдельно

Ветеран


Сообщения: 27449
Благодарности: 8087

Профиль | Отправить PM | Цитировать


Ну, вот, как-то так:
Скрытый текст
Код: Выделить весь код
Param (
    [System.String]$Path2FFMpeg  = "$($ENV:ProgramFiles)\FFmpeg\bin\ffmpeg.exe", 
    [System.String]$SourceFolder = '.', 
    [System.Int32]$GroupBy       = 960
)

$SourceFolder = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($SourceFolder)

if([System.IO.Directory]::Exists($SourceFolder)) {
    if([System.IO.File]::Exists($Path2FFMpeg)) {
        do {
            $sFileList = [System.IO.Path]::Combine($SourceFolder, [System.IO.Path]::GetRandomFileName())
        } until(-not [System.IO.File]::Exists($sFileList))

        $hTable   = @{ iCount = 0 }
        $aFiles   = Get-ChildItem -Path "$SourceFolder\*.*" -File -Include '*.jpg', '*.jpeg', '*.jpe'

        if($aFiles.Count -gt 0) {
            $bSuccess = $true

            $aFiles | Group-Object { [Math]::DivRem($hTable.iValue++ , $GroupBy, [ref]$null) } | ForEach-Object -Process {
                $_.Group | ForEach-Object -Begin {
                    $sContent = ''
                } -Process {
                    $sContent += "file '$($_.Name)'`r`n"
                } -End {
                    $sOutputFileName = ($_.Group[0]).BaseName + ' - ' + ($_.Group[$_.Group.Count - 1]).BaseName + ".avi"

                    Out-File -InputObject $sContent -FilePath $sFileList -Encoding "Default" -NoNewline

                    $oCurrentCodePageEncoding = [Console]::OutputEncoding
                    [Console]::OutputEncoding = [System.Text.Encoding]::UTF8

                    $oProcess = Start-Process `
                        -FilePath $Path2FFMpeg `
                        -ArgumentList "-y -f concat -safe 0 -r 2 -i `"$([System.IO.Path]::GetFileName($sFileList))`" -threads 2 -vcodec libx264 -preset veryfast -qp 30 -tune grain -r 1 -framerate 1 `"$sOutputFileName`"" `
                        -WorkingDirectory $SourceFolder `
                        -NoNewWindow -Wait -PassThru
                    
                    [Console]::OutputEncoding = $oCurrentCodePageEncoding

                    if($oProcess.ExitCode -eq 0) {
                        Write-Host "`r`n$($_.Count) file(s) splitted into [$sOutputFileName].`r`n" -ForegroundColor Green
                    } else {
                        $bSuccess = $false
                        Write-Host "`r`nProbably an error [$($oProcess.ExitCode)] occured while try split files into [$sOutputFileName].`r`n" -ForegroundColor Red
                    }
                }
            }

            [System.IO.File]::Delete($sFileList)

            if($bSuccess) {
                switch($host.UI.PromptForChoice("Delete files?", "Delete all splitted jpeg files?", [System.Management.Automation.Host.ChoiceDescription[]] @("&Yes", "&No"), 1)) {
                    0 {
                        foreach($oFile in $aFiles) {
                            $oFile.Delete()
                            Write-Host "File [$($oFile.Name)] deleted." -ForegroundColor Green
                        }
                        Write-Host "`r`nTotal $($aFiles.Count) file(s) deleted." -ForegroundColor Green
                    }
                    1 {
                        # Nothing to do
                    }
                }
            }
        } else {
            Write-Host "Can't find any jpeg files in source folder [$SourceFolder], nothing to do." -ForegroundColor Green
        }
    } else {
        Write-Host "Can't find ffmpeg in [$Path2FFMpeg]." -ForegroundColor Red
    }
} else {
    Write-Host "Can't find source folder [$SourceFolder]." -ForegroundColor Red
}

Теперь первый параметр, Path2FFMpeg — путь к ffmpeg.exe (по умолчанию — C:\Program Files\FFmpeg\bin\ffmpeg.exe), второй параметр, SourceFolder — путь к целевому каталогу (по умолчанию — текущий каталог), третий параметр, GroupBy — число файлов в «пачке», из которой формируется видеофайл (по умолчанию — 960). Имена выходных видеофайлов формируются по указанному Вами принципу, нумерацию я оттуда вообще убрал.

Например, вызываем скрипт для обработки каталога 0008, находящегося в текущем каталоге, с группировкой файлов по двадцать штук:
Скрытый текст

Возможный результат
Это сообщение посчитали полезным следующие участники:

Отправлено: 02:35, 12-08-2018 | #25