ゆっくりMovieMaker4βで、指定のフォルダ下にある画像ファイルをタイムライン上に横並びのymmpファイルを出力するPowerShellスクリプトを作成しました。
#
# YMM4のymmpファイルをさくせいする。
#
using namespace System.Drawing
Param(
[String]$targetDir="画像を置いてあるフォルダ",
[String]$ymmpPath="出力する.ymmpのパス"
)
Add-Type -AssemblyName System.Drawing
$defaultLength = 6000
$currentFrame = 0
$moveWidth = 3840
$moveHeight = 2160
$data = [PSCustomObject]@{
Timeline = [PSCustomObject]@{
VideoInfo = [PSCustomObject]@{
"FPS" = 60
"Hz" = 48000
"Width" = $moveWidth
"Height" = $moveHeight
}
"Items" = [PSCustomObject]@()
"LayerVisibilities" = [PSCustomObject]@{
"HiddenLayers" = @()
}
"CurrentFrame" = 0
"Length" = 1
"MaxLayer" = 0
}
"Characters" = @()
}
Get-ChildItem -LiteralPath $targetDir -Filter "*.png" | % {
$bmp = [Bitmap]::FromFile($_.FullName)
$Width = $bmp.Width
$Height = $bmp.Height
$bmp.Dispose()
$scale = [double]$moveWidth / [double]$Width
$data.Timeline.Items +=
[PSCustomObject]@{
'$type'="YukkuriMovieMaker.Project.Items.ImageItem, YukkuriMovieMaker"
"FilePath"=$_.FullName
"X" = [PSCustomObject]@{
"From" = 0.0
"To" = 0.0
"AnimationType" = "なし"
"Span" = 0.0
}
"Y" = [PSCustomObject]@{
"From" = 0.0
"To" = 0.0
"AnimationType" = "なし"
"Span" = 0.0
}
"Opacity" = [PSCustomObject]@{
"From" = 100.0
"To" = 0.0
"AnimationType" = "なし"
"Span" = 0.0
}
"Zoom" = [PSCustomObject]@{
"From" = $scale * 100.0
"To" = 0.0
"AnimationType" = "なし"
"Span" = 0.0
}
"Rotation" = [PSCustomObject]@{
"From" = 0.0
"To" = 0.0
"AnimationType" = "なし"
"Span" = 0.0
}
"FadeIn" = 0.0
"FadeOut" = 0.0
"Blend" = "Normal"
"IsInverted" = $false
"IsAlwaysOnTop" = $false
"VideoEffects" = @()
"Group" = 0
"Frame" = $currentFrame
"Layer" = 0
"Length" = $defaultLength
"PlaybackRate" = 100.0
"ContentOffset" = "00:00:00"
"IsLocked" = $false
"IsHidden" = $false
}
$currentFrame += $defaultLength
}
$max = ($data.Timeline.Items | % { $_.Frame } | measure-object -maximum).Maximum
$len = ($data.Timeline.Items | ? { $_.Frame -eq $max }).Length
$data.Timeline.Length = $max + $len
$data.Timeline.MaxLayer = ($data.Timeline.Items | % { $_.Layer } | measure-object -maximum).Maximum
$data | ConvertTo-Json -Depth 4 | Set-Content -LiteralPath $ymmpPath -Encoding UTF8
以前ゆっくりMovieMaker3でも同じ目的のスクリプトを作成しました.
ゆっくりMovieMaker3の.ymmpはXML形式でしたが、ゆっくりMovieMaker4βの.ymmpはjson形式でしたので互換性はないです。
.ymmpを新規に作成する作りなっています。
.ymmpファイルをコピー
参照している素材ファイルごとコピーするプログラムです。実行前に関連ファイルのバックアップを強く推奨。
<#
.SYNOPSIS
ゆっくりムービーメーカー4のYMMPファイルをコピー
.DESCRIPTION
YMMPファイル以外に素材ファイルをコピー先のディレククトリにサブディレクトリ作成しコピー
.EXAMPLE
実行例
.INPUTS
入力
.OUTPUTS
出力
.PARAMETER 引数名
引数
.LINK
関連URL
#>
param(
[string]
$srcFile="コピー元の.ymmpのパス",
[string]
$dstFile="コピー先.ymmpのパス"
)
#Write-Host $srcFile
#Write-Host $dstFile
$dstDir = Split-Path $dstFile
$srcDir = Split-Path $srcFile
$audioDir = Join-Path $dstDir "Audio"
$videoDir = Join-Path $dstDir "Video"
$imageDir = Join-Path $dstDir "Image"
$textDir = Join-Path $dstDir "Text"
$outputDir = Join-Path $dstDir "Output"
if (-not (Test-Path $audioDir)) { New-Item $audioDir -ItemType Directory }
if (-not (Test-Path $videoDir)) { New-Item $videoDir -ItemType Directory }
if (-not (Test-Path $imageDir)) { New-Item $imageDir -ItemType Directory }
if (-not (Test-Path $textDir)) { New-Item $textDir -ItemType Directory }
if (-not (Test-Path $outputDir)) { New-Item $outputDir -ItemType Directory }
# チャプターファイルのコピー
$basename = [System.IO.Path]::GetFileNameWithoutExtension($srcFile)
$chapterSrcFile = Join-Path $srcDir "${basename}.txt"
if (Test-Path $chapterSrcFile) {
$chapterDstFile = Join-Path $outputDir "${basename}.txt"
Copy-Item -Path $chapterSrcFile -Destination $chapterDstFile -Force
}
# ymmp読み込み
$data = Get-Content -LiteralPath $srcFile -Encoding UTF8 | ConvertFrom-Json
# YMMPファイルのパスをセット
$data.FilePath = $dstFile
# Itemsの件数取得
$count = ($data.Timelines.Items).Count
for ($i = 0; $i -lt $count; $i++)
{
# Itemsループ
if ($data.Timelines.Items[$i].'$type' -eq "YukkuriMovieMaker.Project.Items.VoiceItem, YukkuriMovieMaker") {
# 読み上げ音声
# 何もしない
continue
}
$source = $data.Timelines.Items[$i].FilePath
$fileName = Split-Path $source -Leaf
$destination = ""
if ($data.Timelines.Items[$i].'$type' -eq "YukkuriMovieMaker.Project.Items.VideoItem, YukkuriMovieMaker") {
# 動画
$destination = Join-Path $videoDir $fileName
}
if ($data.Timelines.Items[$i].'$type' -eq "YukkuriMovieMaker.Project.Items.AudioItem, YukkuriMovieMaker") {
# 音声
$destination = Join-Path $audioDir $fileName
}
if ($data.Timelines.Items[$i].'$type' -eq "YukkuriMovieMaker.Project.Items.ImageItem, YukkuriMovieMaker") {
# 静止画
$destination = Join-Path $imageDir $fileName
}
Write-Host $destination
# 素材ファイルのコピー
Copy-Item -Path $source -Destination $destination -Force
# コピー先のパスをセット
$data.Timelines.Items[$i].FilePath = $destination
}
# YMMPファイルの保存
$data | ConvertTo-Json -Depth 10 | Set-Content -LiteralPath $dstFile -Encoding UTF8
コメント