avfilter_graph_config(filter_graph, NULL)) ,Segmentation fault #128

Closed
opened 2025-12-23 10:33:36 +01:00 by backuprepo · 26 comments
Owner

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;

filter_graph = avfilter_graph_alloc();
if (!outputs || !inputs || !filter_graph)
{
	ret = AVERROR(ENOMEM);
	goto end;
}

if (dc->decoder->pix_fmt == AV_PIX_FMT_NONE)
{
	dc->decoder->pix_fmt = AV_PIX_FMT_DRM_PRIME;
}
/* buffer video source: the decoded frames from the decoder will be inserted here. */
snprintf(
	args, sizeof(args), "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d", dc->decoder->width,
	dc->decoder->height, dc->decoder->pix_fmt, time_base.num, time_base.den, dc->decoder->sample_aspect_ratio.num,
	dc->decoder->sample_aspect_ratio.den);

ret = avfilter_graph_create_filter(&buffersrc_ctx, buffersrc, "in", args, NULL, filter_graph);
if (ret < 0)
{
	av_log(NULL, AV_LOG_ERROR, "Cannot create buffer source\n");
	goto end;
}

/* buffer video sink: to terminate the filter chain. */
ret = avfilter_graph_create_filter(&buffersink_ctx, buffersink, "out", NULL, NULL, filter_graph);
if (ret < 0)
{
	av_log(NULL, AV_LOG_ERROR, "Cannot create buffer sink\n");
	goto end;
}

bufferSrcParameters = av_buffersrc_parameters_alloc();
bufferSrcParameters->hw_frames_ctx = dc->hw_device_ref;
av_buffersrc_parameters_set(buffersrc_ctx, bufferSrcParameters);

ret = av_opt_set_int_list(buffersink_ctx, "pix_fmts", pix_fmts, AV_PIX_FMT_NONE, AV_OPT_SEARCH_CHILDREN);
if (ret < 0)
{
	av_log(NULL, AV_LOG_ERROR, "Cannot set output pixel format\n");
	goto end;
}

/*
 * Set the endpoints for the filter graph. The filter_graph will
 * be linked to the graph described by filters_descr.
 */

/*
 * The buffer source output must be connected to the input pad of
 * the first filter described by filters_descr; since the first
 * filter input label is not specified, it is set to "in" by
 * default.
 */
outputs->name = av_strdup("in");
outputs->filter_ctx = buffersrc_ctx;
outputs->pad_idx = 0;
outputs->next = NULL;

/*
 * The buffer sink input must be connected to the output pad of
 * the last filter described by filters_descr; since the last
 * filter output label is not specified, it is set to "out" by
 * default.
 */
inputs->name = av_strdup("out");
inputs->filter_ctx = buffersink_ctx;
inputs->pad_idx = 0;
inputs->next = NULL;


if ((ret = avfilter_graph_parse_ptr(filter_graph, filters_descr, &inputs, &outputs, NULL)) < 0)
	goto end;

print_filter_graph(filter_graph);
if ((ret = avfilter_graph_config(filter_graph, NULL)) < 0)
	goto end;

end:
avfilter_inout_free(&inputs);
avfilter_inout_free(&outputs);

return ret;

}

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?

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; filter_graph = avfilter_graph_alloc(); if (!outputs || !inputs || !filter_graph) { ret = AVERROR(ENOMEM); goto end; } if (dc->decoder->pix_fmt == AV_PIX_FMT_NONE) { dc->decoder->pix_fmt = AV_PIX_FMT_DRM_PRIME; } /* buffer video source: the decoded frames from the decoder will be inserted here. */ snprintf( args, sizeof(args), "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d", dc->decoder->width, dc->decoder->height, dc->decoder->pix_fmt, time_base.num, time_base.den, dc->decoder->sample_aspect_ratio.num, dc->decoder->sample_aspect_ratio.den); ret = avfilter_graph_create_filter(&buffersrc_ctx, buffersrc, "in", args, NULL, filter_graph); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Cannot create buffer source\n"); goto end; } /* buffer video sink: to terminate the filter chain. */ ret = avfilter_graph_create_filter(&buffersink_ctx, buffersink, "out", NULL, NULL, filter_graph); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Cannot create buffer sink\n"); goto end; } bufferSrcParameters = av_buffersrc_parameters_alloc(); bufferSrcParameters->hw_frames_ctx = dc->hw_device_ref; av_buffersrc_parameters_set(buffersrc_ctx, bufferSrcParameters); ret = av_opt_set_int_list(buffersink_ctx, "pix_fmts", pix_fmts, AV_PIX_FMT_NONE, AV_OPT_SEARCH_CHILDREN); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Cannot set output pixel format\n"); goto end; } /* * Set the endpoints for the filter graph. The filter_graph will * be linked to the graph described by filters_descr. */ /* * The buffer source output must be connected to the input pad of * the first filter described by filters_descr; since the first * filter input label is not specified, it is set to "in" by * default. */ outputs->name = av_strdup("in"); outputs->filter_ctx = buffersrc_ctx; outputs->pad_idx = 0; outputs->next = NULL; /* * The buffer sink input must be connected to the output pad of * the last filter described by filters_descr; since the last * filter output label is not specified, it is set to "out" by * default. */ inputs->name = av_strdup("out"); inputs->filter_ctx = buffersink_ctx; inputs->pad_idx = 0; inputs->next = NULL; if ((ret = avfilter_graph_parse_ptr(filter_graph, filters_descr, &inputs, &outputs, NULL)) < 0) goto end; print_filter_graph(filter_graph); if ((ret = avfilter_graph_config(filter_graph, NULL)) < 0) goto end; end: avfilter_inout_free(&inputs); avfilter_inout_free(&outputs); return ret; } 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?
backuprepo 2025-12-23 10:33:36 +01:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@nyanmisaka commented on GitHub (Dec 2, 2024):

scale_rkrga only accept AV_PIX_FMT_DRM_PRIME frame input. Otherwise you have to use hwupload,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

@nyanmisaka commented on GitHub (Dec 2, 2024): `scale_rkrga` only accept `AV_PIX_FMT_DRM_PRIME` frame input. Otherwise you have to use `hwupload,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
Author
Owner

@JianJingGao commented on GitHub (Dec 2, 2024):

scale_rkrga only accept AV_PIX_FMT_DRM_PRIME frame input. Otherwise you have to use hwupload,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

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);

@JianJingGao commented on GitHub (Dec 2, 2024): > `scale_rkrga` only accept `AV_PIX_FMT_DRM_PRIME` frame input. Otherwise you have to use `hwupload,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 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);`
Author
Owner

@nyanmisaka commented on GitHub (Dec 2, 2024):

scale_rkrga only accept AV_PIX_FMT_DRM_PRIME frame input. Otherwise you have to use hwupload,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

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);

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

@nyanmisaka commented on GitHub (Dec 2, 2024): > > `scale_rkrga` only accept `AV_PIX_FMT_DRM_PRIME` frame input. Otherwise you have to use `hwupload,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 > > 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);` 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
Author
Owner

@JianJingGao commented on GitHub (Dec 3, 2024):

scale_rkrga only accept AV_PIX_FMT_DRM_PRIME frame input. Otherwise you have to use hwupload,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

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);

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

I checked the presence of a hardware decoder in the incoming filter

image

@JianJingGao commented on GitHub (Dec 3, 2024): > > > `scale_rkrga` only accept `AV_PIX_FMT_DRM_PRIME` frame input. Otherwise you have to use `hwupload,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 > > > > > > 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);` > > 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 I checked the presence of a hardware decoder in the incoming filter ![image](https://github.com/user-attachments/assets/ae3d405c-2c14-4f5c-a6e8-698b17df5b41)
Author
Owner

@nyanmisaka commented on GitHub (Dec 3, 2024):

h264_rkmpp -> drm_prime (nv12), provide hw_frames_ctx

-> scale_rkrga=format=rgba init from hw_frames_ctx -> drm_prime (rgba)

First check if ffmpeg can run. Equivalent in ffmpeg command:

./ffmpeg -hwaccel rkmpp -hwaccel_output_format drm_prime -i input.mp4 -an -sn \
-vf scale_rkrga=format=rgba -f null -
@nyanmisaka commented on GitHub (Dec 3, 2024): `h264_rkmpp` -> drm_prime (nv12), provide `hw_frames_ctx` -> `scale_rkrga=format=rgba` init from `hw_frames_ctx` -> drm_prime (rgba) First check if ffmpeg can run. Equivalent in ffmpeg command: ``` ./ffmpeg -hwaccel rkmpp -hwaccel_output_format drm_prime -i input.mp4 -an -sn \ -vf scale_rkrga=format=rgba -f null - ```
Author
Owner

@JianJingGao commented on GitHub (Dec 3, 2024):

ffmpeg -hwaccel rkmpp -hwaccel_output_format drm_prime -i input.mp4 -an -sn
-vf scale_rkrga=format=rgba -f null -

The ffmpeg status is normal


ffmpeg -hwaccel rkmpp -hwaccel_output_format drm_prime -i 11.mp4 -an -sn -vf scale_rkrga=format=rgba -f null -
ffmpeg version b81c3bf Copyright (c) 2000-2023 the FFmpeg developers
  built with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.2)
  configuration: --prefix=/usr --libdir=/usr/lib/aarch64-linux-gnu --enable-shared --disable-static --enable-gpl --enable-version3 --enable-libdrm --enable-rkmpp --enable-rkrga
  libavutil      58. 29.100 / 58. 29.100
  libavcodec     60. 31.102 / 60. 31.102
  libavformat    60. 16.100 / 60. 16.100
  libavdevice    60.  3.100 / 60.  3.100
  libavfilter     9. 12.100 /  9. 12.100
  libswscale      7.  5.100 /  7.  5.100
  libswresample   4. 12.100 /  4. 12.100
  libpostproc    57.  3.100 / 57.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '11.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    creation_time   : 2024-10-25T06:02:59.000000Z
  Duration: 00:00:56.00, start: 0.000000, bitrate: 4209 kb/s
  Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc, bt709, progressive), 1920x1080 [SAR 16:15 DAR 256:135], 4207 kb/s, 25 fps, 25 tbr, 1k tbn (default)
    Metadata:
      creation_time   : 2024-10-25T06:02:59.000000Z
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (h264_rkmpp) -> wrapped_avframe (native))
Press [q] to stop, [?] for help
rga_api version 1.9.3_[2]
Output #0, null, to 'pipe:':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf60.16.100
  Stream #0:0(und): Video: wrapped_avframe, drm_prime(pc, bt709, progressive), 1920x1080 [SAR 16:15 DAR 256:135], q=2-31, 200 kb/s, 25 fps, 25 tbn (default)
    Metadata:
      creation_time   : 2024-10-25T06:02:59.000000Z
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
      encoder         : Lavc60.31.102 wrapped_avframe
[out#0/null @ 0x55aea874c0] video:656kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
frame= 1400 fps=789 q=-0.0 Lsize=N/A time=00:00:55.96 bitrate=N/A speed=31.5x   
@JianJingGao commented on GitHub (Dec 3, 2024): > ffmpeg -hwaccel rkmpp -hwaccel_output_format drm_prime -i input.mp4 -an -sn \ > -vf scale_rkrga=format=rgba -f null - The ffmpeg status is normal ``` ffmpeg -hwaccel rkmpp -hwaccel_output_format drm_prime -i 11.mp4 -an -sn -vf scale_rkrga=format=rgba -f null - ffmpeg version b81c3bf Copyright (c) 2000-2023 the FFmpeg developers built with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.2) configuration: --prefix=/usr --libdir=/usr/lib/aarch64-linux-gnu --enable-shared --disable-static --enable-gpl --enable-version3 --enable-libdrm --enable-rkmpp --enable-rkrga libavutil 58. 29.100 / 58. 29.100 libavcodec 60. 31.102 / 60. 31.102 libavformat 60. 16.100 / 60. 16.100 libavdevice 60. 3.100 / 60. 3.100 libavfilter 9. 12.100 / 9. 12.100 libswscale 7. 5.100 / 7. 5.100 libswresample 4. 12.100 / 4. 12.100 libpostproc 57. 3.100 / 57. 3.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '11.mp4': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 creation_time : 2024-10-25T06:02:59.000000Z Duration: 00:00:56.00, start: 0.000000, bitrate: 4209 kb/s Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc, bt709, progressive), 1920x1080 [SAR 16:15 DAR 256:135], 4207 kb/s, 25 fps, 25 tbr, 1k tbn (default) Metadata: creation_time : 2024-10-25T06:02:59.000000Z handler_name : VideoHandler vendor_id : [0][0][0][0] Stream mapping: Stream #0:0 -> #0:0 (h264 (h264_rkmpp) -> wrapped_avframe (native)) Press [q] to stop, [?] for help rga_api version 1.9.3_[2] Output #0, null, to 'pipe:': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf60.16.100 Stream #0:0(und): Video: wrapped_avframe, drm_prime(pc, bt709, progressive), 1920x1080 [SAR 16:15 DAR 256:135], q=2-31, 200 kb/s, 25 fps, 25 tbn (default) Metadata: creation_time : 2024-10-25T06:02:59.000000Z handler_name : VideoHandler vendor_id : [0][0][0][0] encoder : Lavc60.31.102 wrapped_avframe [out#0/null @ 0x55aea874c0] video:656kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown frame= 1400 fps=789 q=-0.0 Lsize=N/A time=00:00:55.96 bitrate=N/A speed=31.5x ```
Author
Owner

