avformat/mux: factorize header writing code