H.264 video encoder: wraps TinyH264Encoder (https://github.com/pschatzmann/TinyH264). Configure via setSize()/ setQp() (or setTargetBitrate() for rate control) same as TinyH264Encoder and setVideoFormat() for the raw picture format write() expects (I420 - planar Y/U/V concatenated in one buffer - by default), then feed raw pictures via write() - the resulting Annex-B bitstream is written to the Print target configured via setOutput() (e.g. a Muxer's addVideoFrame() by way of an adapter, or any other Print) instead of a caller-supplied buffer.
More...
#include <CodecH264.h>
|
| template<typename Fn > |
| size_t | writeOut (Fn encodeInto) |
| |
H.264 video encoder: wraps TinyH264Encoder (https://github.com/pschatzmann/TinyH264). Configure via setSize()/ setQp() (or setTargetBitrate() for rate control) same as TinyH264Encoder and setVideoFormat() for the raw picture format write() expects (I420 - planar Y/U/V concatenated in one buffer - by default), then feed raw pictures via write() - the resulting Annex-B bitstream is written to the Print target configured via setOutput() (e.g. a Muxer's addVideoFrame() by way of an adapter, or any other Print) instead of a caller-supplied buffer.
The internal bitstream scratch buffer starts at kDefaultBitstreamBufferSize and grows (doubling, up to a few attempts) whenever an encode call comes back short - the same "call again with a
bigger buffer" recovery TinyH264Encoder's own encodeFrame() family documents, done automatically so callers don't need to size it by hand. Use setBitstreamBufferSize() to pre-size it (e.g. to avoid the first frame paying for a grow-and-retry).
- Author
- Phil Schatzmann
- Copyright
- GPLv3
◆ H264Encoder() [1/3]
| H264Encoder |
( |
int |
width = 0, |
|
|
int |
height = 0, |
|
|
int |
keyframeInterval = 0 |
|
) |
| |
|
inline |
◆ H264Encoder() [2/3]
◆ H264Encoder() [3/3]
◆ begin() [1/2]
See TinyH264Encoder::begin() - equivalent to begin(reserveColorConversionScratch=false); see that overload if you need to pass true.
Implements VideoEncoder.
◆ begin() [2/2]
| bool begin |
( |
bool |
reserveColorConversionScratch | ) |
|
|
inline |
See TinyH264Encoder::begin()
◆ driver()
| tinyh264::TinyH264Encoder< tinyh264::PSRAMAllocatorESP32< uint8_t > > & driver |
( |
| ) |
|
|
inline |
Direct access to the wrapped TinyH264Encoder, e.g. for its width()/height()/y()/u()/v() reconstructed-picture accessors.
◆ end()
◆ lastQp()
The QP actually used by the most recent write() call.
◆ setBitstreamBufferSize()
| void setBitstreamBufferSize |
( |
size_t |
size | ) |
|
|
inline |
Pre-sizes the internal bitstream scratch buffer encodeFrame() and its color-format siblings encode into before writing the result to setOutput() - call before the first encode call to avoid paying for the automatic grow-and-retry on it (see class comment). Shrinks are ignored (the buffer never releases memory on its own).
◆ setKeyframeInterval()
| void setKeyframeInterval |
( |
int |
frames | ) |
|
|
inline |
See TinyH264Encoder::setKeyframeInterval()
◆ setOutput() [1/2]
| void setOutput |
( |
Print & |
out | ) |
|
|
inlineoverridevirtual |
Defines the target the encoded bitstream is written to, one write() call per write() call that actually produced output.
Implements VideoEncoder.
◆ setOutput() [2/2]
◆ setPackedStride()
| void setPackedStride |
( |
int |
stride | ) |
|
|
inline |
See TinyH264Encoder::setPackedStride()
◆ setQp()
See TinyH264Encoder::setQp()
◆ setSize()
| void setSize |
( |
int |
width, |
|
|
int |
height |
|
) |
| |
|
inline |
See TinyH264Encoder::setSize()
◆ setStride()
| void setStride |
( |
int |
strideY, |
|
|
int |
strideC |
|
) |
| |
|
inline |
See TinyH264Encoder::setStride()
◆ setTargetBitrate()
| void setTargetBitrate |
( |
int |
bitsPerSecond, |
|
|
double |
fps |
|
) |
| |
|
inline |
See TinyH264Encoder::setTargetBitrate()
◆ setVideoFormat()
Selects the raw picture format write() expects - VideoFormat::I420 (the default: planar Y/U/V, concatenated Y then U then V in one buffer, split via setSize()'s width/height), YUV422 (packed YUYV), RGB565/RGB666/RGB888 (packed) - see TinyH264Encoder's own encodeFrame()-family doc comments (h264_encoder.h) for exactly what each byte layout is. Any other VideoFormat is logged and ignored (previous format kept).
Implements VideoEncoder.
◆ videoInfo()
◆ write()
| size_t write |
( |
const uint8_t * |
data, |
|
|
size_t |
len |
|
) |
| |
|
inlineoverridevirtual |
Encodes one raw picture, in setVideoFormat()'s format (I420 by default), sized for setSize()'s width/height, and writes the resulting Annex-B bitstream to setOutput() - returns the number of bytes written (0 if nothing was, e.g. setSize()/setOutput() was never called, or len doesn't match the configured format/size). len is only used to validate the I420 case (the other formats are packed buffers TinyH264Encoder itself size-checks internally); see TinyH264Encoder's own encodeFrame()-family doc comments (h264_encoder.h) for exactly what each byte layout/size is.
Implements VideoEncoder.
◆ writeOut()
template<typename Fn >
| size_t writeOut |
( |
Fn |
encodeInto | ) |
|
|
inlineprotected |
◆ bitstream
◆ encoder_
| tinyh264::TinyH264Encoder< tinyh264::PSRAMAllocatorESP32<uint8_t> > encoder_ |
|
protected |
◆ height_
◆ input_format
◆ kDefaultBitstreamBufferSize
| constexpr size_t kDefaultBitstreamBufferSize = 16384 |
|
staticconstexpr |
◆ kMaxGrowRetries
| constexpr int kMaxGrowRetries = 4 |
|
staticconstexprprotected |
Number of times to double the bitstream buffer and retry an undersized encode call before giving up (see class comment).
◆ p_out
◆ p_out_video
◆ width_
The documentation for this class was generated from the following file: