Last active
March 12, 2022 08:39
-
-
Save simics-ja/99a8da258c8ea11d0def5553d6e56df8 to your computer and use it in GitHub Desktop.
[Powershellでffmpeg実行サンプル] #ffmpeg #Powershell
This file contains hidden or 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
# ビットレートが半分のh265にエンコードして、.\done\に出力するスクリプト | |
# NVENC使うのでGeForce系のグラボないとダメ | |
$items = Get-ChildItem; | |
Write-Output $lines; | |
foreach($i in $items){ | |
if($i.PSIsContainer -or [System.IO.Path]::GetExtension($i) -eq "ps1"){ | |
continue; | |
} | |
$name = [System.IO.Path]::GetFileNameWithoutExtension($i); | |
$ext = [System.IO.Path]::GetExtension($i) | |
$filename = $name + $ext | |
$info = ffprobe $filename -hide_banner -show_entries format=bit_rate | |
$regex = New-Object regex "bit_rate=(.+)\s\[" | |
$results = $regex.Matches($info) | |
$bitrate = $results[0].Groups[1].Value/2 | |
$bitrate = [Math]::Truncate($bitrate) | |
$bitrate | |
$filename | |
ffmpeg -i "$i" -vcodec hevc_nvenc -acodec aac -b:a 128k -b:v "$bitrate" ".\done\$name.mp4" | |
} |
This file contains hidden or 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
$csvs = Get-ChildItem ./csv | |
foreach($csv in $csvs) { | |
$csv_name = $csv.Name | |
$video_name = (Get-ChildItem ./ -Filter "$($csv_name.Substring(0, $csv_name.LastIndexOf("."))).*").Name | |
$no_ext_name = [System.IO.Path]::GetFileNameWithoutExtension($video_name); | |
$ext = [System.IO.Path]::GetExtension($video_name) | |
$trim_table = Import-Csv "./csv/$csv_name" -Header 'begin', 'end' | |
Write-Host "# start >> $video_name" | |
$i = 1 | |
foreach($section in $trim_table){ | |
$begin = [double]$section.begin | |
$end = [double]$section.end | |
if ($begin -eq "") { | |
$begin = "0.0" | |
} | |
if ($end -eq "") { | |
$info = ffprobe $video_name -v quiet -hide_banner -show_entries format=duration | |
$end = [double](New-Object regex "duration=(.+)\s\[").Matches($info).Groups[1].Value | |
} | |
$duration = $end-$begin | |
Write-Host "## begin: $begin, end: $end, duration: $duration" | |
Write-Host "# output: $no_ext_name$i.$ext" | |
ffmpeg -ss $begin -i $video_name -ss 0 -t $duration -c:v copy -c:a copy -async 1 "./trimed/$no_ext_name$i.$ext" | |
$i++ | |
} | |
} |
This file contains hidden or 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
# 連番のPNGをh264のmp4に変換 | |
ffmpeg -r 29.970 -i "input\%06d.jpg" -vcodec h264_nvenc video.mp4 | |
# 音声だけ無劣化抽出 | |
ffmpeg -i "input.mp4" -vn -acodec copy 'audio.aac' | |
# 無音動画に音声を結合 | |
ffmpeg -i video.mp4 -i audio.aac -c:v copy -c:a copy output.mp4 | |
# 動画を回転 | |
# transpose=1:90度 時計まわりに回転 | |
# transpose=2:90度 時計反まわりに回転 | |
# transpose=3:90度 時計まわり回転後、上下を反転 | |
# transpose=0:90度 時計反まわり回転後、上下を反転 | |
ffmpeg -i input.mp4 -vf "transpose=1" -crf 26 output.mp4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment