Skip to content

Instantly share code, notes, and snippets.

@TakamiChie
Last active January 14, 2023 10:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TakamiChie/ee761c6dd8c7b427914073f1098ed1fc to your computer and use it in GitHub Desktop.
Save TakamiChie/ee761c6dd8c7b427914073f1098ed1fc to your computer and use it in GitHub Desktop.
ffmpegを使用して動画を切り分ける(まとめ動画作成用)
## Cut and output video files.
## $range Specify the range to output. Specify as "Start:Length".
## $source The name of the file to read. This parameter is required.
## $outfile The name of the file to output. When not specified, it is output to the desktop folder with the file name "outfile.mp4".
## ex. movcut "30:10" [filename]
function movcut (
[Parameter(mandatory=$true)][ValidatePattern('^[\d\.]+:[\d\.]+$')][String] $range,
[Parameter(mandatory=$true)] $source,
[Parameter(mandatory=$false)] $outfile=""
) {
if($outfile -eq ""){ $outfile = [Environment]::GetFolderPath("Desktop") + "\outfile.mp4" }
$n = $range -Split ":"
ffmpeg -ss $($n[0]) -i ""${source}"" -t $($n[1]) ""${outfile}""
}
## Output multiple video files by specifying a partial part of a video file.
## $ranges Specify the range to output. Specify it as Start:Length in the array.
## $source The name of the file to read. This parameter is required.
## $outdir The name of the folder to output. If not specified, it will be output to the desktop folder.
## ex. movcuts 20:10,40:10,50:10 -source [filename]
function movcuts (
[Parameter(mandatory=$true)][String[]] $ranges,
[Parameter(mandatory=$true)] $source,
[Parameter(mandatory=$false)] $outdir=""
) {
if($outdir -eq ""){ $outdir = [Environment]::GetFolderPath("Desktop") }
$i = 1
foreach($range in $ranges){
movcut -range $range -source $source -outfile "${outdir}\${i}.mp4"
$i++;
}
}
@TakamiChie
Copy link
Author

ffmpegへ指定する秒数に小数点を指定できるように変更

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment