mirror of
https://github.com/nyanmisaka/ffmpeg-rockchip.git
synced 2026-01-24 07:31:22 +01:00
avfilter_graph_config(filter_graph, NULL)) ,Segmentation fault #128
Labels
No labels
bug
enhancement
help wanted
invalid
pull-request
question
upstream
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: starred/ffmpeg-rockchip#128
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @JianJingGao on GitHub (Dec 2, 2024).
Filter: buffer
Output: buffer -> scale_rkrga
Filter: buffersink
Input: buffersink -> format
Filter: scale_rkrga
Input: scale_rkrga -> buffer
Output: scale_rkrga -> hwmap
Filter: hwmap
Input: hwmap -> scale_rkrga
Output: hwmap -> format
Filter: format
Input: format -> hwmap
Output: format -> buffersink
rga_api version 1.9.3_[2]
Segmentation fault
`int init_filters(const char *filters_descr, DecodeContext *dc)
{
char args[512];
int ret = 0;
const AVFilter *buffersrc = avfilter_get_by_name("buffer");
const AVFilter *buffersink = avfilter_get_by_name("buffersink");
AVFilterInOut *outputs = avfilter_inout_alloc();
AVFilterInOut *inputs = avfilter_inout_alloc();
AVRational time_base = dc->stream->time_base;
enum AVPixelFormat pix_fmts[] = {AV_PIX_FMT_DRM_PRIME, AV_PIX_FMT_BGRA, AV_PIX_FMT_NONE};
AVBufferSrcParameters *bufferSrcParameters = NULL;
AVFilterGraphSegment *seg;
end:
avfilter_inout_free(&inputs);
avfilter_inout_free(&outputs);
}
std::stringstream ss;
ss << "scale_rkrga=format=bgr24,hwmap,format=bgr24";
init_filters(ss.str().c_str(), dc);
`
I need to convert DRM to BGR24 for opencv to use, may I ask where I went wrong?
@nyanmisaka commented on GitHub (Dec 2, 2024):
scale_rkrgaonly acceptAV_PIX_FMT_DRM_PRIMEframe input. Otherwise you have to usehwupload,scale_rkrga...See also https://github.com/search?q=avfilter_get_by_name%28%22scale_vaapi%22%29+avfilter_get_by_name%28%22scale_cuda%22%29&type=code
@JianJingGao commented on GitHub (Dec 2, 2024):
After I added hwupload, I was told I couldn't find the hardware device. But I've already hard decoded it.
[hwupload @ 0x7f8c009bf0] A hardware device reference is required to upload frames to.
[Parsed_hwupload_0 @ 0x7f8c02c5f0] Query format failed for 'Parsed_hwupload_0': Invalid argument
ss << "hwupload,scale_rkrga=format=rgba,hwdownload,format=rgba"; init_filters(ss.str().c_str(), dc);@nyanmisaka commented on GitHub (Dec 2, 2024):
Then you can search for this line of prompts in the FFmpeg repo to find out what settings you are missing that caused the failure.
https://github.com/search?q=repo%3AFFmpeg%2FFFmpeg+%22A+hardware+device+reference+is+required%22&type=code
@JianJingGao commented on GitHub (Dec 3, 2024):
I checked the presence of a hardware decoder in the incoming filter
@nyanmisaka commented on GitHub (Dec 3, 2024):
h264_rkmpp-> drm_prime (nv12), providehw_frames_ctx->
scale_rkrga=format=rgbainit fromhw_frames_ctx-> drm_prime (rgba)First check if ffmpeg can run. Equivalent in ffmpeg command:
@JianJingGao commented on GitHub (Dec 3, 2024):
The ffmpeg status is normal
@nyanmisaka commented on GitHub (Dec 3, 2024):
So this is still not an ffmpeg issue, there must be something not set in the code that is causing the segfault. Check the following, and if that doesn't work, check the ffmpeg API documentation.
Check the AVFrame output by MPP decoder is comply with
AVFrame->format == AV_PIX_FMT_DRM_PRIMECheck if
AVBufferSrcParameters->hw_frames_ctxis assigned asAVFrame->hw_frames_ctx@JianJingGao commented on GitHub (Dec 4, 2024):
At present, I debug to rkrga_common.c static av_cold int init_hwframes_ctx(AVFilterContext *avctx)

