8#include "QtCore/qloggingcategory.h"
14static Q_LOGGING_CATEGORY(qLcEncodingFormatContext,
"qt.multimedia.ffmpeg.encodingformatcontext");
19constexpr size_t DefaultBufferSize = 4096;
23 : m_avFormatContext(avformat_alloc_context())
26 m_avFormatContext->oformat =
const_cast<AVOutputFormat *
>(avFormat);
33 avformat_free_context(m_avFormatContext);
43 std::unique_ptr<char,
decltype(&av_free)>
url(
44 reinterpret_cast<char *
>(av_malloc(filePathUtf8.size() + 1)), &av_free);
45 memcpy(
url.get(), filePathUtf8.constData(), filePathUtf8.size() + 1);
48 auto result = avio_open2(&m_avFormatContext->pb,
url.get(), AVIO_FLAG_WRITE,
nullptr,
nullptr);
50 qCDebug(qLcEncodingFormatContext)
51 <<
"opened by file path:" <<
url.get() <<
", result:" <<
result;
53 Q_ASSERT(m_avFormatContext->url ==
nullptr);
55 m_avFormatContext->url =
url.release();
57 openAVIOWithQFile(filePath);
60void EncodingFormatContext::openAVIOWithQFile(
const QString &filePath)
67 auto file = std::make_unique<QFile>(filePath);
70 qCDebug(qLcEncodingFormatContext) <<
"Cannot open QFile" << filePath;
77 m_outputFile = std::move(
file);
88 auto buffer =
static_cast<uint8_t *
>(av_malloc(DefaultBufferSize));
89 m_avFormatContext->pb = avio_alloc_context(
buffer, DefaultBufferSize, 1,
device,
nullptr,
97 if (m_avFormatContext->url && *m_avFormatContext->url !=
'\0') {
98 auto closeResult = avio_closep(&m_avFormatContext->pb);
101 av_free(std::exchange(m_avFormatContext->pb->buffer,
nullptr));
102 avio_context_free(&m_avFormatContext->pb);
107 av_freep(&m_avFormatContext->url);
108 m_outputFile.reset();
IOBluetoothDevice * device
void openAVIO(const QString &filePath)
EncodingFormatContext(QMediaFormat::FileFormat fileFormat)
QFILE_MAYBE_NODISCARD bool open(OpenMode flags) override
Opens the file using OpenMode mode, returning true if successful; otherwise false.
\inmodule QtCore \reentrant
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
QByteArray toUtf8() const &
int writeQIODevice(void *opaque, AvioWriteBufferType buf, int buf_size)
int64_t seekQIODevice(void *opaque, int64_t offset, int whence)
Combined button and popup list for selecting options.
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
QUrl url("example.com")
[constructor-url-reference]