23#include <opendht/utils.h>
34#warning Debug utilities included in build
36using Clock = std::chrono::steady_clock;
37using namespace std::literals;
57 template<
class Period = std::ratio<1>>
60 auto diff = std::chrono::duration_cast<Period>(Clock::now() - start_);
65 JAMI_DBG() << name_ <<
": " <<
action <<
" after " << dht::print_duration(Clock::now() - start_);
69 std::string_view name_;
70 std::chrono::time_point<Clock> start_;
83 throw std::runtime_error(
"Failed to allocate output format context");
86 switch (
frame->format) {
110 throw std::runtime_error(
"Unsupported audio format");
115 throw std::runtime_error(
"Failed to find audio codec");
119 throw std::runtime_error(
"Failed to allocate audio codec context");
122 codec_ctx_->ch_layout =
frame->ch_layout;
123 codec_ctx_->sample_rate =
frame->sample_rate;
128 throw std::runtime_error(
"Failed to open audio codec");
132 throw std::runtime_error(
"Failed to create audio stream");
135 throw std::runtime_error(
"Failed to copy codec parameters to stream");
139 throw std::runtime_error(
"Failed to open output file for writing");
143 throw std::runtime_error(
"Failed to write header to output file");
149 JAMI_ERROR(
"Error sending a frame to the encoder");
159 pkt->stream_index = stream_->index;
162 lastPts +=
frame->nb_samples * (
int64_t)stream_->time_base.den / (stream_->time_base.num * (
int64_t)
frame->sample_rate);
165 JAMI_ERROR(
"Error while writing output packet");
198 : filename_(filename)
203 f_ =
fopen(filename.c_str(),
"wb");
207 VideoWriter(
const std::string& filename,
int format,
int width,
int height)
214 JAMI_DBG(
"Play video file with: ffplay -f rawvideo -pixel_format %s -video_size %dx%d %s",
227 if (format_ !=
f->format || width_ !=
f->width || height_ !=
f->height)
238 reinterpret_cast<const int*
>(
f->linesize),
254 std::string filename_;
Ex: Timer t; std::this_thread::sleep_for(std::chrono::milliseconds(10)); JAMI_DBG() << "Task took " <...
Timer(std::string_view name)
void print(std::string_view action) const
uint64_t getDuration() const
Minimally invasive video writer.
void write(VideoFrame &frame)
VideoWriter(const std::string &filename, int format, int width, int height)
VideoWriter(const std::string &filename, AVPixelFormat format, int width, int height)
void write(AVFrame *frame)
WavWriter(const char *filename, AVFrame *frame)
std::chrono::steady_clock Clock
#define JAMI_ERROR(formatstr,...)
#define JAMI_WARNING(formatstr,...)
void emitSignal(Args... args)
void av_packet_free(AVPacket **frame)