Last active
May 10, 2019 04:33
-
-
Save nyanshiba/ad54d13d71a65bab45fc89441fd11823 to your computer and use it in GitHub Desktop.
OBSのメディアソースを使用してBGMと曲名を表示する為の、RGBAなaviとconcatフォーマットのtxtを生成するやつ https://nyanshiba.hatenablog.com/entry/2019/04/07/001832#OBS%E3%81%A0%E3%81%91%E3%81%A7BGM%E3%82%92%E5%86%8D%E7%94%9F%E6%9B%B2%E5%90%8D%E3%82%92%E8%A1%A8%E7%A4%BA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#190508 | |
#ユーザ設定 | |
$Settings = | |
@{ | |
#Input,Output指定: Output\input.txt Inputのみ指定: Input\input.txt | |
#BGM素材入力ディレクトリ | |
Input = "C:\Users\sbn\Music\audiolibrary" | |
#Input = "C:\Users\sbn\Music\minecraft\sounds\music" | |
#Input = "C:\Rec\audiolibrary" | |
#avi出力ディレクトリ | |
Output = "C:\Rec\audiolibrary" | |
#Output = "C:\Rec\minecraft" | |
#解像度 | |
Resolution = "640x40" | |
#フォントサイズ | |
FontSize = 32 | |
#フォントファイル | |
FontFile = 'C\://Users/sbn/Documents/fonts/minecraft_font_by_pwnage_block_d37t6nb.ttf' | |
} | |
function Out-ConcatTxt | |
{ | |
param | |
( | |
[string]$Dir | |
) | |
Write-Output "$Dir\input.txt" | |
#ファイルリストをシャッフルし、OBSのメディアソース(ffmpeg concat)で使用できるフォーマットでtxtに出力 | |
"ffconcat version 1.0`r`nfile '$(((Get-ChildItem "$Dir/*.*" -Recurse).Name | Get-Random -Count ([int]::MaxValue)) -join "'`r`nfile '")'" | Out-File "$Dir\input.txt" -Encoding UTF8 | |
} | |
#出力ディレクトリがなければ作成 | |
if (!(Test-Path $Settings.Output)) | |
{ | |
$null = New-Item -Path $Settings.Output -ItemType Directory -Force | |
} | |
if ($Settings.Output) | |
{ | |
#ソースディレクトリ下の全てのファイルに対し、その曲名が表示されるRGBA動画を作成 | |
foreach ($AudioFile in Get-ChildItem "$($Settings.Input)/*.*" -Recurse) | |
{ | |
$AudioFile.Name | |
#既に存在する場合は上書きしない | |
ffmpeg -n -v quiet -i "$($AudioFile.FullName)" -f lavfi -i "color=c=0x00000000:s=$($Settings.Resolution):r=1,format=pix_fmts=rgba" -vf "drawtext=fontsize=$($Settings.FontSize):fontcolor=0xe0e0e0:fontfile='$($Settings.FontFile)':text='$($AudioFile.BaseName)'" -c:a copy -c:v utvideo -pred median -shortest -pix_fmt rgba "$($Settings.Output)\$($AudioFile.BaseName).avi" | |
} | |
Out-ConcatTxt -Dir $Settings.Output | |
} else | |
{ | |
Out-ConcatTxt -Dir $Settings.Input | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment