<div dir="ltr"><div><div><div><div><div>Hi again.<br><br></div>Today I made some simpler code and retested<br></div>I have a crash and a core file<br><br></div>Here is the backtrace:<br>Program terminated with signal SIGSEGV, Segmentation fault.<br>#0  __memcpy_ssse3_rep () at ../sysdeps/i386/i686/multiarch/memcpy-ssse3-rep.S:1299<br>1299    ../sysdeps/i386/i686/multiarch/memcpy-ssse3-rep.S: No such file or directory.<br>(gdb) bt<br>#0  __memcpy_ssse3_rep () at ../sysdeps/i386/i686/multiarch/memcpy-ssse3-rep.S:1299<br>#1  0x080acc14 in avio_read (s=0xb156be0, buf=0xb1c0189d "", size=16471) at libavformat/aviobuf.c:570<br>#2  0x081a35ba in append_packet_chunked (s=0xb156be0, pkt=0xb4801238, size=21644) at libavformat/utils.c:223<br>#3  0x0810a067 in mov_read_packet (s=0xb1579a0, pkt=0xb4801238) at libavformat/mov.c:4235<br>#4  0x081a4962 in ff_read_packet (s=0xb1579a0, pkt=0xb4801238) at libavformat/utils.c:665<br>#5  0x081a7e99 in read_frame_internal (s=s@entry=0xb1579a0, pkt=pkt@entry=0x917b180 <pkt+576>) at libavformat/utils.c:1318<br>#6  0x081a8ea3 in av_read_frame (s=<optimized out>, pkt=0x917b180 <pkt+576>) at libavformat/utils.c:1529<br>#7  0x080952f8 in worker_thread (Param=0xbfa4c650) at videogw.c:51<br>#8  0xb72e0efb in start_thread (arg=0xb4801b40) at pthread_create.c:309<br>#9  0xb721962e in clone () at ../sysdeps/unix/sysv/linux/i386/clone.S:129<br><br><br></div>Mine source code is:<br><br>/*<br> * Copyright (c) 2013 Stefano Sabatini<br> *<br> * Permission is hereby granted, free of charge, to any person obtaining a copy<br> * of this software and associated documentation files (the "Software"), to deal<br> * in the Software without restriction, including without limitation the rights<br> * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell<br> * copies of the Software, and to permit persons to whom the Software is<br> * furnished to do so, subject to the following conditions:<br> *<br> * The above copyright notice and this permission notice shall be included in<br> * all copies or substantial portions of the Software.<br> *<br> * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br> * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br> * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL<br> * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br> * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,<br> * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN<br> * THE SOFTWARE.<br> */<br><br>/**<br> * @file<br> * libavformat/libavcodec demuxing and muxing API example.<br> *<br> * Remux streams from one container format to another.<br> * @example remuxing.c<br> */<br><br>#include <libavutil/timestamp.h><br>#include <libavformat/avformat.h><br>#include <pthread.h><br>#include <unistd.h><br><br>#define MAX 10<br><br>AVOutputFormat *ofmt[MAX];<br>AVFormatContext *ifmt_ctx[MAX], *ofmt_ctx[MAX];<br>int video_idx[MAX];<br>AVPacket pkt[MAX];<br><br>void* worker_thread(void *Param)<br>{<br>    int id = *((int*)Param);<br>    int idx = video_idx[id];<br>    int ret;<br><br>    while (1)<br>    {<br>        ret = av_read_frame(ifmt_ctx[id], &pkt[id]);<br>        if (ret < 0)<br>            break;<br><br>        if (pkt[id].stream_index != idx)<br>            continue;<br><br>        AVStream *in_stream  = ifmt_ctx[id]->streams[pkt[id].stream_index];<br>        AVStream *out_stream = ofmt_ctx[id]->streams[pkt[id].stream_index];<br><br>        AVRational time_base = ifmt_ctx[id]->streams[idx]->time_base;<br><br>        int time = 1000 * 1000 * strtof(av_ts2timestr(pkt[id].duration, &time_base), NULL);<br>        usleep(time);<br><br>        pkt[id].pts = av_rescale_q_rnd(pkt[id].pts, in_stream->time_base, out_stream->time_base, AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);<br>        pkt[id].dts = av_rescale_q_rnd(pkt[id].dts, in_stream->time_base, out_stream->time_base, AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);<br>        pkt[id].duration = av_rescale_q(pkt[id].duration, in_stream->time_base, out_stream->time_base);<br>        pkt[id].pos = -1;<br><br>        ret = av_interleaved_write_frame(ofmt_ctx[id], &pkt[id]);<br>        if (ret < 0)<br>        {<br>            fprintf(stderr, "Error muxing packet thread %d\n", id);<br>            break;<br>        }<br><br>        av_free_packet(&pkt[id]);<br>    }<br>}<br><br>int main(int argc, char **argv)<br>{<br>    char *in_filename, out_filename[22];<br>    int ret, i = 0;<br><br>    memset(ofmt, 0, sizeof(ofmt));<br>    memset(ofmt_ctx, 0, sizeof(ofmt_ctx));<br>    memset(ifmt_ctx, 0, sizeof(ifmt_ctx));<br>    memset(video_idx, -1, sizeof(video_idx));<br><br>    in_filename  = "/home/georgi/Downloads/video/IMG_0019.MOV";<br><br>    av_register_all();<br>    avformat_network_init();<br><br>    for (i = 0; i < MAX; i++)<br>    {<br>        fprintf(stdout, "%d\n", i);<br><br>        if ((ret = avformat_open_input(&ifmt_ctx[i], in_filename, 0, 0)) < 0)<br>        {<br>            fprintf(stderr, "Could not open input file '%s'", in_filename);<br>            goto end;<br>        }<br><br>        if ((ret = avformat_find_stream_info(ifmt_ctx[i], 0)) < 0)<br>        {<br>            fprintf(stderr, "Failed to retrieve input stream information");<br>            goto end;<br>        }<br><br>        ifmt_ctx[i]->flags |= AVFMT_FLAG_GENPTS;<br><br>        sprintf(out_filename,"rtp://10.101.3.60:%d", 9078 + i);<br><br>        avformat_alloc_output_context2(&ofmt_ctx[i], NULL, "rtp", out_filename);<br><br>        if (!ofmt_ctx[i])<br>        {<br>            fprintf(stderr, "Could not create output context\n");<br>            ret = AVERROR_UNKNOWN;<br>            goto end;<br>        }<br><br>        ofmt[i] = ofmt_ctx[i]->oformat;<br><br>        int k;<br>        for (k = 0; k < ifmt_ctx[i]->nb_streams; k++)<br>        {<br>            if (ifmt_ctx[i]->streams[k]->codec->codec_type == AVMEDIA_TYPE_VIDEO)<br>            {<br>                AVStream *in_stream = ifmt_ctx[i]->streams[k];<br>                AVStream *out_stream = avformat_new_stream(ofmt_ctx[i], in_stream->codec->codec);<br>                if (!out_stream)<br>                {<br>                    fprintf(stderr, "Failed allocating output stream\n");<br>                    ret = AVERROR_UNKNOWN;<br>                    goto end;<br>                }<br><br>                ret = avcodec_copy_context(out_stream->codec, in_stream->codec);<br>                if (ret < 0)<br>                {<br>                    fprintf(stderr, "Failed to copy context from input to output stream codec context\n");<br>                    goto end;<br>                }<br>                out_stream->codec->codec_tag = 0;<br>                if (ofmt_ctx[i]->oformat->flags & AVFMT_GLOBALHEADER)<br>                    out_stream->codec->flags |= CODEC_FLAG_GLOBAL_HEADER;<br><br>                video_idx[i] = k;<br>            }<br>        }<br><br>        if (!(ofmt[i]->flags & AVFMT_NOFILE))<br>        {<br>            ret = avio_open(&ofmt_ctx[i]->pb, out_filename, AVIO_FLAG_WRITE);<br>            if (ret < 0)<br>            {<br>                fprintf(stderr, "Could not open output file '%s'", out_filename);<br>                goto end;<br>            }<br>        }<br><br>        ret = avformat_write_header(ofmt_ctx[i], NULL);<br>        if (ret < 0)<br>        {<br>            fprintf(stderr, "Error occurred when opening output file\n");<br>            goto end;<br>        }<br>    }<br><br>    pthread_t thread_ids[MAX];<br>    for (i = 0; i < MAX; i++)<br>    {<br>        if ( 0 != pthread_create(&thread_ids[i], NULL, &worker_thread, (void*)&i) )<br>        {<br>            fprintf(stderr, "Could not create thread %d\n", i);<br>            break;<br>        }<br>    }<br><br>    for (i = 0; i < MAX; i++)<br>    {<br>        pthread_join(thread_ids[i], NULL);<br>    }<br><br>end:<br><br>    for (i = 0; i < MAX; i++)<br>    {<br>        av_write_trailer(ofmt_ctx[i]);<br><br>        avformat_close_input(&ifmt_ctx[i]);<br><br>        /* close output */<br>        if (ofmt_ctx[i] && !(ofmt[i]->flags & AVFMT_NOFILE))<br>            avio_closep(&ofmt_ctx[i]->pb);<br><br>        avformat_free_context(ofmt_ctx[i]);<br><br>        if (ret < 0 && ret != AVERROR_EOF)<br>        {<br>            fprintf(stderr, "Error occurred: %s\n", av_err2str(ret));<br>            return 1;<br>        }<br>    }<br><br>    return 0;<br>}<br><br></div>Is this a bug in ffmpeg or I do not use it the right way ?<br></div>