@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.

  1. Check the AVFrame output by MPP decoder is comply with AVFrame->format == AV_PIX_FMT_DRM_PRIME

  2. Check if AVBufferSrcParameters->hw_frames_ctx is assigned as AVFrame->hw_frames_ctx

@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. 1. Check the AVFrame output by MPP decoder is comply with `AVFrame->format == AV_PIX_FMT_DRM_PRIME` 2. Check if `AVBufferSrcParameters->hw_frames_ctx` is assigned as `AVFrame->hw_frames_ctx`
Author
Owner

@JianJingGao commented on GitHub (Dec 4, 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.

  1. Check the AVFrame output by MPP decoder is comply with AVFrame->format == AV_PIX_FMT_DRM_PRIME
  2. Check if AVBufferSrcParameters->hw_frames_ctx is assigned as AVFrame->hw_frames_ctx

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?
image

@JianJingGao commented on GitHub (Dec 4, 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. > > 1. Check the AVFrame output by MPP decoder is comply with `AVFrame->format == AV_PIX_FMT_DRM_PRIME` > 2. Check if `AVBufferSrcParameters->hw_frames_ctx` is assigned as `AVFrame->hw_frames_ctx` 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? ![image](https://github.com/user-attachments/assets/e5d012db-9f14-4bce-aebf-c518dda322ef)
Author
Owner

@nyanmisaka commented on GitHub (Dec 4, 2024):

image

I can't reproduce it ^

@nyanmisaka commented on GitHub (Dec 4, 2024): ![image](https://github.com/user-attachments/assets/973b199f-07d4-4c7e-91f8-fceb3f47af70) I can't reproduce it ^
Author
Owner

@JianJingGao commented on GitHub (Dec 4, 2024):

image

I can't reproduce it ^

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)
{

RKRGAContext *r = avctx->priv;
AVFilterLink *inlink = avctx->inputs[0];
AVFilterLink *outlink = avctx->outputs[0];
AVHWFramesContext *hwfc_in;
AVHWFramesContext *hwfc_out;
AVBufferRef *hwfc_out_ref;
AVHWDeviceContext *device_ctx;
AVRKMPPFramesContext *rkmpp_fc;
int ret;

if (!inlink->hw_frames_ctx)
    return AVERROR(EINVAL);

hwfc_in = (AVHWFramesContext *)inlink->hw_frames_ctx->data;

if (hwfc_in->device_ref)
{
    av_log(avctx, AV_LOG_ERROR, "device_ref address: %p\n", (void *)inlink->hw_frames_ctx);
    av_log(avctx, AV_LOG_ERROR, "hwfc_in device_ref address: %p\n", (void *)hwfc_in->device_ref);

    if (hwfc_in->device_ref->data)
    {
        AVHWDeviceContext *hw_device_ctx = (AVHWDeviceContext *)hwfc_in->device_ref->data;
        // 打印硬件设备上下文的相关信息
        printf("HW Device Context: %p\n", (void *)hw_device_ctx);
        // 这里可以根据实际硬件上下文类型进一步打印相关信息
    }
}` 
@JianJingGao commented on GitHub (Dec 4, 2024): > ![image](https://private-user-images.githubusercontent.com/14953024/392270308-973b199f-07d4-4c7e-91f8-fceb3f47af70.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzMyOTk4MzcsIm5iZiI6MTczMzI5OTUzNywicGF0aCI6Ii8xNDk1MzAyNC8zOTIyNzAzMDgtOTczYjE5OWYtMDdkNC00YzdlLTkxZjgtZmNlYjNmNDdhZjcwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDEyMDQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQxMjA0VDA4MDUzN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWU0NmJhZjk2ZDU3YzkzZjFmMDM0Y2IxODZmMzdlMjhhMWEyZjQ0NTU0MGM4MjU1ZmJjZGU4ZjBhOWI4NGQ3NTAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.3IHeLBSKkzUsFSy4h4yeLZE7RKLd3u-hiwS1vFuARPo) > > I can't reproduce it ^ 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) { RKRGAContext *r = avctx->priv; AVFilterLink *inlink = avctx->inputs[0]; AVFilterLink *outlink = avctx->outputs[0]; AVHWFramesContext *hwfc_in; AVHWFramesContext *hwfc_out; AVBufferRef *hwfc_out_ref; AVHWDeviceContext *device_ctx; AVRKMPPFramesContext *rkmpp_fc; int ret; if (!inlink->hw_frames_ctx) return AVERROR(EINVAL); hwfc_in = (AVHWFramesContext *)inlink->hw_frames_ctx->data; if (hwfc_in->device_ref) { av_log(avctx, AV_LOG_ERROR, "device_ref address: %p\n", (void *)inlink->hw_frames_ctx); av_log(avctx, AV_LOG_ERROR, "hwfc_in device_ref address: %p\n", (void *)hwfc_in->device_ref); if (hwfc_in->device_ref->data) { AVHWDeviceContext *hw_device_ctx = (AVHWDeviceContext *)hwfc_in->device_ref->data; // 打印硬件设备上下文的相关信息 printf("HW Device Context: %p\n", (void *)hw_device_ctx); // 这里可以根据实际硬件上下文类型进一步打印相关信息 } }`
Author
Owner

@JianJingGao commented on GitHub (Dec 4, 2024):

image

@JianJingGao commented on GitHub (Dec 4, 2024): ![image](https://github.com/user-attachments/assets/2f536ef9-210d-4cb3-b46e-171435664249)
Author
Owner

@nyanmisaka commented on GitHub (Dec 4, 2024):

image

Get rid of this auto inserted scale filter and check again.

@nyanmisaka commented on GitHub (Dec 4, 2024): ![image](https://github.com/user-attachments/assets/ac4db7dd-9636-4c12-816c-007ca2e7fafc) Get rid of this auto inserted `scale` filter and check again.
Author
Owner

@JianJingGao commented on GitHub (Dec 5, 2024):

Get rid of this auto inserted scale filter and check again.

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

@JianJingGao commented on GitHub (Dec 5, 2024): > Get rid of this auto inserted `scale` filter and check again. 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
Author
Owner

@nyanmisaka commented on GitHub (Dec 5, 2024):

https://ffmpeg.org/doxygen/7.0/group__lavfi__buffersink.html#ga653228f4cbca427c654d844a5fc59cfa

AVERROR(EAGAIN) if no frames are available at this point; more input frames must be added to the filtergraph to get more output.

@nyanmisaka commented on GitHub (Dec 5, 2024): https://ffmpeg.org/doxygen/7.0/group__lavfi__buffersink.html#ga653228f4cbca427c654d844a5fc59cfa > [AVERROR(EAGAIN)](https://ffmpeg.org/doxygen/7.0/filter__design_8txt.html#adf2fb515710d47541f7150ecd2950e76) if no frames are available at this point; more input frames must be added to the filtergraph to get more output.
Author
Owner

@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.

@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.
Author
Owner

@JianJingGao commented on GitHub (Dec 5, 2024):

soga,

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.

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

@JianJingGao commented on GitHub (Dec 5, 2024): soga, > 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. 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
Author
Owner

@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): I'm not clear on your workflow, it looks like you messed up the input format of `scale_rkrga`.
Author
Owner

@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)

@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)
Author
Owner

@JianJingGao commented on GitHub (Dec 6, 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)

image

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
image

@JianJingGao commented on GitHub (Dec 6, 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) ![image](https://github.com/user-attachments/assets/2c3a643a-53a2-45f5-b2a6-4eac0caec298) 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 ![image](https://github.com/user-attachments/assets/375d9675-1f2b-4752-94ef-137626a7ba9b)
Author
Owner

@nyanmisaka commented on GitHub (Dec 6, 2024):

It looks like the problem is solved?

@nyanmisaka commented on GitHub (Dec 6, 2024): It looks like the problem is solved?
Author
Owner

@qaz624824554 commented on GitHub (Dec 31, 2024):

@JianJingGao 老哥你解决了吗,可以分享下解决方案吗~

@qaz624824554 commented on GitHub (Dec 31, 2024): @JianJingGao 老哥你解决了吗,可以分享下解决方案吗~
Author
Owner

@qaz624824554 commented on GitHub (Jan 1, 2025):

老哥不用了,我硬啃1天ffmpeg源码后,终于解决了这个问题😭

@qaz624824554 commented on GitHub (Jan 1, 2025): 老哥不用了,我硬啃1天ffmpeg源码后,终于解决了这个问题😭
Author
Owner

@qaz624824554 commented on GitHub (Jan 1, 2025):

image

@qaz624824554 commented on GitHub (Jan 1, 2025): ![image](https://github.com/user-attachments/assets/244afa3e-b715-483f-ab8f-d632fd088ac3)
Author
Owner

@xqhua commented on GitHub (Jan 1, 2025):

老哥不用了,我硬啃1天ffmpeg源码后,终于解决了这个问题😭

老哥能分享下解决方案不?我卡在hw_frames_ctx配置这儿...应该是我配置的有问题,,,导致av_buffersrc_parameters_set和avfilter_graph_config一直有问题

@xqhua commented on GitHub (Jan 1, 2025): > 老哥不用了,我硬啃1天ffmpeg源码后,终于解决了这个问题😭 老哥能分享下解决方案不?我卡在hw_frames_ctx配置这儿...应该是我配置的有问题,,,导致av_buffersrc_parameters_set和avfilter_graph_config一直有问题
Author
Owner

@qaz624824554 commented on GitHub (Jan 4, 2025):

@xqhua 你的报错信息是什么

@qaz624824554 commented on GitHub (Jan 4, 2025): @xqhua 你的报错信息是什么
Author
Owner

@xqhua commented on GitHub (Jan 4, 2025):

@qaz624824554 一开始是遇到的问题和楼主调试时遇到的一样:

[hwupload @ XXXXXXXXX] A hardware device reference is required to upload frames to.

随后我在初始化hwupload filter后使用以下方式指定了

ret = ret = avfilter_graph_create_filter(&hwuploader_ctx, hwuploader, "hwupload", NULL, NULL, filter_graph);
hwuploader_ctx->hw_device_ctx = av_buffer_ref(device_ref);

上述报错不再出现,但是我从filter里取出的帧还是nv12的(我想将nv12转成bgr24)。
可能是我之前配置的hw_frames_ctx有问题,或者是我在hwuploader_ctx中指定hw_device_ctx的方式不对?以下是我配置hw_frames_ctx的大致流程:

AVHWFramesContext *temp_frames_ctx = NULL;
if(!(decoder->hw_frames_ctx = av_hwframe_ctx_alloc(decoder_ctx->hw_device_ctx)))
    return -1;
temp_frames_ctx = (AVHWFramesContext *)(decoder->hw_frames_ctx-data);
temp_frames_ctx->format = AV_PIX_FMT_DRM_PRIME;
temp_frames_ctx->sw_format = AV_PIX_FMT_NV12;
temp_frames_ctx->width = decoder_ctx->width;
temp_frames_ctx->height = decoder_ctx->height;
if((ret = av_hwframe_ctx_init(decoder->hw_frames_ctx)) < 0)
{
    av_buffer_unref(&decoder->hw_frames_ctx)
    return -1;
}

请问我是漏了啥还是配置错了啥嘛?

@xqhua commented on GitHub (Jan 4, 2025): @qaz624824554 一开始是遇到的问题和楼主调试时遇到的一样: ### [hwupload @ XXXXXXXXX] A hardware device reference is required to upload frames to. 随后我在初始化hwupload filter后使用以下方式指定了 ``` ret = ret = avfilter_graph_create_filter(&hwuploader_ctx, hwuploader, "hwupload", NULL, NULL, filter_graph); hwuploader_ctx->hw_device_ctx = av_buffer_ref(device_ref); ``` 上述报错不再出现,但是我从filter里取出的帧还是nv12的(我想将nv12转成bgr24)。 可能是我之前配置的hw_frames_ctx有问题,或者是我在hwuploader_ctx中指定hw_device_ctx的方式不对?以下是我配置hw_frames_ctx的大致流程: ``` AVHWFramesContext *temp_frames_ctx = NULL; if(!(decoder->hw_frames_ctx = av_hwframe_ctx_alloc(decoder_ctx->hw_device_ctx))) return -1; temp_frames_ctx = (AVHWFramesContext *)(decoder->hw_frames_ctx-data); temp_frames_ctx->format = AV_PIX_FMT_DRM_PRIME; temp_frames_ctx->sw_format = AV_PIX_FMT_NV12; temp_frames_ctx->width = decoder_ctx->width; temp_frames_ctx->height = decoder_ctx->height; if((ret = av_hwframe_ctx_init(decoder->hw_frames_ctx)) < 0) { av_buffer_unref(&decoder->hw_frames_ctx) return -1; } ``` 请问我是漏了啥还是配置错了啥嘛?
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#128
No description provided.