Add global hardware acceleration codec switch

This commit is contained in:
dijunkun
2023-09-21 10:42:16 +08:00
parent a794cd43b9
commit b4318cc8d6
17 changed files with 113 additions and 85 deletions

View File

@@ -4,16 +4,9 @@
#include "log.h"
#define SAVE_ENCODER_STREAM 0
#define SAVE_ENCODER_STREAM 1
FFmpegVideoEncoder::FFmpegVideoEncoder() {
if (SAVE_ENCODER_STREAM) {
file_ = fopen("encode_stream.h264", "w+b");
if (!file_) {
LOG_WARN("Fail to open stream.h264");
}
}
}
FFmpegVideoEncoder::FFmpegVideoEncoder() {}
FFmpegVideoEncoder::~FFmpegVideoEncoder() {
if (SAVE_ENCODER_STREAM && file_) {
fflush(file_);
@@ -21,12 +14,14 @@ FFmpegVideoEncoder::~FFmpegVideoEncoder() {
file_ = nullptr;
}
av_packet_free(&packet_);
if (nv12_data_) {
free(nv12_data_);
nv12_data_ = nullptr;
}
if (packet_) {
av_packet_free(&packet_);
}
}
int FFmpegVideoEncoder::Init() {
@@ -82,6 +77,13 @@ int FFmpegVideoEncoder::Init() {
packet_ = av_packet_alloc();
if (SAVE_ENCODER_STREAM) {
file_ = fopen("encode_stream.h264", "w+b");
if (!file_) {
LOG_WARN("Fail to open stream.h264");
}
}
return 0;
}