AVCodec *codec = avcodec_find_encoder_by_name(codec_name.c_str());
if (codec == nullptr) {
fprintf(stderr, "ERROR: Could not find codec '%s'\n", codec_name.c_str());
AVCodec *codec = avcodec_find_encoder_by_name(codec_name.c_str());
if (codec == nullptr) {
fprintf(stderr, "ERROR: Could not find codec '%s'\n", codec_name.c_str());
}
if (avcodec_open2(ctx, codec, NULL) < 0) {
fprintf(stderr, "Could not open codec '%s'\n", codec_name.c_str());
}
if (avcodec_open2(ctx, codec, NULL) < 0) {
fprintf(stderr, "Could not open codec '%s'\n", codec_name.c_str());
/*log_ctx=*/nullptr);
if (resampler == nullptr) {
fprintf(stderr, "Allocating resampler failed.\n");
/*log_ctx=*/nullptr);
if (resampler == nullptr) {
fprintf(stderr, "Allocating resampler failed.\n");
}
if (swr_init(resampler) < 0) {
fprintf(stderr, "Could not open resample context.\n");
}
if (swr_init(resampler) < 0) {
fprintf(stderr, "Could not open resample context.\n");
audio_frame->channel_layout = AV_CH_LAYOUT_STEREO;
audio_frame->format = ctx->sample_fmt;
audio_frame->sample_rate = OUTPUT_FREQUENCY;
if (av_samples_alloc(audio_frame->data, nullptr, 2, num_samples, ctx->sample_fmt, 0) < 0) {
fprintf(stderr, "Could not allocate %zu samples.\n", num_samples);
audio_frame->channel_layout = AV_CH_LAYOUT_STEREO;
audio_frame->format = ctx->sample_fmt;
audio_frame->sample_rate = OUTPUT_FREQUENCY;
if (av_samples_alloc(audio_frame->data, nullptr, 2, num_samples, ctx->sample_fmt, 0) < 0) {
fprintf(stderr, "Could not allocate %zu samples.\n", num_samples);
}
if (swr_convert(resampler, audio_frame->data, num_samples, reinterpret_cast<const uint8_t **>(&audio), num_samples) < 0) {
fprintf(stderr, "Audio conversion failed.\n");
}
if (swr_convert(resampler, audio_frame->data, num_samples, reinterpret_cast<const uint8_t **>(&audio), num_samples) < 0) {
fprintf(stderr, "Audio conversion failed.\n");
}
int err = avcodec_send_frame(ctx, audio_frame);
if (err < 0) {
fprintf(stderr, "avcodec_send_frame() failed with error %d\n", err);
}
int err = avcodec_send_frame(ctx, audio_frame);
if (err < 0) {
fprintf(stderr, "avcodec_send_frame() failed with error %d\n", err);