Skip to content

Commit b33312c

Browse files
committed
change getAvailableCodecs
1 parent ac3b563 commit b33312c

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

include/recorder.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ class FFMPEG_API_DLL Recorder {
6161
* This function iterates through all available codecs in FFmpeg and
6262
* returns a sorted vector of codec names.
6363
*
64-
* @return A vector of strings representing the names of available codecs.
64+
* @return A vector of pairs representing the ids and names of available codecs.
6565
*/
66-
std::vector<std::string> getAvailableCodecs();
66+
std::vector<std::pair<int, std::string>> getAvailableCodecs();
6767

6868
private:
6969
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-
std::string m_codec = "libx264";
314+
int m_codecId = 27;
315315
int64_t m_bitrate = 30000000;
316316
uint32_t m_width = 1920;
317317
uint32_t m_height = 1080;

src/recorder.cpp

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

1313
namespace ffmpeg {
1414

15-
std::vector<std::string> Recorder::getAvailableCodecs() {
16-
std::vector<std::string> vet;
15+
std::vector<std::pair<int, std::string>> Recorder::getAvailableCodecs() {
16+
std::vector<std::pair<int, std::string>> vet;
1717

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

21-
while ((codec = av_codec_iterate(&iter)))
22-
vet.push_back(codec->name);
21+
while ((codec = av_codec_iterate(&iter))) {
22+
if(codec->type == AVMEDIA_TYPE_VIDEO)
23+
vet.push_back({(int)codec->id, codec->name});
24+
}
2325

24-
std::sort(vet.begin(), vet.end());
26+
std::sort(vet.begin(), vet.end(), [](std::pair<int, std::string>& a, std::pair<int, std::string>& b) { return a.second < b.second; });
2527

2628
return vet;
2729
}
@@ -33,7 +35,7 @@ bool Recorder::init(const RenderSettings& settings) {
3335
return false;
3436
}
3537

36-
m_codec = avcodec_find_encoder_by_name(settings.m_codec.c_str());
38+
m_codec = avcodec_find_encoder((AVCodecID)settings.m_codecId);
3739
if (!m_codec) {
3840
geode::log::error("Could not find encoder.");
3941
return false;
@@ -77,11 +79,11 @@ bool Recorder::init(const RenderSettings& settings) {
7779
}
7880

7981
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_codec);
82+
geode::log::info("Codec {} does not support pixel format, defaulting to codec's format", settings.m_codecId);
8183
m_codecContext->pix_fmt = m_codec->pix_fmts[0];
8284
}
8385
else
84-
geode::log::info("Codec {} supports pixel format.", settings.m_codec);
86+
geode::log::info("Codec {} supports pixel format.", settings.m_codecId);
8587

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

0 commit comments

Comments
 (0)