<div dir="ltr">Thanks for replying Paul, very much appreciated. I used 32<br><div>because I followed Olive video editor's source code; it resembles</div><div>what my 2009 still developed software does: making a video file</div><div>of pictures with some transiction effect. Anyway I solved the crash</div><div>but VLC gives a black screen and a lot of totally undocumented </div><div>error messages in the terminal window when reproducing the video</div><div>file...</div><div><br></div><div>if you want to give a look to the software: <a href="http://imagination.sourceforge.net/">http://imagination.sourceforge.net/</a></div><div><br></div><div>Many thanks</div><div>Giuseppe</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, 26 Aug 2021 at 20:16, Paul B Mahol <<a href="mailto:onemda@gmail.com">onemda@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Aug 18, 2021 at 1:17 PM Colossus <<a href="mailto:colossus73@gmail.com" target="_blank">colossus73@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Ok, I reordered the code. I don't get anymore the annoying message<div>'input picture width greater than stride' but I get a crash in memalloc() called</div><div>by av_send_frame().</div><div><br></div><div><b>This is the gdb output:</b></div><div>Thread 1 "imagination" received signal SIGABRT, Aborted.<br>__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50<br>50       ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.<br>(gdb) bt<br>#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50<br>#1  0x00007ffff5518537 in __GI_abort () at abort.c:79<br>#2  0x00007ffff5571768 in __libc_message (action=action@entry=do_abort, fmt=fmt@entry=0x7ffff567fe2d "%s\n")<br>    at ../sysdeps/posix/libc_fatal.c:155<br>#3  0x00007ffff5578a5a in malloc_printerr (str=str@entry=0x7ffff5682110 "malloc_consolidate(): invalid chunk size")<br>    at malloc.c:5347<br>#4  0x00007ffff5579918 in malloc_consolidate (av=av@entry=0x7ffff56b1b80 <main_arena>) at malloc.c:4477<br>#5  0x00007ffff557b755 in _int_malloc (av=av@entry=0x7ffff56b1b80 <main_arena>, bytes=bytes@entry=16288) at malloc.c:3699<br>#6  0x00007ffff557c4af in _int_memalign<br>    (av=av@entry=0x7ffff56b1b80 <main_arena>, alignment=alignment@entry=64, bytes=bytes@entry=16176) at malloc.c:4684<br>#7  0x00007ffff557d55c in _mid_memalign (alignment=64, bytes=16176, address=<optimized out>) at malloc.c:3312<br>#8  0x00007ffff1e9fb2a in x264_malloc () at /lib/x86_64-linux-gnu/libx264.so.160<br>#9  0x00007ffff1eba75c in  () at /lib/x86_64-linux-gnu/libx264.so.160<br>#10 0x00007ffff1ebe6b0 in  () at /lib/x86_64-linux-gnu/libx264.so.160<br>#11 0x00007ffff1f27957 in  () at /lib/x86_64-linux-gnu/libx264.so.160<br>#12 0x00007ffff1ea4aa1 in x264_encoder_encode () at /lib/x86_64-linux-gnu/libx264.so.160<br>#13 0x00007ffff62df6d8 in  () at /lib/x86_64-linux-gnu/libavcodec.so.58<br>#14 0x00007ffff6094c37 in avcodec_encode_video2 () at /lib/x86_64-linux-gnu/libavcodec.so.58<br>#15 0x00007ffff6095012 in  () at /lib/x86_64-linux-gnu/libavcodec.so.58<br>#16 0x00007ffff609519f in <b>avcodec_send_frame</b> () at /lib/x86_64-linux-gnu/libavcodec.so.58<br>#17 0x000055555557aaae in img_export_encode_av_frame<br>    (pkt=0x5555556e6d60, ctx=0x55555643cb40, fmt=0x5555564859c0, frame=<optimized out>) at export.c:968<br></div><div><br></div><div>And this is the code:</div><div>static gboolean img_export_frame_to_avframe(img_window_struct *img, cairo_surface_t *surface)<br>{<br> static gint i = 0;<br><br>  gint    width, height, stride, row, col, offset, ret;<br> uint8_t  *pix, *data;<br>        AVFrame *frame;<br><br>     /* Image info and pixel data */<br>       width  = cairo_image_surface_get_width( surface );<br>   height = cairo_image_surface_get_height( surface );<br>   stride = cairo_image_surface_get_stride( surface );<br>   pix    = cairo_image_surface_get_data( surface );<br><br> /* Initialize AVFrame to be sent to the encoder */<br>    frame = av_frame_alloc();<br>     frame->format = img->codec_context->pix_fmt;<br> frame->width  = img->video_size[0];<br>    frame->height = img->video_size[1];<br>     av_frame_get_buffer(frame, 32);<br></div></div></blockquote><div><br></div><div>Why 32?, in doxy 0 is recommended, unless programmer know exactly what he is doing. </div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><br>     /* Fill the frame data with pixels from the Cairo surface */<br> for( row = 0; row < height; row++ )<br>        {<br>             data = pix + row * stride;<br>            for( col = 0; col < width; col++ )<br>         {<br>                     frame->data[0][row * frame->linesize[0] + col] = data[2];<br>                       frame->data[1][row * frame->linesize[1] + col] = data[1];<br>                       frame->data[2][row * frame->linesize[2] + col] = data[0];<br>                       data += 4;<br>            }<br>             frame->pts = i;<br>            i++;<br>  }<br>     //sws_scale(img->sws_ctx, pix, img->video_frame->linesize, 0, img->video_frame->height, img->video_frame->data, sws_frame->linesize);<br> <br>      ret = img_export_encode_av_frame(frame, img->video_format_context, img->codec_context, &img->video_packet);<br>      <br>if (frame)</div><div>{</div><div>av_frame_free(&frame);<br> frame = NULL;<br>}</div><div>return ret;<br>}<br><br>gboolean img_export_encode_av_frame(AVFrame *frame, AVFormatContext *fmt, AVCodecContext *ctx, AVPacket *pkt)<br>{<br>      gint ret;<br>    <br>    /* send the frame to the encoder */<br>    ret = <b>avcodec_send_frame</b>(ctx, frame);<br>    if (ret < 0)<br>    {<br>             g_print("Av error: %s\n",av_err2str(ret));<br>          g_print("Error sending a frame for encoding\n");<br>            return FALSE;<br> }<br>    while (ret >= 0)<br>    {<br>        ret = avcodec_receive_packet(ctx, pkt);<br>        if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)<br>                     return TRUE;<br>        else if (ret < 0)<br>                        g_print("Error during encoding\n");<br>                 <br>              av_interleaved_write_frame(fmt, pkt);<br>         av_packet_unref(pkt);<br>         return FALSE;<br>    }<br>    return TRUE;<br>}</div><div><br></div><div>What can be the cause of the crash now?<br></div></div></blockquote><div><br></div><div>Check with valgrind or similar for buffer overreads or overwrites.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><br>Thanks<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, 16 Aug 2021 at 16:35, Nicolas George <<a href="mailto:george@nsup.org" target="_blank">george@nsup.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Colossus (12021-08-16):<br>
> I told you I did and avcodec_send_frame() is the one that throws that error.<br>
<br>
I will trust the code I see. Re-post your code once you have fixed the<br>
order of the function calls and checked all the return values properly,<br>
if it still does not work.<br>
<br>
-- <br>
  Nicolas George<br>
