浏览代码

obs-ffmpeg/ffmpeg-mux: Add ability to get FFmpeg logging

Maya Venkatraman 5 年之前
父节点
当前提交
f7a468dd30
共有 1 个文件被更改,包括 35 次插入0 次删除
  1. 35 0
      plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c

+ 35 - 0
plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c

@@ -28,6 +28,10 @@
 
 
 #include <libavformat/avformat.h>
 #include <libavformat/avformat.h>
 
 
+#define ANSI_COLOR_RED "\x1b[0;91m"
+#define ANSI_COLOR_MAGENTA "\x1b[0;95m"
+#define ANSI_COLOR_RESET "\x1b[0m"
+
 #if LIBAVCODEC_VERSION_MAJOR >= 58
 #if LIBAVCODEC_VERSION_MAJOR >= 58
 #define CODEC_FLAG_GLOBAL_H AV_CODEC_FLAG_GLOBAL_HEADER
 #define CODEC_FLAG_GLOBAL_H AV_CODEC_FLAG_GLOBAL_HEADER
 #else
 #else
@@ -217,6 +221,33 @@ static bool get_audio_params(struct audio_params *audio, int *argc,
 	return true;
 	return true;
 }
 }
 
 
+static void ffmpeg_log_callback(void *param, int level, const char *format,
+				va_list args)
+{
+	char out_buffer[4096];
+	vsnprintf(out_buffer, sizeof(out_buffer), format, args);
+
+	switch (level) {
+	case AV_LOG_INFO:
+		fprintf(stdout, "info: [ffmpeg_muxer] %s", out_buffer);
+		fflush(stdout);
+		break;
+
+	case AV_LOG_WARNING:
+		fprintf(stdout, "%swarning: [ffmpeg_muxer] %s%s",
+			ANSI_COLOR_MAGENTA, out_buffer, ANSI_COLOR_RESET);
+		fflush(stdout);
+		break;
+
+	case AV_LOG_ERROR:
+		fprintf(stderr, "%serror: [ffmpeg_muxer] %s%s", ANSI_COLOR_RED,
+			out_buffer, ANSI_COLOR_RESET);
+		fflush(stderr);
+	}
+
+	UNUSED_PARAMETER(param);
+}
+
 static bool init_params(int *argc, char ***argv, struct main_params *params,
 static bool init_params(int *argc, char ***argv, struct main_params *params,
 			struct audio_params **p_audio)
 			struct audio_params **p_audio)
 {
 {
@@ -286,6 +317,10 @@ static bool init_params(int *argc, char ***argv, struct main_params *params,
 
 
 	*p_audio = audio;
 	*p_audio = audio;
 
 
+#ifdef DEBUG_FFMPEG
+	av_log_set_callback(ffmpeg_log_callback);
+#endif
+
 	get_opt_str(argc, argv, &params->muxer_settings, "muxer settings");
 	get_opt_str(argc, argv, &params->muxer_settings, "muxer settings");
 
 
 	return true;
 	return true;