shithub: h264bsd

ref: d845fb5e4d7e03cd55f0c627f5c5d81c4599ec8b
dir: /test/Rakefile/

View raw version
require 'open-uri'

def output_dir(size)
  sprintf("output/%s", size)
end

def raw_dir(size)
  sprintf("raw/%s", size)
end

def raw_files(size)
  (5208..5280).collect {|n| sprintf("raw/%s/big_buck_bunny_%05d.png", size, n)}
end

# 640x360
directory raw_dir("640x360")

rule %r(raw/640x360/big_buck_bunny_[0-9]+\.png) => raw_dir("640x360") do |t|
  url = sprintf("http://media.xiph.org/BBB/BBB-360-png/%s", t.name.pathmap("%f"))
  puts "Grabbing #{url}"
  open(url) do |s|
    IO.copy_stream(s, t.name)
  end
end

file "test_640x360.h264" => raw_files("640x360") do |f|
  sh "ffmpeg -y -start_number 5208 -i raw/640x360/big_buck_bunny_%05d.png -pix_fmt yuv420p -c:v libx264 -x264-params keyint=40 -profile:v baseline -f rawvideo test_640x360.h264"
end

# 1920x1080
directory raw_dir("1920x1080")

rule %r(raw/1920x1080/big_buck_bunny_[0-9]+\.png) => raw_dir("1920x1080") do |t|
  url = sprintf("http://media.xiph.org/BBB/BBB-1080-png/%s", t.name.pathmap("%f"))
  puts "Grabbing #{url}"
  open(url) do |s|
    IO.copy_stream(s, t.name)
  end
end

file "test_1920x1080.h264" => raw_files("1920x1080") do |f|
  sh "ffmpeg -y -start_number 5208 -i raw/1920x1080/big_buck_bunny_%05d.png -pix_fmt yuv420p -c:v libx264 -x264-params keyint=40 -profile:v baseline -f rawvideo test_1920x1080.h264"
end

task :generate_test_data => ["test_640x360.h264", "test_1920x1080.h264"]

directory output_dir("640x360")
directory output_dir("1920x1080")

task :generate_output_data => ["test_640x360.h264", "test_1920x1080.h264", output_dir("640x360"), output_dir("1920x1080")] do
  sh "ffmpeg -y -i test_640x360.h264 -c:v rawvideo -f image2 -pix_fmt yuv420p output/640x360/frame_%02d.yuv"
  sh "ffmpeg -y -i test_1920x1080.h264 -c:v rawvideo -f image2 -pix_fmt yuv420p output/1920x1080/frame_%02d.yuv"
end

task :clean do
  FileUtils.rm_rf "raw"
  FileUtils.rm_rf "output"
  FileUtils.rm_f "test_640x360.h264"
  FileUtils.rm_f "test_1920x1080.h264"
end

task :default => [:generate_test_data]