<div dir="ltr"> if (open_url(argv[1], &stream) == 0) {<br><br>        AVFrame* pic = av_frame_alloc();<br>        int i, size, x, y, outbuf_size;<br>        uint8_t *outbuf, *picture_buf;<br><br>        // alloc image and output buffer<br>
        outbuf_size = 100000;<br>        outbuf = malloc(outbuf_size);<br>        size = VIDEO_WIDTH * VIDEO_HEIGHT;<br>        picture_buf = malloc((size * 3) / 2); // size for YUV 420<br><br>        pic->data[0] = picture_buf;<br>
        pic->data[1] = pic->data[0] + size;<br>        pic->data[2] = pic->data[1] + size / 4;<br>        pic->linesize[0] = VIDEO_WIDTH;<br>        pic->linesize[1] = VIDEO_WIDTH / 2;<br>        pic->linesize[2] = VIDEO_WIDTH / 2;<br>
        AVPacket packet;<br>        av_init_packet(&packet);<br>        i = 0;<br><br>        int ret = avformat_write_header(stream.output_format_context, NULL);<br><br>        if (ret < 0) {<br>            av_log(NULL, AV_LOG_ERROR, "Error occurred when opening output file\n");<br>
            return ret;<br>        }<br><br>        while (!stopped) {<br>            // encode 1 second of video<br>            for(i = 0; i < 25; i++) {<br>                // prepare a dummy image<br>                //<br>
                for(y = 0; y < VIDEO_HEIGHT; y++) {<br><br>                    for(x = 0; x < VIDEO_WIDTH; x++) {<br>                        pic->data[0][y * pic->linesize[0] + x] = x + y + i * 3;<br>                    }<br>
                }<br><br>                // Cb and Cr<br>                for(y=0;y<VIDEO_HEIGHT/2;y++) {<br>                    for(x=0;x<VIDEO_WIDTH/2;x++) {<br>                        pic->data[1][y * pic->linesize[1] + x] = 128 + y + i * 2;<br>
                        pic->data[2][y * pic->linesize[2] + x] = 64 + x + i * 5;<br>                    }<br>                }<br><br>                int got_packet_ptr;<br>                avcodec_encode_video2(stream.stream->codec, &packet, pic, &got_packet_ptr);<br>
                int stream_index = 0;<br>                // prepare packet for muxing<br>                packet.stream_index = stream_index;<br>                packet.dts = av_rescale_q_rnd(packet.dts,<br>                        stream.output_format_context->streams[stream_index]->codec->time_base,<br>
                        stream.output_format_context->streams[stream_index]->time_base,<br>                        AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);<br>                packet.pts = av_rescale_q_rnd(packet.pts,<br>
                        stream.output_format_context->streams[stream_index]->codec->time_base,<br>                        stream.output_format_context->streams[stream_index]->time_base,<br>                        AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);<br>
                packet.duration = av_rescale_q(packet.duration,<br>                        stream.output_format_context->streams[stream_index]->codec->time_base,<br>                        stream.output_format_context->streams[stream_index]->time_base);<br>
<br>                if (got_packet_ptr) {<br>                    av_interleaved_write_frame(stream.output_format_context, &packet);<br>                } else<br>                    break;<br><br>                usleep(2);<br>
            }<br>        }<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">2014-08-01 5:01 GMT+04:00 Dmitry Adjiev <span dir="ltr"><<a href="mailto:adjiev.dmitry@gmail.com" target="_blank">adjiev.dmitry@gmail.com</a>></span>:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hello.<br clear="all"><div>I have a problem with avcodec_encode_video2.<br></div><div>I send h263 video stream to network, this code works when I compile it with C, but when I try to use C++ classes it crashes.<br>

</div><div>Can anyone help me?<span class="HOEnZb"><font color="#888888"><br></font></span></div><span class="HOEnZb"><font color="#888888"><div>-- <br>Regards,<br>Dmitry
</div></font></span></div>
</blockquote></div><br><br clear="all"><br>-- <br>Regards,<br>Dmitry
</div>