FindFFmpeg works on Windows
The application links with ffmpeg dll and needs a copy of it to works in the output binary location.
This commit is contained in:
65
ffmini.cpp
65
ffmini.cpp
@@ -1,7 +1,70 @@
|
||||
#include "fmt/format.h"
|
||||
#include "miniaudio.h"
|
||||
|
||||
extern "C" {
|
||||
#include "libavcodec/avcodec.h"
|
||||
#include "libavformat/avformat.h"
|
||||
#include "libavcodec/avcodec.h"
|
||||
}
|
||||
|
||||
auto callback([[maybe_unused]]ma_device* device, [[maybe_unused]]void* output, [[maybe_unused]]void const* input, [[maybe_unused]]ma_uint32 frame_count) -> void {
|
||||
}
|
||||
|
||||
auto main([[maybe_unused]]int argc, [[maybe_unused]]char const* argv[]) -> int {
|
||||
fmt::print("Hello, World!\n");
|
||||
AVFormatContext* format_context = avformat_alloc_context();
|
||||
if (!format_context) {
|
||||
fmt::print(stderr, "Failed to create AVFormatContext\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto const filename = "C:/Users/miku/Downloads/Porter Robinson - Trying to Feel Alive (Official Audio).webm";
|
||||
if (avformat_open_input(&format_context, filename, nullptr, nullptr) != 0) {
|
||||
fmt::print(stderr, "Failed to open file {}\n", filename);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (avformat_find_stream_info(format_context, nullptr) < 0) {
|
||||
fmt::print(stderr, "Error loading stream info\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::int64_t stream_index = -1;
|
||||
AVCodec const* codec = nullptr;
|
||||
for (std::uint32_t i = 0; i < format_context->nb_streams; ++i) {
|
||||
auto* params = format_context->streams[i]->codecpar;
|
||||
codec = avcodec_find_decoder(params->codec_id);
|
||||
if (!codec) continue;
|
||||
if (params->codec_type == AVMEDIA_TYPE_AUDIO) {
|
||||
stream_index = static_cast<std::int64_t>(i);
|
||||
}
|
||||
}
|
||||
|
||||
if (stream_index == -1) {
|
||||
fmt::print(stderr, "Couldn't find valid audio track inside file: {}\n", filename);
|
||||
return 1;
|
||||
}
|
||||
|
||||
ma_device device;
|
||||
auto device_config = ma_device_config_init(ma_device_type_playback);
|
||||
device_config.playback.format = ma_format_f32;
|
||||
device_config.playback.channels = 2;
|
||||
device_config.sampleRate = 48000;
|
||||
device_config.dataCallback = callback;
|
||||
device_config.pUserData = nullptr;
|
||||
|
||||
if (ma_device_init(nullptr, &device_config, &device) != MA_SUCCESS) {
|
||||
fmt::print(stderr, "Failed to open playback device\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (ma_device_start(&device) != MA_SUCCESS) {
|
||||
fmt::print(stderr, "Failed to start playback device.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
ma_device_uninit(&device);
|
||||
avformat_close_input(&format_context);
|
||||
avformat_free_context(format_context);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user