#!/usr/bin/env ruby # Invia overlay.png aggiornata a ffmpeg via image2pipe (FIFO). # ffmpeg con -loop 1 legge il file una sola volta: questo processo rilegge il PNG # quando cambia mtime (punteggio, badge stato, …). require "fileutils" pipe_path = ARGV.fetch(0) png_path = ARGV.fetch(1) poll_sec = (ARGV[2] || ENV.fetch("OVERLAY_PIPE_POLL_SEC", "0.4")).to_f abort "pipe mancante: #{pipe_path}" unless File.exist?(pipe_path) abort "png mancante: #{png_path}" unless File.exist?(png_path) stop = false trap("TERM") { stop = true } trap("INT") { stop = true } # image2pipe richiede frame continui: inviamo la PNG a ritmo fisso ( anche se invariata ). File.open(pipe_path, "wb") do |pipe| loop do break if stop if File.exist?(png_path) pipe.write(File.binread(png_path)) pipe.flush end sleep poll_sec end rescue Errno::EPIPE # ffmpeg chiuso end