Skip to content

Commit 9b13343

Browse files
committed
nvm change codec again yay!!!
1 parent 530c5cd commit 9b13343

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

include/recorder.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ class FFMPEG_API_DLL Recorder {
6262
* This function iterates through all available codecs in FFmpeg and
6363
* returns a sorted vector of codec names.
6464
*
65-
* @return A map of representing the names and ids of available codecs.
65+
* @return A vector representing the names of available codecs.
6666
*/
67-
std::unordered_map<std::string, int> getAvailableCodecs();
67+
std::vector<std::string> getAvailableCodecs();
6868

6969
private:
7070
AVFormatContext* m_formatContext = nullptr;

include/render_settings.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ enum class HardwareAccelerationType : int {
311311
struct RenderSettings {
312312
HardwareAccelerationType m_hardwareAccelerationType = HardwareAccelerationType::NONE;
313313
PixelFormat m_pixelFormat = PixelFormat::RGB0;
314-
int m_codecId = 27;
314+
std::string m_codec = "h264";
315315
int64_t m_bitrate = 30000000;
316316
uint32_t m_width = 1920;
317317
uint32_t m_height = 1080;

src/recorder.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,28 @@ extern "C" {
1212

1313
namespace ffmpeg {
1414

15-
std::unordered_map<std::string, int> Recorder::getAvailableCodecs() {
16-
std::unordered_map<std::string, int> map;
15+
std::vector<std::string> Recorder::getAvailableCodecs() {
16+
std::vector<std::string> vec;
1717

1818
void* iter = nullptr;
1919
const AVCodec * codec;
2020

2121
while ((codec = av_codec_iterate(&iter))) {
22-
if(codec->type == AVMEDIA_TYPE_VIDEO)
23-
map.insert({codec->name, (int)codec->id});
22+
if(codec->type == AVMEDIA_TYPE_VIDEO && avcodec_find_encoder_by_name(codec->name) != nullptr)
23+
vec.push_back(codec->name);
2424
}
2525

26-
return map;
26+
return vec;
27+
}
28+
29+
const AVCodec* getCodecByName(const std::string& name) {
30+
void* iter = nullptr;
31+
const AVCodec * codec;
32+
while ((codec = av_codec_iterate(&iter))) {
33+
if(codec->type == AVMEDIA_TYPE_VIDEO && std::string(codec->name) == name)
34+
return codec;
35+
}
36+
return nullptr;
2737
}
2838

2939
bool Recorder::init(const RenderSettings& settings) {
@@ -33,7 +43,7 @@ bool Recorder::init(const RenderSettings& settings) {
3343
return false;
3444
}
3545

36-
m_codec = avcodec_find_encoder((AVCodecID)settings.m_codecId);
46+
m_codec = getCodecByName(settings.m_codec);
3747
if (!m_codec) {
3848
geode::log::error("Could not find encoder.");
3949
return false;
@@ -77,11 +87,11 @@ bool Recorder::init(const RenderSettings& settings) {
7787
}
7888

7989
if(m_codecContext->pix_fmt == AV_PIX_FMT_NONE) {
80-
geode::log::info("Codec {} does not support pixel format, defaulting to codec's format", settings.m_codecId);
90+
geode::log::info("Codec {} does not support pixel format, defaulting to codec's format", settings.m_codec);
8191
m_codecContext->pix_fmt = m_codec->pix_fmts[0];
8292
}
8393
else
84-
geode::log::info("Codec {} supports pixel format.", settings.m_codecId);
94+
geode::log::info("Codec {} supports pixel format.", settings.m_codec);
8595

8696
if (avcodec_open2(m_codecContext, m_codec, NULL) < 0) {
8797
geode::log::error("Could not open codec.");

0 commit comments

Comments
 (0)