Skip to content

Instantly share code, notes, and snippets.

@retorillo
Last active April 12, 2021 12:56
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 retorillo/6e221f328c12b2e65fa888f3849f19b7 to your computer and use it in GitHub Desktop.
Save retorillo/6e221f328c12b2e65fa888f3849f19b7 to your computer and use it in GitHub Desktop.
$TZ = 9; $PN = 'メディアの作成日時'; $E = @{ H='AVC'; X='HENC' }; $S = new-object -comObject shell.application; $I = -1; $D = $S.namespace((get-item .).fullName); 0..512 | foreach { $prop = $D.getDetailsOf($null, $_); if ($prop -eq $PN) { $I= $_; } }; if ($I -ne -1) { dir *.mp4 | foreach { $F = $D.parseName($_.name); $W = '{0}.wav' -f $_.baseName; $M = ($_.name + "`t" + $D.getDetailsOf($F, $I)) -match '^G(H|X)([\d]{2})[\d]{4}.((?i)mp4)\t[^\d]*(\d{4})[^\d]+(\d{1,2})[^\d]+(\d{1,2})[^\d]+(\d{1,2})[^\d]+(\d{1,2}).*$'; if ($M) { $G = $Matches; $J = ((new-object datetime ($G[4], $G[5], $G[6], $G[7], $G[8], "0")) - [timespan]::fromhours($TZ)); $N = 'GOPRO_{0}_C{1}_{2}_{3}' -f $J.toString('yyyyMMdd_HHmm'), $G[2], $E[$G[1]], $_.baseName; rni $_.name ('{0}.mp4' -f $N); if (test-path $W) { rni $W ('{0}.wav' -f $N) } } } }
@retorillo
Copy link
Author

ファイル名の右側にあるRawのボタンをクリックしてもらえるとコピーしやすくなります

@retorillo
Copy link
Author

retorillo commented Apr 10, 2021

GoProにはタイムゾーンの設定項目がなく、世界標準時としてファイルを保存しているため、日本時間で設定していると「メディアの作成日時」に+9時間のズレが生じます。これを修正するコードも含まれており、正しく日本で撮影した時刻に調節してくれます。あくまで日本のWindows向けに作っており、海外で撮影・取り込む場合は問題があるかもしれません。$TZ = 9 を適切なタイムゾーンに設定し $PN = 'メディアの作成日時' をその国の言葉に修正することで期待通りに動作する場合があります。ただ、そもそも時間のフォーマットとして yyyy MM dd ... 形式に依存しているため、Windowsの日時の書式の設定を変えてる場合や、英語版にしている場合はうまく動作しない場合があります。コードはCC0として配布しますので自由に改変して使って下さい

@retorillo
Copy link
Author

retorillo commented Apr 10, 2021

以下のコードで元のファイル名に戻せるはずです

dir *.mp4,*.wav | foreach { if ($_.name -match "_(G.*\.((?i)mp4|wav))$") { move $_.name $Matches.1; "{0} => {1}" -f $_.name, $Matches.1 } }

@retorillo
Copy link
Author

GoProをRAWオーディオで撮影した場合に出力されるWAVファイルも合わせて変更されるように改良しました

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