[Libav-user] avcodec_encode_video2 C++problem

Dmitry Adjiev adjiev.dmitry at gmail.com
Fri Aug 1 03:11:40 CEST 2014


I solved the issue. I don't know why. but in C++ buffer size outbuf_size =
100000; was too small, so increase of buffer size solves the problem.
Thanks for everyone who read it


2014-08-01 5:08 GMT+04:00 Dmitry Adjiev <adjiev.dmitry at gmail.com>:

>  if (open_url(argv[1], &stream) == 0) {
>
>         AVFrame* pic = av_frame_alloc();
>         int i, size, x, y, outbuf_size;
>         uint8_t *outbuf, *picture_buf;
>
>         // alloc image and output buffer
>         outbuf_size = 100000;
>         outbuf = malloc(outbuf_size);
>         size = VIDEO_WIDTH * VIDEO_HEIGHT;
>         picture_buf = malloc((size * 3) / 2); // size for YUV 420
>
>         pic->data[0] = picture_buf;
>         pic->data[1] = pic->data[0] + size;
>         pic->data[2] = pic->data[1] + size / 4;
>         pic->linesize[0] = VIDEO_WIDTH;
>         pic->linesize[1] = VIDEO_WIDTH / 2;
>         pic->linesize[2] = VIDEO_WIDTH / 2;
>         AVPacket packet;
>         av_init_packet(&packet);
>         i = 0;
>
>         int ret = avformat_write_header(stream.output_format_context,
> NULL);
>
>         if (ret < 0) {
>             av_log(NULL, AV_LOG_ERROR, "Error occurred when opening output
> file\n");
>             return ret;
>         }
>
>         while (!stopped) {
>             // encode 1 second of video
>             for(i = 0; i < 25; i++) {
>                 // prepare a dummy image
>                 //
>                 for(y = 0; y < VIDEO_HEIGHT; y++) {
>
>                     for(x = 0; x < VIDEO_WIDTH; x++) {
>                         pic->data[0][y * pic->linesize[0] + x] = x + y + i
> * 3;
>                     }
>                 }
>
>                 // Cb and Cr
>                 for(y=0;y<VIDEO_HEIGHT/2;y++) {
>                     for(x=0;x<VIDEO_WIDTH/2;x++) {
>                         pic->data[1][y * pic->linesize[1] + x] = 128 + y +
> i * 2;
>                         pic->data[2][y * pic->linesize[2] + x] = 64 + x +
> i * 5;
>                     }
>                 }
>
>                 int got_packet_ptr;
>                 avcodec_encode_video2(stream.stream->codec, &packet, pic,
> &got_packet_ptr);
>                 int stream_index = 0;
>                 // prepare packet for muxing
>                 packet.stream_index = stream_index;
>                 packet.dts = av_rescale_q_rnd(packet.dts,
>
> stream.output_format_context->streams[stream_index]->codec->time_base,
>
> stream.output_format_context->streams[stream_index]->time_base,
>                         AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
>                 packet.pts = av_rescale_q_rnd(packet.pts,
>
> stream.output_format_context->streams[stream_index]->codec->time_base,
>
> stream.output_format_context->streams[stream_index]->time_base,
>                         AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
>                 packet.duration = av_rescale_q(packet.duration,
>
> stream.output_format_context->streams[stream_index]->codec->time_base,
>
> stream.output_format_context->streams[stream_index]->time_base);
>
>                 if (got_packet_ptr) {
>
> av_interleaved_write_frame(stream.output_format_context, &packet);
>                 } else
>                     break;
>
>                 usleep(2);
>             }
>         }
>
>
> 2014-08-01 5:01 GMT+04:00 Dmitry Adjiev <adjiev.dmitry at gmail.com>:
>
> Hello.
>> I have a problem with avcodec_encode_video2.
>> 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.
>> Can anyone help me?
>> --
>> Regards,
>> Dmitry
>>
>
>
>
> --
> Regards,
> Dmitry
>



-- 
Regards,
Dmitry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20140801/cd3d1539/attachment.html>


More information about the Libav-user mailing list