If you access the data in hwfc_in->device_ref, a segment error occurs, and hwfc_in->device_ref is not NULL. Why?
@nyanmisaka commented on GitHub (Dec 4, 2024):
I can't reproduce it ^
@JianJingGao commented on GitHub (Dec 4, 2024):
I find that before forcibly forwarding, you can print addresses without segment errors. After forcibly forwarding, hwfc_in will report segment errors.Is there something wrong with that.
`static av_cold int init_hwframes_ctx(AVFilterContext *avctx)
{
@JianJingGao commented on GitHub (Dec 4, 2024):
@nyanmisaka commented on GitHub (Dec 4, 2024):
Get rid of this auto inserted
scalefilter and check again.@JianJingGao commented on GitHub (Dec 5, 2024):
halo,I modified the code to use the inlink->hw_frames_ctx access action instead of the cast hardware reference, and it compiled. In ret = av_buffersink_get_frame(buffersink_ctx, sw_frame);
Exit return -11. Is this normal?
const char *filter_descr = "hwupload,scale_rkrga=format=rgba,hwdownload,format=rgba";
[file @ 0x5555577d30] Setting default whitelist 'file,crypto,data'
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x55555778c0] Format mov,mp4,m4a,3gp,3g2,mj2 probed with size=2048 and score=100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x55555778c0] ISO: File Type Major Brand: isom
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x55555778c0] Unknown dref type 0x206c7275 size 12
[h264_rkmpp @ 0x5555579810] 222222222222
[h264_rkmpp @ 0x5555579810] Picked up an existing RKMPP hardware device
detected 8 logical cores
[in @ 0x55555a1e70] Setting 'video_size' to value '1920x1080'
[in @ 0x55555a1e70] Setting 'pix_fmt' to value '179'
[in @ 0x55555a1e70] Setting 'time_base' to value '1/1000'
[in @ 0x55555a1e70] Setting 'pixel_aspect' to value '0/1'
[in @ 0x55555a1e70] w:1920 h:1080 pixfmt:drm_prime tb:1/1000 fr:0/1 sar:0/1
[AVFilterGraph @ 0x55555a1000] Setting 'format' to value 'rgba'
[AVFilterGraph @ 0x55555a1000] Setting 'pix_fmts' to value 'rgba'
[h264_rkmpp @ 0x5555579810] device_ref address: 0x55555797f0
[h264_rkmpp @ 0x5555579810] device_ref address: 0x55555797f0
[auto_scale_0 @ 0x55555a3cc0] w:iw h:ih flags:'' interl:0
[out @ 0x55555a2070] auto-inserting filter 'auto_scale_0' between the filter 'Parsed_format_3' and the filter 'out'
[AVFilterGraph @ 0x55555a1000] query_formats: 6 queried, 4 merged, 1 already done, 0 delayed
[Parsed_scale_rkrga_1 @ 0x55555a23f0] inlink->hw_frames_ctx address: 0x55555a3850
[Parsed_scale_rkrga_1 @ 0x55555a23f0] sw_format: 0
[Parsed_scale_rkrga_1 @ 0x55555a23f0] ----No hw context provided on input
[Parsed_scale_rkrga_1 @ 0x55555a23f0] ff66666666666
rga_api version 1.9.3_[2]
[Parsed_scale_rkrga_1 @ 0x55555a23f0] ff7777777777
[Parsed_scale_rkrga_1 @ 0x55555a23f0] 222--->hw_frames_ctx address: 0x55555a3850
[Parsed_scale_rkrga_1 @ 0x55555a23f0] 100000000000000001
[Parsed_scale_rkrga_1 @ 0x55555a23f0] 10000000000000000
[Parsed_scale_rkrga_1 @ 0x55555a23f0] hwfc66666666666
[Parsed_scale_rkrga_1 @ 0x55555a23f0] av_hwframe_ctx_init
[Parsed_scale_rkrga_1 @ 0x55555a23f0] av_buffer_unref
[Parsed_scale_rkrga_1 @ 0x55555a23f0] ff888888888888
[Parsed_scale_rkrga_1 @ 0x55555a23f0] w:1920 h:1080 fmt:yuv420p -> w:1920 h:1080 fmt:rgba
[swscaler @ 0x55555b1ed0] [swscaler @ 0x55555c00d0] Forcing full internal H chroma due to input having non subsampled chroma
[swscaler @ 0x55555b1ed0] [swscaler @ 0x55555d4f30] Forcing full internal H chroma due to input having non subsampled chroma
[swscaler @ 0x55555b1ed0] [swscaler @ 0x55555e9d90] Forcing full internal H chroma due to input having non subsampled chroma
[swscaler @ 0x55555b1ed0] [swscaler @ 0x55555febf0] Forcing full internal H chroma due to input having non subsampled chroma
[swscaler @ 0x55555b1ed0] [swscaler @ 0x5555613a50] Forcing full internal H chroma due to input having non subsampled chroma
[swscaler @ 0x55555b1ed0] [swscaler @ 0x55556288b0] Forcing full internal H chroma due to input having non subsampled chroma
[swscaler @ 0x55555b1ed0] [swscaler @ 0x555563d710] Forcing full internal H chroma due to input having non subsampled chroma
[swscaler @ 0x55555b1ed0] [swscaler @ 0x5555652570] Forcing full internal H chroma due to input having non subsampled chroma
[swscaler @ 0x55555b1ed0] [swscaler @ 0x55556673d0] Forcing full internal H chroma due to input having non subsampled chroma
[auto_scale_0 @ 0x55555a3cc0] w:1920 h:1080 fmt:rgba sar:0/1 -> w:1920 h:1080 fmt:bgra sar:0/1 flags:0x00000004
[file @ 0x555567c230] Setting default whitelist 'file,crypto,data'
[NULL @ 0x5555578860] nal_unit_type: 7(SPS), nal_ref_idc: 3
[NULL @ 0x5555578860] Decoding VUI
[NULL @ 0x5555578860] nal_unit_type: 8(PPS), nal_ref_idc: 3
[NULL @ 0x5555578860] Decoding VUI
[NULL @ 0x5555578860] ct_type:0 pic_struct:0
[h264_rkmpp @ 0x5555579810] Wrote 239524 bytes to decoder
[NULL @ 0x5555578860] ct_type:0 pic_struct:0
[h264_rkmpp @ 0x5555579810] Wrote 12138 bytes to decoder
[NULL @ 0x5555578860] ct_type:0 pic_struct:0
[h264_rkmpp @ 0x5555579810] Wrote 8701 bytes to decoder
[NULL @ 0x5555578860] ct_type:0 pic_struct:0
[h264_rkmpp @ 0x5555579810] Wrote 9812 bytes to decoder
[NULL @ 0x5555578860] ct_type:0 pic_struct:0
[h264_rkmpp @ 0x5555579810] Noticed an info change
[h264_rkmpp @ 0x5555579810] Decoder options: deint=true afbc=0 fast_parse=true buf_mode=0
[h264_rkmpp @ 0x5555579810] Configured with size: 1920x1080 | pix_fmt: drm_prime | sw_pix_fmt: nv12
[h264_rkmpp @ 0x5555579810] Received a frame
[Parsed_scale_rkrga_1 @ 0x55555a23f0] RGA src | fd:18 mmu:1 rd_mode:0 | x:0 y:0 w:1920 h:1080 ws:1920 hs:1088 fmt:0xb
[Parsed_scale_rkrga_1 @ 0x55555a23f0] RGA dst | fd:35 mmu:1 rd_mode:0 | x:0 y:0 w:1920 h:1080 ws:1920 hs:1783 fmt:0x0
@nyanmisaka commented on GitHub (Dec 5, 2024):
https://ffmpeg.org/doxygen/7.0/group__lavfi__buffersink.html#ga653228f4cbca427c654d844a5fc59cfa
@nyanmisaka commented on GitHub (Dec 5, 2024):
The RGA filter is asynchronous in and out. It does not block after submitting a frame, you can continue to submit frames and get frames. Eventually, the RGA filter will drain the remaining frames when EOF is reached.
@JianJingGao commented on GitHub (Dec 5, 2024):
soga,
According to what you said, I can already get the AVFrame of BGRA, but when I add opencv to test the image, the filter will report an error. Is there any conflict between the two? Calling a CV-related function, even cv::WaitKey(), will report this error, which will work if commented out
[Parsed_scale_rkrga_1 @ 0x5555ac8ac0] Unsupported 'input' pad 0 format: '(null)'
[Parsed_scale_rkrga_1 @ 0x5555ac8ac0] Failed to configure output pad on Parsed_scale_rkrga_1
@nyanmisaka commented on GitHub (Dec 5, 2024):
I'm not clear on your workflow, it looks like you messed up the input format of
scale_rkrga.@nyanmisaka commented on GitHub (Dec 5, 2024):
h264_rkmpp -> AVFrame (drm_prime)
scale_rkrga=format=rgba -> AVFrame (drm_prime)
hwdownload,format=rgba -> AVFrame (rgba)
AVFrame (rgba)
-> data[0] (packed RGBA data)
-> linesize[0] (width pitch/stride in bytes)
@JianJingGao commented on GitHub (Dec 6, 2024):
const char *filter_descr = "hwupload,scale_rkrga=format=rgba,hwdownload,format=rgba";
I found that after referencing a third-party function, hwfc = (AVHWFramesContext *)link->hw_frames_ctx->data;
This variable will fail, I have tried opencv and SDL2 both problems. In addition, auto-insert filter has been removed, and my debugging information is currently excluded, which looks very clean
The following is a working log with comments

@nyanmisaka commented on GitHub (Dec 6, 2024):
It looks like the problem is solved?
@qaz624824554 commented on GitHub (Dec 31, 2024):
@JianJingGao 老哥你解决了吗,可以分享下解决方案吗~
@qaz624824554 commented on GitHub (Jan 1, 2025):
老哥不用了,我硬啃1天ffmpeg源码后,终于解决了这个问题😭
@qaz624824554 commented on GitHub (Jan 1, 2025):
@xqhua commented on GitHub (Jan 1, 2025):
老哥能分享下解决方案不?我卡在hw_frames_ctx配置这儿...应该是我配置的有问题,,,导致av_buffersrc_parameters_set和avfilter_graph_config一直有问题
@qaz624824554 commented on GitHub (Jan 4, 2025):
@xqhua 你的报错信息是什么
@xqhua commented on GitHub (Jan 4, 2025):
@qaz624824554 一开始是遇到的问题和楼主调试时遇到的一样:
[hwupload @ XXXXXXXXX] A hardware device reference is required to upload frames to.
随后我在初始化hwupload filter后使用以下方式指定了
上述报错不再出现,但是我从filter里取出的帧还是nv12的(我想将nv12转成bgr24)。
可能是我之前配置的hw_frames_ctx有问题,或者是我在hwuploader_ctx中指定hw_device_ctx的方式不对?以下是我配置hw_frames_ctx的大致流程:
请问我是漏了啥还是配置错了啥嘛?