使用 FFmpeg.AutoGen 讀取攝像頭,將圖片顯示在控制元件上,并保存影像到檔案中,一開始讀取正常,聲音、影像都能保存,但是讀取幾分鐘后,程式在使用 av_read_frame 時,會讀取不到資料,錯誤碼 -5,攝像頭也自動關閉了。直接使用 ffmpeg.exe 去讀取攝像頭,保存檔案的時候,幾個小時都不會有問題。讀取的邏輯使用就是雷神的。請問這種回傳 -5 錯誤碼的情況是怎么出現的,應該怎么處理?
邏輯代碼如下:
while (1)
{
if ((ret = ffmpeg.av_read_frame(m_pVidFmtCtx, dec_pkt)) == 0)
{
ret = ffmpeg.avcodec_send_packet(m_pVidFmtCtx->streams[dec_pkt->stream_index]->codec, dec_pkt);
while(ret >= 0)
{
ret = ffmpeg.avcodec_receive_frame(m_pVidFmtCtx->streams[dec_pkt->stream_index]->codec, pframe);
ffmpeg.sws_scale(img_rgb_ctx, pframe->data, pframe->linesize, 0, cy, dstData, dstLinesize);
var bitmap = new Bitmap(dstWidth, dstHeight, dstLinesize[0], PixelFormat.Format24bppRgb, convertedFrameBufferPtr);
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/48139.html
標籤:C#
