Files
crossdesk/tests/opus/main.cpp
2023-11-21 22:30:25 -08:00

31 lines
644 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <fstream>
#include <iostream>
#include <vector>
#include "OpusEncoderImpl.h"
#include "opus/opus.h"
int main() {
OpusEncoderImpl* opusEncoder = new OpusEncoderImpl(48000, 2);
std::ifstream inputFile("ls.pcm", std::ios::binary);
if (!inputFile) {
std::cerr << "Failed to open input file." << std::endl;
return -1;
}
char sample[960];
while (inputFile.read(sample, 960)) {
opusEncoder->Feed((unsigned char*)sample, 960);
}
// // 读取编码后的opus一般放在单独线程这里只是为了方便
// StreamInfo info;
// while (opusEncoder.PopFrame(info)) {
// .....
// }
opusEncoder->Stop();
return 0;
}