Skip to content

Instantly share code, notes, and snippets.

Last active December 28, 2017 10:17
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save remko/8990436d33174deba5e88e5ea35596b0 to your computer and use it in GitHub Desktop.
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]
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 "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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment