Files
simgear/simgear/screen/video-encoder.hxx
T
Julian Smith 5627b135b4 simgear/screen/: added support for video encoding.
Uses ffmpeg libraries to provide video encoding of an osg::GraphicsContext
(which could be for Flightgear's main window) to file.

The video codec is specified as a string at runtime. Success depends on what is
supported by the system's ffmpeg installation.

Handling of resize doesn't always work. We finish current stream and create a
new encoder and continue. Works ok with mpeg2, but with more modern codecs vlc
usually fails to handle the change.

We call the encoder on a separate thread to avoid latency.

If SG_FFMPEG is not defined, we don't make calls to ffmpeg libraries and
VideoEncoder class's constructor always throws an exception.
2021-12-08 10:31:27 +00:00

62 lines
1.8 KiB
C++

#pragma once
#include <memory>
#include <string>
#include <osg/GraphicsContext>
namespace simgear
{
/* Compressed video encoder.
Generated video contains information about frame times, and also copes with
changes to the width and/or height of the frames.
So replay will replicate variable frame rates and window resizing. */
struct VideoEncoder
{
/* Constructor; sets things up to write compressed video to file <path>.
Args:
path
Name of output file. Container type is inferred from suffix using
avformat_alloc_output_context2()). List of supported containers can
be found with 'ffmpeg -formats'.
codec_name
Name of codec, passed to avcodec_find_encoder_by_name(). List of
supported codecs can be found with 'ffmpeg -codecs'.
quality
Encoding quality in range 0..1 or -1 to use codec's default.
speed:
Encoding speed in range 0..1 or -1 to use codec's default.
bitrate
Target bitratae in bits/sec or -1 to use codex's default.
Throws exception if we cannot set up encoding, e.g. unrecognised
codec. Other configuration errors may be detected only when encode() is
called.
*/
VideoEncoder(
const std::string& path,
const std::string& codec,
double quality,
double speed,
int bitrate
);
/* Appends gc's current bitmap to compressed video. Works by scheduling a
callback with gc->add(). <dt> must be non-zero.
Throws exception if error has occurred previously - for example sometimes a
configuration doesn't fail until we start sending frames. */
void encode(double dt, osg::GraphicsContext* gc);
~VideoEncoder();
private:
osg::ref_ptr<struct VideoEncoderInternal> m_internal;
};
}