吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1470|回复: 11
收起左侧

[其他原创] power shell ffmpeg视频截图九宫格缩图预览

  [复制链接]
aichiyu 发表于 2023-10-14 22:35
[Asm] 纯文本查看 复制代码
$files = Get-ChildItem *.mp4,*.mkv
foreach ($file in $files) {
    # 定义函数以获取视频时长
    function Get-VideoDuration($file) {
        $ffmpegOutput = & ffmpeg -i $file 2>&1
        $durationMatch = [regex]::Match($ffmpegOutput, 'Duration: (\d+:\d+:\d+\.\d+)')
        if ($durationMatch.Success) {
            $duration = $durationMatch.Groups[1].Value
            $timeComponents = $duration -split ':'
            $durationInSeconds = [int]$timeComponents[0] * 3600 + [int]$timeComponents[1] * 60 + [math]::Round([double]$timeComponents[2])
            return $durationInSeconds
        }
        return 0
    }
    #文件
    $fileRootPath = $file.Name
    #$fileRootPath = Read-Host "名称带文件类型"
    #$fileRootPath = ""
    $time = Get-VideoDuration $fileRootPath
    #Write-Host "视频时长:$time 秒"

    # 获取视频时长
    $durationInSeconds = Get-VideoDuration $fileRootPath

    # 计算截取的时间点,从第10秒开始,平均分成9帧
    $frameTimes = @()
    for ($i = 0; $i -lt 9; $i++) {
        $frameTimes += [math]::Round(10 + $durationInSeconds / 9 * $i)
    }

    # 定义文件路径和参数
    $outputPath = "img"
    New-Item -Path ./$outputPath -ItemType Directory -Force
    # 生成创建图像的命令 -n 是跳过 -y是覆盖
    for ($i = 0; $i -lt 9; $i++) {
        $command = "ffmpeg -ss " + $frameTimes[$i] + " -i `"$fileRootPath`" -vframes 1 -q:v 2 " + $outputPath + "\frame_$i.jpg"
        Invoke-Expression $command
        Write-Host "已截取图像 $i"
    }

    # 合并截取的图像成图像网格
    # 获取文件大小
    $fileInfo = Get-Item $file.Name
    $fileSizeBytes = $fileInfo.Length
    $fileSizeGB = [math]::Round($fileSizeBytes / 1GB, 2)  # 转换为千兆字节

    # 转换时间
    $hours = [math]::floor($time / 3600)  # 计算小时
    $minutes = [math]::floor(($time % 3600) / 60)  # 计算分钟
    $seconds = $time % 60  # 计算剩余的秒数

    $名称 =$file.Name -replace ".mp4|.mkv", ""

    # 水印图像文件路径
    $watermarkImage = "D:/Software/O.png"
    #$watermarkImage = "E:/O.png"

    # 合并图像和水印
    $font = "D:/Software/ios.ttf"
    #$font = "E:/ios.ttf"
    $text = "名      称:$名称`n视频时长:$hours 小时 $minutes 分钟 $seconds 秒`n大      小:$fileSizeGB.GB"
    $标题 = "$名称"
    $视频时长 = "视频时长:$hours 小时 $minutes 分钟 $seconds 秒"
    $大小 = "大小:$fileSizeGB.GB"
    $outputFileName = "$fileRootPath.jpg"

    $mergeCommand = "ffmpeg -y -i `"$outputPath\frame_%d.jpg`" -i $watermarkImage -filter_complex `"
    [0:v]scale=-1:468,drawbox=x=0:y=0:w=iw:h=ih:c=white:t=10,tile=3x3,
    pad=iw:ih+155:0:155:white,drawtext=text='$text':fontfile='$font':fontsize=35:fontcolor=black:x=600:y=30[bg];
    [bg][1:v]overlay=10:10`" `"$outputFileName`""
    Invoke-Expression $mergeCommand


    Remove-Item -Path .\$outputPath -Recurse #删除图片
    Write-Host "图像网格创建完成。"
}

(9%MBMJ[8$QQUT81O2TVPAG.png
鸡肋

免费评分

参与人数 7吾爱币 +13 热心值 +7 收起 理由
苏紫方璇 + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
Eqwer + 1 + 1 我很赞同!
liyitong + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
TXT2BIN + 1 + 1 谢谢@Thanks!
腰围两尺99 + 1 + 1 用心讨论,共获提升!
为之奈何? + 1 + 1 我很赞同!
Bob5230 + 1 + 1 热心回复!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

liqingjun38 发表于 2023-10-15 00:02
感谢分享~
quanyuhai 发表于 2023-10-15 07:42
jxncyk 发表于 2023-10-15 08:08
igo9go 发表于 2023-10-15 08:51
楼主 我想要你预览的那个视频可以吗?
ysjd22 发表于 2023-10-15 09:15
太厉害了。。
ck1001CK 发表于 2023-10-15 09:21
居然是,柯南耶,画质不错哦
langbi 发表于 2023-10-15 09:30
感谢分享,顶一下
zx52 发表于 2023-10-15 10:42
感谢分享,有成品吗,类似exe的最好
liyitong 发表于 2023-10-15 11:04
好家伙。视频网站预览图,的小编,一下自动化了。
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-28 07:26

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表