10#include "gifencoder_p.h"
12#include "pipewireproduce_p.h"
18#include <libavcodec/avcodec.h>
19#include <libavfilter/buffersink.h>
20#include <libavfilter/buffersrc.h>
21#include <libavutil/pixfmt.h>
24#include "logging_record.h"
26using namespace Qt::StringLiterals;
28GifEncoder::GifEncoder(PipeWireProduce *produce)
29 : SoftwareEncoder(produce)
33bool GifEncoder::initialize(
const QSize &size)
35 m_filterGraphToParse = u
"split[v1][v2];[v1]palettegen=stats_mode=single[palette];[v2][palette]paletteuse=new=1:dither=sierra2_4a"_s;
36 createFilterGraph(size);
38 auto codec = avcodec_find_encoder_by_name(
"gif");
40 qCWarning(PIPEWIRERECORD_LOGGING) <<
"gif codec not found";
44 m_avCodecContext = avcodec_alloc_context3(codec);
45 if (!m_avCodecContext) {
46 qCWarning(PIPEWIRERECORD_LOGGING) <<
"Could not allocate video codec context";
51 m_avCodecContext->width = size.
width();
52 m_avCodecContext->height = size.
height();
53 m_avCodecContext->pix_fmt = AV_PIX_FMT_PAL8;
54 m_avCodecContext->time_base = AVRational{1, 1000};
56 AVDictionary *options =
nullptr;
58 applyEncodingPreference(options);
60 if (
int result = avcodec_open2(m_avCodecContext, codec, &options); result < 0) {
61 qCWarning(PIPEWIRERECORD_LOGGING) <<
"Could not open codec" << av_err2str(result);
68std::pair<int, int> GifEncoder::encodeFrame(
int maximumFrames)
70 auto level = av_log_get_level();
72 av_log_set_level(AV_LOG_ERROR);
73 auto ret = SoftwareEncoder::encodeFrame(maximumFrames);
74 av_log_set_level(level);
78int GifEncoder::percentageToAbsoluteQuality([[maybe_unused]]
const std::optional<quint8> &quality)
83void GifEncoder::applyEncodingPreference([[maybe_unused]] AVDictionary *options)
QStringView level(QStringView ifopt)
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:05:20 by
doxygen 1.12.0 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.