Temporary Workaround for GoPro footage re-encoding
Pre-releaseWin64 FFMPEG binary (based on up-to-date master branch of the FFMPEG project), which permits remuxing of unknown streams, like the TMCD stream with which the GoPro community has been having issues for some time now.
THIS BINARY IS THEORETICALLY DANGEROUS, skipping a codec_validation procedure EVERY TIME. The goal is to only make it work when "copy_unknown" flag is enabled, but it is not so trivial to have it passed into the remuxer.
The binary has been tested with this Powershell script:
# Define the directory containing the MP4 files
$videoDirectory = "E:\Video\GoPro\GoPro"
# Define the target directory for the encoded files
$targetDirectory = "C:\Video_Encode\NewGoPro"
# Ensure the target directory exists
if (-not (Test-Path -Path $targetDirectory)) {
New-Item -ItemType Directory -Force -Path $targetDirectory | Out-Null
}
# Get all MP4 files in the directory
$gxFiles = Get-ChildItem -Path $videoDirectory -Filter GX*.MP4 -Recurse
$ghFiles = Get-ChildItem -Path $videoDirectory -Filter GH*.MP4 -Recurse
# Loop through each GX*.MP4 file
foreach ($source in $gxFiles) {
# Construct the output file name by replacing the extension with .mp4
$outputPath = Join-Path -Path $targetDirectory -ChildPath ([System.IO.Path]::GetFileNameWithoutExtension($source.Name) + ".mp4")
Write-Host $source.FullName
# Execute the FFmpeg command to compress the video
& ffmpeg.exe -n -i $source.FullName `
-map 0 -map -0:d:2 -copy_unknown -map_metadata 0 `
-c copy -c:v hevc_nvenc -recast_media `
-write_tmcd 0 `
-spatial-aq 1 -aq-strength 8 -b_ref_mode 2 -lookahead_level 15 -tune hq -qp 34 -pix_fmt yuv420p -level '5.1' -no-scenecut 1 -strict_gop 1 `
-tag:v hvc1 -vf scale=out_range=pc:out_color_matrix=bt709 -color_range:v 'pc' -colorspace:v bt709 `
-tag:d:0 'tmcd' -tag:d:1 'gpmd' `
$outputPath
$target = Get-Item -LiteralPath $outputPath;
foreach ($prop in 'CreationTime', 'LastWriteTime', 'LastAccessTime'){
Write-Host $source.'LastWriteTime'
Write-Host $target.$prop
$target.$prop = $source.'CreationTime'
}
}
# Loop through each GH*.MP4 file
foreach ($source in $ghFiles) {
# Construct the output file name by replacing the extension with .mp4
$outputPath = Join-Path -Path $targetDirectory -ChildPath ([System.IO.Path]::GetFileNameWithoutExtension($source.Name) + ".mp4")
Write-Host $source.FullName
# Execute the FFmpeg command to compress the video
& ffmpeg.exe -n -i $source.FullName `
-map 0 -map -0:d:2 -copy_unknown -map_metadata 0 `
-c copy -c:v libx265 -recast_media `
-write_tmcd 0 -ss 00:00:50 -t 00:00:40 `
-crf 29 -pix_fmt yuv420p -level '5.1' -preset 'medium' -no-scenecut 1 `
-tag:v hvc1 -vf scale=out_range=pc:out_color_matrix=bt709 -color_range:v 'pc' -colorspace:v bt709 `
-tag:d:0 'tmcd' -tag:d:1 'gpmd' `
$outputPath
$target = Get-Item -LiteralPath $outputPath;
foreach ($prop in 'CreationTime', 'LastWriteTime', 'LastAccessTime'){
Write-Host $source.'LastWriteTime'
Write-Host $target.$prop
$target.$prop = $source.'CreationTime'
}
}
Issue explained:
The aforementioned TMCD stream is normally part of the .MOV format and should only be useful with QuickTime software present in Apple products. For some reason it has been included by GoPro in the .MP4 container, which does not support it by default.