simgear/screen/video-encoder*: support for logging timing info for sws_scale().

This commit is contained in:
Julian Smith
2022-05-01 15:18:58 +01:00
parent 8037a0eb20
commit ac37f734ba
3 changed files with 28 additions and 7 deletions
+17 -2
View File
@@ -4,6 +4,7 @@
#ifndef SG_VIDEO_ENCODER_STANDALONE #ifndef SG_VIDEO_ENCODER_STANDALONE
#include <simgear/debug/logstream.hxx> #include <simgear/debug/logstream.hxx>
#include <simgear/timing/rawprofile.hxx>
#endif #endif
extern "C" extern "C"
@@ -72,6 +73,7 @@ static const char* select(const char** names, int names_num, double select)
return names[i]; return names[i];
} }
/* Video encoder which uses ffmpeg libraries. */ /* Video encoder which uses ffmpeg libraries. */
struct FfmpegEncoder struct FfmpegEncoder
{ {
@@ -94,6 +96,7 @@ struct FfmpegEncoder
double m_t = 0; double m_t = 0;
int64_t m_t_int_prev = 0; int64_t m_t_int_prev = 0;
bool m_have_written_header = false; bool m_have_written_header = false;
bool m_log_sws_scale_stats;
/* Constructor. /* Constructor.
@@ -111,6 +114,9 @@ struct FfmpegEncoder
Encoding speed in range 0..1 or -1 to use codec's default. Encoding speed in range 0..1 or -1 to use codec's default.
bitrate bitrate
Target bitratae in bits/sec or -1 to use codex's default. Target bitratae in bits/sec or -1 to use codex's default.
log_sws_scale_stats
If true we write summary timing stats for our calls of sws_scale()
to SG_LOG().
Throws exception if we cannot set up encoding, e.g. unrecognised Throws exception if we cannot set up encoding, e.g. unrecognised
codec. Other configuration errors may be detected only when encode() is codec. Other configuration errors may be detected only when encode() is
@@ -121,7 +127,8 @@ struct FfmpegEncoder
const std::string& codec_name, const std::string& codec_name,
double quality, double quality,
double speed, double speed,
int bitrate int bitrate,
bool log_sws_scale_stats=false
) )
{ {
assert(quality == -1 || (quality >= 0 && quality <= 1)); assert(quality == -1 || (quality >= 0 && quality <= 1));
@@ -134,6 +141,8 @@ struct FfmpegEncoder
m_speed = speed; m_speed = speed;
m_bitrate = bitrate; m_bitrate = bitrate;
m_log_sws_scale_stats = log_sws_scale_stats;
try try
{ {
m_codec = avcodec_find_encoder_by_name(codec_name.c_str()); m_codec = avcodec_find_encoder_by_name(codec_name.c_str());
@@ -435,11 +444,14 @@ struct FfmpegEncoder
We also need to flip the image vertically so set m_input_linesize[0] to We also need to flip the image vertically so set m_input_linesize[0] to
-ve and make m_input_data[0] point to the last line in input_raw. */ -ve and make m_input_data[0] point to the last line in input_raw. */
#ifndef SG_VIDEO_ENCODER_STANDALONE
static RawProfile raw_profile(1, "sws_scale() time: ");
if (m_log_sws_scale_stats) raw_profile.start();
#endif
int stride2 = -stride; int stride2 = -stride;
const uint8_t* input_raw2 = (const uint8_t*) input_raw + stride * (height-1); const uint8_t* input_raw2 = (const uint8_t*) input_raw + stride * (height-1);
sws_scale( sws_scale(
m_sws_context, m_sws_context,
//(const uint8_t * const *)
&input_raw2, &input_raw2,
&stride2, &stride2,
0 /*srcSliceY*/, 0 /*srcSliceY*/,
@@ -447,6 +459,9 @@ struct FfmpegEncoder
m_frame_yuv->data, m_frame_yuv->data,
m_frame_yuv->linesize m_frame_yuv->linesize
); );
#ifndef SG_VIDEO_ENCODER_STANDALONE
if (m_log_sws_scale_stats) raw_profile.stop();
#endif
/* Send m_frame_yuv to encoder. */ /* Send m_frame_yuv to encoder. */
m_t += dt; m_t += dt;
+6 -4
View File
@@ -41,12 +41,13 @@ struct VideoEncoderInternal : osg::GraphicsOperation
const std::string& codec, const std::string& codec,
double quality, double quality,
double speed, double speed,
int bitrate int bitrate,
bool log_sws_scale_stats
) )
: :
osg::GraphicsOperation("VideoEncoderOperation", false /*keep*/), osg::GraphicsOperation("VideoEncoderOperation", false /*keep*/),
m_image(new osg::Image), m_image(new osg::Image),
m_ffmpeg_encoder(path, codec, quality, speed, bitrate), m_ffmpeg_encoder(path, codec, quality, speed, bitrate, log_sws_scale_stats),
m_thread( m_thread(
[this] [this]
{ {
@@ -180,11 +181,12 @@ VideoEncoder::VideoEncoder(
const std::string& codec, const std::string& codec,
double quality, double quality,
double speed, double speed,
int bitrate int bitrate,
bool log_sws_scale_stats
) )
{ {
av_log_set_callback(av_log); av_log_set_callback(av_log);
m_internal = new VideoEncoderInternal(path, codec, quality, speed, bitrate); m_internal = new VideoEncoderInternal(path, codec, quality, speed, bitrate, log_sws_scale_stats);
} }
VideoEncoder::~VideoEncoder() VideoEncoder::~VideoEncoder()
+5 -1
View File
@@ -34,6 +34,9 @@ struct VideoEncoder
Encoding speed in range 0..1 or -1 to use codec's default. Encoding speed in range 0..1 or -1 to use codec's default.
bitrate bitrate
Target bitratae in bits/sec or -1 to use codex's default. Target bitratae in bits/sec or -1 to use codex's default.
log_sws_scale_stats
If true we write summary timing stats for our calls of sws_scale()
to SG_LOG().
Throws exception if we cannot set up encoding, e.g. unrecognised Throws exception if we cannot set up encoding, e.g. unrecognised
codec. Other configuration errors may be detected only when encode() is codec. Other configuration errors may be detected only when encode() is
@@ -44,7 +47,8 @@ struct VideoEncoder
const std::string& codec, const std::string& codec,
double quality, double quality,
double speed, double speed,
int bitrate int bitrate,
bool log_sws_scale_stats=false
); );
/* Appends gc's current bitmap to compressed video. Works by scheduling a /* Appends gc's current bitmap to compressed video. Works by scheduling a