Skip to content

Commit

Permalink
Merge pull request #499 from legerch/add-ffmpeg-debug-control
Browse files Browse the repository at this point in the history
Add ffmpeg debug control
  • Loading branch information
valbok authored Dec 4, 2024
2 parents e34d4ae + 054b97c commit 746db80
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 17 deletions.
57 changes: 40 additions & 17 deletions src/QtAVPlayer/qavdemuxer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,45 @@ class QAVDemuxerPrivate
QString bsfs;
};

static void log_callback(void *ptr, int level, const char *fmt, va_list vl)
{
/* Do we need to log ? */
if(level > av_log_get_level()){
return;
}

/* Format log line */
char line[1024];
static int print_prefix = 1;

av_log_format_line(ptr, level, fmt, vl, line, sizeof(line), &print_prefix);

/* Adapt it to Qt log format */
switch(level)
{
case AV_LOG_PANIC:{
qFatal("[ffmpeg] %s", line);
}break;

case AV_LOG_FATAL:
case AV_LOG_ERROR:{
qCritical("[ffmpeg] %s", line);
}break;

case AV_LOG_WARNING:{
qWarning("[ffmpeg] %s", line);
}break;

case AV_LOG_INFO:{
qInfo("[ffmpeg] %s", line);
}break;

default:{
qDebug("[ffmpeg] %s", line);
}break;
}
}

static int decode_interrupt_cb(void *ctx)
{
auto d = reinterpret_cast<QAVDemuxerPrivate *>(ctx);
Expand All @@ -125,6 +164,7 @@ QAVDemuxer::QAVDemuxer()
avcodec_register_all();
#endif
avdevice_register_all();
av_log_set_callback(log_callback);
loaded = true;
}
}
Expand Down Expand Up @@ -211,22 +251,6 @@ static int setup_video_codec(const QString &inputVideoCodec, AVStream *stream, Q
return 0;
}

static void log_callback(void *ptr, int level, const char *fmt, va_list vl)
{
if (level > av_log_get_level())
return;

va_list vl2;
char line[1024];
static int print_prefix = 1;

va_copy(vl2, vl);
av_log_format_line(ptr, level, fmt, vl2, line, sizeof(line), &print_prefix);
va_end(vl2);

qDebug() << "FFmpeg:" << line;
}

QStringList QAVDemuxer::supportedFormats()
{
static QStringList values;
Expand Down Expand Up @@ -369,7 +393,6 @@ int QAVDemuxer::load(const QString &url, QAVIODevice *dev)
return ret;

locker.relock();
av_log_set_callback(log_callback);

#if LIBAVUTIL_VERSION_INT < AV_VERSION_INT(59, 8, 0)
d->seekable = d->ctx->iformat->read_seek || d->ctx->iformat->read_seek2;
Expand Down
13 changes: 13 additions & 0 deletions src/QtAVPlayer/qavplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,19 @@ void QAVPlayer::setInputOptions(const QMap<QString, QString> &opts)
Q_EMIT inputOptionsChanged(opts);
}


/*!
* \brief Use to set log level of FFmpeg backend
* \param[in] level
* Level log to use. Please see:
* https://ffmpeg.org/doxygen/trunk/group__lavu__log__constants.html
* for value details
*/
void QAVPlayer::setLogsLevelBackend(int level)
{
av_log_set_level(level);
}

QAVStream::Progress QAVPlayer::progress(const QAVStream &s) const
{
return d_func()->demuxer.progress(s);
Expand Down
3 changes: 3 additions & 0 deletions src/QtAVPlayer/qavplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ public Q_SLOTS:
void audioFrame(const QAVAudioFrame &frame);
void subtitleFrame(const QAVSubtitleFrame &frame);

public:
static void setLogsLevelBackend(int level);

protected:
std::unique_ptr<QAVPlayerPrivate> d_ptr;

Expand Down

0 comments on commit 746db80

Please sign in to comment.