<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Dear all,<div><br></div><div>I’ve been working on a small C application using libav to  transcode mpegts file (change heigh, width, bitrate…). </div><div>Source file can be transcoding using ffmpeg command line without problem</div><div><a href="https://gist.github.com/whatvn/7e669d295238a009f9d4">https://gist.github.com/whatvn/7e669d295238a009f9d4</a></div><div><br></div><div>But I would like to transcode this video using libav api library to integrate it to our application (nginx).</div><div>What I have until now is this source code:</div><div><br></div><div><a href="https://gist.github.com/whatvn/9ae5678cd5a4090ac469">https://gist.github.com/whatvn/9ae5678cd5a4090ac469</a></div><div><br></div><div>I don’t want to write transcoded result into file, I I use a callback write function to write to output buffer and pass it to AVIOContext: </div><div><br></div><div><div>static int write_adbr_packet(void *opaque, unsigned char *buf, int buf_size) {</div><div>    int old_size;</div><div>    video_buffer *destination = (video_buffer *) opaque;</div><div><br></div><div>    if (destination->data == NULL) {</div><div>        destination->data = malloc(memory_pool, 9600 * sizeof (unsigned char));</div><div>    }</div><div>    old_size = destination->len;</div><div>    destination->len += buf_size;</div><div>    ngx_memcpy(destination->data + old_size, buf, buf_size * sizeof (unsigned char));</div><div>    return buf_size;</div><div>}</div></div><div> </div><div>When running, my application got coredump:</div><div><br></div><div>Back trace: fail at av_interleaved_write_frame </div><div><br></div><div><div>warning: no loadable sections found in added symbol-file system-supplied DSO at 0x7fff40ffe000</div><div>Core was generated by `nginx: worker process                          '.</div><div>Program terminated with signal 11, Segmentation fault.</div><div>#0  malloc_consolidate (av=av@entry=0x7fa70e2d0740 <main_arena>) at malloc.c:4088</div><div>4088    malloc.c: No such file or directory.</div><div>(gdb) bt</div><div>#0  malloc_consolidate (av=av@entry=0x7fa70e2d0740 <main_arena>) at malloc.c:4088</div><div>#1  0x00007fa70df8f7e8 in _int_free (av=0x7fa70e2d0740 <main_arena>, p=0x1fd5e30, have_lock=0) at malloc.c:3994</div><div>#2  0x00007fa70eb16f3f in av_buffer_unref () from /usr/local/lib/libavutil.so.54</div><div>#3  0x00007fa70ee56124 in av_free_packet () from /usr/local/lib/libavcodec.so.56</div><div>#4  0x00007fa710049cea in av_interleaved_write_frame () from /usr/local/lib/libavformat.so.56</div></div><div><br></div><div><br></div><div>Info all register:</div><div><br></div><div><a href="https://gist.github.com/whatvn/6f9a58389a1d6f43848b">https://gist.github.com/whatvn/6f9a58389a1d6f43848b</a></div><div><br></div><div>I know there must be something wrong with my implement, but I cannot find it for several days. </div><div>Could someone please dig in my source code and give me some suggestion, please!</div><div><br></div><div>Thanks,</div><div><br></div><div>Hung</div><div> </div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></body></html>