42#ifndef CA_FFMPEG_SINK_H
43#define CA_FFMPEG_SINK_H
69namespace ca_ffmpeg_detail {
73 std::string
out =
"'";
74 for (
const char c : s)
87 return std::system(
"ffmpeg -version >/dev/null 2>&1") == 0;
96template <
typename Mapper>
107 command_ =
"ffmpeg -y -loglevel error -f image2pipe -vcodec ppm -r " + std::to_string(
opts_.
fps)
116 <<
"Ffmpeg_Frame_Sink: ffmpeg is not available in PATH";
121 <<
"Ffmpeg_Frame_Sink: cannot start ffmpeg";
146 other.pipe_ =
nullptr;
152 if (
pipe_ !=
nullptr)
169 return pipe_ !=
nullptr;
177 template <
typename Lattice>
181 if (
pipe_ ==
nullptr)
183 std::ostringstream
ppm(std::ios::binary);
185 const std::string bytes =
ppm.str();
186 const std::size_t
written = std::fwrite(bytes.data(), 1, bytes.size(),
pipe_);
188 <<
"Ffmpeg_Frame_Sink::accept: ffmpeg pipe write failed";
194 if (
pipe_ ==
nullptr)
200 <<
"Ffmpeg_Frame_Sink::flush: ffmpeg exited with status " << status;
204template <
typename Mapper>
Exception handling system with formatted messages for Aleph-w.
#define ah_runtime_error_if(C)
Throws std::runtime_error if condition holds.
size_t size_t int32_t * out
File-format readers and writers for cellular-automata frames.
Frame sink that streams PPM frames into ffmpeg.
bool active() const noexcept
Return true when a live ffmpeg process is attached.
Ffmpeg_Frame_Sink(Ffmpeg_Frame_Sink &&other) noexcept
Move-construct a sink, transferring the process handle.
Ffmpeg_Frame_Sink(std::filesystem::path output, Mapper mapper, Ffmpeg_Options opts={})
Build an ffmpeg frame sink.
~Ffmpeg_Frame_Sink()
Close ffmpeg best-effort.
const std::string & command() const noexcept
Return the ffmpeg command used by this sink.
void flush()
Flush and close the ffmpeg process if one was started.
void accept(const std::size_t step, const Lattice &frame)
Send one frame to ffmpeg, or no-op when inactive.
Ffmpeg_Frame_Sink(const Ffmpeg_Frame_Sink &)=delete
Ffmpeg_Frame_Sink & operator=(const Ffmpeg_Frame_Sink &)=delete
std::filesystem::path output_
Lattice that adds boundary-aware access on top of a storage.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
std::string shell_quote(const std::string &s)
void write_ppm(std::ostream &out, const Lattice &frame, Mapper &&mapper, const NetPBM_Write_Options &opts={})
Write a binary PPM (P6) image.
Main namespace for Aleph-w library functions.
and
Check uniqueness with explicit hash + equality functors.
Options for Ffmpeg_Frame_Sink.
bool auto_start
start ffmpeg in the constructor
std::string pixel_format
output pixel format
std::string codec
ffmpeg encoder name
unsigned fps
input and output frame rate
bool require_ffmpeg
throw if ffmpeg cannot be started