Skip to content

Instantly share code, notes, and snippets.

@ghotz
Last active August 14, 2020 08:06
Show Gist options
  • Select an option

  • Save ghotz/549b9129824e37f274b141d9f73ed752 to your computer and use it in GitHub Desktop.

Select an option

Save ghotz/549b9129824e37f274b141d9f73ed752 to your computer and use it in GitHub Desktop.
Extract Creation/Encoded date/time from DVCAM AVI or HDC M2T files, set it to file creation/modified date time and add it as a prefix to filename
# Extract DV AVI Creation date/time, set it to file creation/modified date time and add it as a prefix to filename
# Needs Medianfo CLI executable from https://mediaarea.net/en/MediaInfo/Download/Windows
# Note: -LiteralPath is used because directory names have [] characters
dir -LiteralPath 'Z:\Videos' -Include *.avi | % {
$CreationDate = & C:\utils\mediainfo\MediaInfo.exe --Inform="General;%Recorded_Date%" "$($_.FullName)";
$_.CreationTime = [datetime]$CreationDate;
$_.LastWriteTime = [datetime]$CreationDate;
$prefix = $CreationDate -replace '-|:|.000','' -replace " ", "-";
Rename-Item -LiteralPath $_.FullName ($prefix + '-' + $_.Name);
}
# Extract HDV m2t Creation date/time, set it to file creation/modified date time and add it as a prefix to filename
# Needs Medianfo CLI executable from https://mediaarea.net/en/MediaInfo/Download/Windows
# Note: -LiteralPath is used because directory names have [] characters
dir -LiteralPath 'Z:\Videos' -Include *.m2t | % {
$CreationDateStr = & C:\utils\mediainfo\MediaInfo.exe --Inform="General;%Encoded_Date%" "$($_.FullName)";
$CreationDateUtc = [DateTime]::SpecifyKind(($CreationDateStr -replace 'UTC', ''), [DateTimeKind]::Utc);
# you need to know the time zone where the video was recorded
$CreationDateAtRecordingSite = [System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId($CreationDateUtc, 'Central European Standard Time')
$_.CreationTime = $CreationDateAtRecordingSite;
$_.LastWriteTime = $CreationDateAtRecordingSite;
$prefix = $CreationDateAtRecordingSite.ToString('yyyyMMdd-HHmmss');
Rename-Item -LiteralPath $_.FullName ($prefix + '-' + $_.Name);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment