On 8/25/2022 12:16 PM, Reynolds Kosloskey wrote:
Hello all.
I am working on a capture/encoder project. I've gotten it to work
well enough, for the most part.
If I record shorter segments, like in the 1-2 minute range, the output
files are fine.
However, as the clip gets longer, it eventually starts hitting an I/O
Error (-5) when executing *av_interleaved_write_frame(format_context,
output_packet). *It never recovers from this, all writing to the file
stops, and attempting to close the file results in an unplayable file.
This is the part of the code that writes audio frames, and also where
the error is detected:
int Recorder::audioWriteFrame(void* ctx, AVFrame* frame) {
if (!decoding) return -1;
if (recording) {
frames_all++;
frames_audio++;
AVPacket* output_packet = av_packet_alloc();
int ret = avcodec_send_frame(audio_context, frame);
while (ret >= 0)
{
ret = avcodec_receive_packet(audio_context, output_packet);
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
break;
}
else if (ret < 0) {
cout << "AUD-AVCRPX: ";
cout << ret;
break;
}
chrono::steady_clock::time_point now =
chrono::high_resolution_clock::now();
long long ms_elapsed =
chrono::duration_cast<chrono::microseconds>(now - rec_started).count();
ms_elapsed = av_rescale_q(ms_elapsed,
audio_context->time_base, audio_stream->time_base);
output_packet->pts = ms_elapsed;
output_packet->dts = ms_elapsed;
output_packet->stream_index = audio_stream->index;
* ret = av_interleaved_write_frame(format_context,
output_packet); **
** if (ret < 0) {**
** char* errmsg = new char[4096];**
** av_strerror(ret, errmsg, 4096);**
** cout << "audio av_interleaved_write_frame ERROR: ";**
** cout << errmsg;**
** cout << "\r\n";**
** }**
** ret = ret;*
}
av_packet_unref(output_packet);
av_packet_free(&output_packet);
}
return 0;
}
Any ideas why this is happening would be helpful.
--Reynolds
If anyone else comes across this error, one thing to look at would be
the size of the buffers you're using. In my case, I had an audio
decoding thread that I passed a buffer to *avio_alloc_context*.
Increasing that buffer size seems to have gotten rid of the issue.
_______________________________________________
Libav-user mailing list
[email protected]
https://ffmpeg.org/mailman/listinfo/libav-user
To unsubscribe, visit link above, or email
[email protected] with subject "unsubscribe".