Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assertion failed when decoding yuv420p to h264 #114

Open
ZhaoyungZhang opened this issue Apr 14, 2022 · 0 comments
Open

Assertion failed when decoding yuv420p to h264 #114

ZhaoyungZhang opened this issue Apr 14, 2022 · 0 comments

Comments

@ZhaoyungZhang
Copy link

Hi, I try to record screen with gdigrab. Then put the screen recording data into the avframe, convert to yuv data via sws_scale, and try to convert yuv420p to h264 using avcodec_send_frame. But when I do:

ret = avcodec_send_frame(pH264EnCodecCtx, pFrameYUV);

I get:
Assertion ((src_linesize) >= 0 ? (src_linesize) : (-(src_linesize))) >= bytewidth failed at libavutil/imgutils.c:314

Why? And how to solve this porblem!

code:
`//Read the data in the recorded screen--->packet
if (av_read_frame(pFormatCtx, packet) < 0)
break;

        if (packet->stream_index == videoIndex) {
            // Decode from screen recording stream, read raw data into pFrame
            int ret = avcodec_send_packet(pDeCodecCtx, packet);
            if (ret < 0) {
                printf("Decoder: send packet failed.\n");
                return -1;
            }
            ret = avcodec_receive_frame(pDeCodecCtx, pFrame);
            if (ret < 0) {
                printf("Decoder: receive frame failed.\n");
                return -1;
            }
            // Convert video frames from screen recording data space format to YUV space format
            sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize, 0, pDeCodecCtx->height, pFrameYUV->data, pFrameYUV->linesize);

            // Encode YUV data to h264
            ret = avcodec_send_frame(pH264EnCodecCtx, pFrameYUV);
            if (ret < 0) {
                printf("Encoder: send frame failed.\n");
                return -1;
            }
            ret = avcodec_receive_packet(pH264EnCodecCtx, packet);
            if (ret < 0) {
                printf("Encoder: receive packet failed.\n");
                return -1;
            }`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant