Skip to content

Instantly share code, notes, and snippets.

@Geesu
Created August 6, 2018 18:59
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 Geesu/60be8537e07bda977794d171c2fa3e2c to your computer and use it in GitHub Desktop.
Save Geesu/60be8537e07bda977794d171c2fa3e2c to your computer and use it in GitHub Desktop.
Remove all metadata from MP4 files for better processing by Plex.
#!/bin/ruby
# This script specifically removes all meta data from mp4 files which have a title property set
# You can't change this property unfortunately. So instead just strip all metadata from the file with ffmpeg.
# Requirements:
# brew install ffmpeg exiftool
# Just set the path to all of your mp4 files
path = '/Volumes/Movies'
# Loop through all files recursively
Dir.glob("#{path}/**/*") do |original_file|
next if original_file == '.' or original_file == '..'
ext = File.extname(original_file)
directory = File.dirname(original_file)
filename = File.basename(original_file)
# mp4 files only
if ext.downcase == '.mp4'
# Check if we need to even process this file:
result = `exiftool -G1 -a -s -title "#{original_file}"`
if result.length > 0
puts "Updating meta data for #{original_file}"
puts result
new_file = "#{directory}/new_#{filename}"
`ffmpeg -i "#{original_file}" -map_metadata -1 -c:v copy -c:a copy "#{new_file}"`
`mv -f "#{new_file}" "#{original_file}"`
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment