Hello, I am trying to encode one single video frame as a jpg image.
This my code: -------------------------------------------------- void saveFrame(AVFrame *pFrame,char *filename, int i) { // pFrame has pix_fmt AV_PIX_FMT_YUV420P int ret; FILE *JPEGFile; AVCodec *jpegCodec = avcodec_find_encoder(AV_CODEC_ID_MJPEG); if (!jpegCodec) { return; } AVCodecContext *jpegContext = avcodec_alloc_context3(jpegCodec); if (!jpegContext) { fprintf(stderr,"Error getting encoder context\n"); return; } AVPacket* packet = av_packet_alloc(); jpegContext->height = pFrame->height; jpegContext->width = pFrame->width; jpegContext->pix_fmt = AV_PIX_FMT_YUVJ420P; jpegContext->time_base = (AVRational){1,25}; jpegContext->framerate = (AVRational){25,1}; jpegContext->qcompress = 0.5; if (avcodec_open2(jpegContext, jpegCodec, NULL) < 0) { fprintf(stderr,"Error opening encoder\n"); return; } ret = avcodec_send_frame(jpegContext,pFrame); if (ret < 0) { write_avErrorMsg(ret,"saveFrame"); return; } ret = avcodec_receive_packet(jpegContext,packet); if (ret < 0) { write_avErrorMsg(ret,"saveFrame"); return; } JPEGFile = fopen(filename, "wb"); fwrite(packet->data, 1, packet->size, JPEGFile); fclose(JPEGFile); av_packet_unref(packet); avcodec_close(jpegContext); return; ----------------------------------------- Calling avcodec_send_frame results in this error:Assertion ((src_linesize) >= 0 ? (src_linesize) : (-(src_linesize))) >= bytewidth failed at src/libavutil/imgutils.c:349
Something seems to be wrong with the source (pFrame in my example). I assume an issue with the bytewidth, because the values of pFrame->linesize are correct.
How can I fix this problem? Thanks in advance, Udo
_______________________________________________ Libav-user mailing list Libav-user@ffmpeg.org https://ffmpeg.org/mailman/listinfo/libav-user To unsubscribe, visit link above, or email libav-user-requ...@ffmpeg.org with subject "unsubscribe".