Skip to content

Instantly share code, notes, and snippets.

@remko remko/to_metadata.rb
Last active Dec 28, 2017

Embed
What would you like to do?
Converts a list of files to FFmpeg's metadata format
#!/usr/bin/env ruby
require 'csv'
def parse_csv(s)
return CSV.parse(s)[0][0]
end
title = parse_csv(`ffprobe -i \"#{ARGV[0]}\" -show_entries format_tags=album -v quiet -of csv=\"p=0\"`)
artist = parse_csv(`ffprobe -i \"#{ARGV[0]}\" -show_entries format_tags=artist -v quiet -of csv=\"p=0\"`)
puts ";FFMETADATA1"
puts "title=#{title}"
puts "artist=#{artist}"
start = 0
ARGV.each do |file|
puts "[CHAPTER]"
length = parse_csv(`ffprobe -i \"#{file}\" -show_entries format=duration -v quiet -of csv=\"p=0\"`)
length = Integer(Float(length)*1000000)
title = parse_csv(`ffprobe -i \"#{file}\" -show_entries format_tags=title -v quiet -of csv=\"p=0\"`)
title = title || file
puts "TIMEBASE=1/1000000"
puts "START=#{start}"
puts "END=#{start+length}"
puts "title=#{title}"
start = start + length
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.