_______________________________________________<br>
Libav-user mailing list<br>
<a href="mailto:Libav-user@ffmpeg.org" target="_blank">Libav-user@ffmpeg.org</a><br>
<a href="https://ffmpeg.org/mailman/listinfo/libav-user" rel="noreferrer" target="_blank">https://ffmpeg.org/mailman/listinfo/libav-user</a><br>
<br>
To unsubscribe, visit link above, or email<br>
<a href="mailto:libav-user-request@ffmpeg.org" target="_blank">libav-user-request@ffmpeg.org</a> with subject "unsubscribe".<br>
</blockquote></div>
_______________________________________________<br>
Libav-user mailing list<br>
<a href="mailto:Libav-user@ffmpeg.org" target="_blank">Libav-user@ffmpeg.org</a><br>
<a href="https://ffmpeg.org/mailman/listinfo/libav-user" rel="noreferrer" target="_blank">https://ffmpeg.org/mailman/listinfo/libav-user</a><br>
<br>
To unsubscribe, visit link above, or email<br>
<a href="mailto:libav-user-request@ffmpeg.org" target="_blank">libav-user-request@ffmpeg.org</a> with subject "unsubscribe".<br>
</blockquote></div></div>
_______________________________________________<br>
Libav-user mailing list<br>
<a href="mailto:Libav-user@ffmpeg.org" target="_blank">Libav-user@ffmpeg.org</a><br>
<a href="https://ffmpeg.org/mailman/listinfo/libav-user" rel="noreferrer" target="_blank">https://ffmpeg.org/mailman/listinfo/libav-user</a><br>
<br>
To unsubscribe, visit link above, or email<br>
<a href="mailto:libav-user-request@ffmpeg.org" target="_blank">libav-user-request@ffmpeg.org</a> with subject "unsubscribe".<br>
</blockquote></div>