Internal bug, should not have happened 在同时编码与解码的时候 #34

Closed
opened 2025-12-23 10:31:18 +01:00 by backuprepo · 3 comments
Owner

Originally created by @Coloryr on GitHub (Mar 25, 2024).

System.ApplicationException: Internal bug, should not have happened
   at IPHost.Desktop.FFmpegHelper.ThrowExceptionIfError(Int32 error) in E:\code\IPHost\IPHost.Desktop\FFmpegHelper.cs:line 76
   at IPHost.Desktop.VideoDecoder.<.ctor>b__28_0() in E:\code\IPHost\IPHost.Desktop\VideoDecoder.cs:line 192
Aborted
if (packs.TryDequeue(out var packet))
{
    var data = (byte*)ffmpeg.av_malloc((ulong)packet.Size);
    Marshal.Copy(packet.Data, 0, (IntPtr)data, packet.Size);

    ffmpeg.av_packet_from_data(_pPacket, data, packet.Size)
        .ThrowExceptionIfError();

    ffmpeg.avcodec_send_packet(_videoCodecContext, _pPacket)
        .ThrowExceptionIfError();

    //ffmpeg.av_packet_unref(_pPacket);
    ffmpeg.av_free(data);

    error = ffmpeg.avcodec_receive_frame(_videoCodecContext, _videoFrame);
    if (error == 0)
    {
        AVFrame frame = *_videoFrame;

        if (_videoCodecContext->hw_device_ctx != null)
        {
            ffmpeg.av_hwframe_transfer_data(_receivedFrame, _videoFrame, 0)
                .ThrowExceptionIfError();
            frame = *_receivedFrame;
            if (first_frame)
            {
                first_frame = false;
            }
        }

        if (vfc == null)
        {
            var sourceSize = FrameSize;
            var sourcePixelFormat = HWDeviceType == AVHWDeviceType.AV_HWDEVICE_TYPE_NONE
            ? _videoCodecContext->pix_fmt
                     : DecodeHelper.GetHWPixelFormat(HWDeviceType);
            var destinationSize = sourceSize;
            var destinationPixelFormat = AVPixelFormat.AV_PIX_FMT_BGRA;
            vfc = new VideoFrameConverter(sourceSize, sourcePixelFormat, destinationSize, destinationPixelFormat);
        }

        var convertedFrame = vfc.Convert(frame);
        IPHostApi.SetVideoPtr(_uuid, convertedFrame.width, convertedFrame.height, (IntPtr)convertedFrame.data[0]);

        start_time = ffmpeg.av_gettime() - ffmpeg.av_rescale_q(_videoFrame->pts, TimeBase, ffmpeg.av_make_q(1, ffmpeg.AV_TIME_BASE));
    }
    else if (error != -11)
    {
        error.ThrowExceptionIfError();
    }
}
else
{
    Thread.Sleep(1);
}
Originally created by @Coloryr on GitHub (Mar 25, 2024). ``` System.ApplicationException: Internal bug, should not have happened at IPHost.Desktop.FFmpegHelper.ThrowExceptionIfError(Int32 error) in E:\code\IPHost\IPHost.Desktop\FFmpegHelper.cs:line 76 at IPHost.Desktop.VideoDecoder.<.ctor>b__28_0() in E:\code\IPHost\IPHost.Desktop\VideoDecoder.cs:line 192 Aborted ``` ``` if (packs.TryDequeue(out var packet)) { var data = (byte*)ffmpeg.av_malloc((ulong)packet.Size); Marshal.Copy(packet.Data, 0, (IntPtr)data, packet.Size); ffmpeg.av_packet_from_data(_pPacket, data, packet.Size) .ThrowExceptionIfError(); ffmpeg.avcodec_send_packet(_videoCodecContext, _pPacket) .ThrowExceptionIfError(); //ffmpeg.av_packet_unref(_pPacket); ffmpeg.av_free(data); error = ffmpeg.avcodec_receive_frame(_videoCodecContext, _videoFrame); if (error == 0) { AVFrame frame = *_videoFrame; if (_videoCodecContext->hw_device_ctx != null) { ffmpeg.av_hwframe_transfer_data(_receivedFrame, _videoFrame, 0) .ThrowExceptionIfError(); frame = *_receivedFrame; if (first_frame) { first_frame = false; } } if (vfc == null) { var sourceSize = FrameSize; var sourcePixelFormat = HWDeviceType == AVHWDeviceType.AV_HWDEVICE_TYPE_NONE ? _videoCodecContext->pix_fmt : DecodeHelper.GetHWPixelFormat(HWDeviceType); var destinationSize = sourceSize; var destinationPixelFormat = AVPixelFormat.AV_PIX_FMT_BGRA; vfc = new VideoFrameConverter(sourceSize, sourcePixelFormat, destinationSize, destinationPixelFormat); } var convertedFrame = vfc.Convert(frame); IPHostApi.SetVideoPtr(_uuid, convertedFrame.width, convertedFrame.height, (IntPtr)convertedFrame.data[0]); start_time = ffmpeg.av_gettime() - ffmpeg.av_rescale_q(_videoFrame->pts, TimeBase, ffmpeg.av_make_q(1, ffmpeg.AV_TIME_BASE)); } else if (error != -11) { error.ThrowExceptionIfError(); } } else { Thread.Sleep(1); } ```
backuprepo 2025-12-23 10:31:18 +01:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@Coloryr commented on GitHub (Mar 25, 2024):

如果只是单一编码或者解码没这个问题,而且这个问题是概率发生
问题发生在avcodec_receive_frame

@Coloryr commented on GitHub (Mar 25, 2024): 如果只是单一编码或者解码没这个问题,而且这个问题是概率发生 问题发生在`avcodec_receive_frame`
Author
Owner

@nyanmisaka commented on GitHub (Mar 25, 2024):

Not reproducible via FFmpeg CLI transcoding. More information is needed to locate which line in FFmpeg is throwing this error AVERROR_BUG. There's indeed one in rkmppdec.c but it is used as an assertion.

@nyanmisaka commented on GitHub (Mar 25, 2024): Not reproducible via FFmpeg CLI transcoding. More information is needed to locate which line in FFmpeg is throwing this error `AVERROR_BUG`. There's [indeed one](https://github.com/nyanmisaka/ffmpeg-rockchip/blob/1fa586ac7fa224bde0100def5e5f3406f6c2e663/libavcodec/rkmppdec.c#L797C23-L797C34) in `rkmppdec.c` but it is used as an assertion.
Author
Owner

@nyanmisaka commented on GitHub (Apr 24, 2024):

The problem cannot be reproduced through the CLI. My guess is that in the downstream application, the encoder takes up too many slots in the decoder buffer pool and the decoder is stuck.

@nyanmisaka commented on GitHub (Apr 24, 2024): The problem cannot be reproduced through the CLI. My guess is that in the downstream application, the encoder takes up too many slots in the decoder buffer pool and the decoder is stuck.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: starred/ffmpeg-rockchip#34
No description provided.