Hm, i really dont believe your problem is the flushing part itself.
I wonder if the pkt you are sending to the encoder is initialized - at least i cannot see how. There is a huge number of issues in avcodec_encode_video2 that occur when you send it a pkt that it did not expect. Here is how I flush at the end of transcoding: int stillgotframes = 1; while(stillgotframes){ AVPacket pkt; av_init_packet(&pkt); int got_packet=0; int ret = -1; pkt.size = video_outbuf_size; //1000000 pkt.data = video_outbuf; // constant location in memory ret = avcodec_encode_video2(video_st->codec, &pkt, NULL, &got_packet); av_interleaved_write_frame(oc, &pkt); stillgotframes = got_packet; } Harry Von: libav-user-boun...@ffmpeg.org [mailto:libav-user-boun...@ffmpeg.org] Im Auftrag von Ashwin Chandra - SISA Gesendet: Friday, February 08, 2013 7:22 PM An: This list is about using libavcodec, libavformat, libavutil, libavdevice and libavfilter. Betreff: Re: [Libav-user] Problem with using libavcodec with AV_CODEC_ID_H264 All those presets I tried but didn't help. From: libav-user-boun...@ffmpeg.org [mailto:libav-user-boun...@ffmpeg.org] On Behalf Of Ashwin Chandra - SISA Sent: Friday, February 08, 2013 8:39 AM To: This list is about using libavcodec, libavformat, libavutil, libavdevice and libavfilter. Subject: Re: [Libav-user] Problem with using libavcodec with AV_CODEC_ID_H264 But the decoding_encoding example works for me without any changes. The problem is if you just want to encode two frames and flush them all out. With 25 there doesn't seem to be any issues. From: libav-user-boun...@ffmpeg.org [mailto:libav-user-boun...@ffmpeg.org] On Behalf Of Harald Jordan Sent: Friday, February 08, 2013 12:53 AM To: 'This list is about using libavcodec, libavformat, libavutil, libavdevice and libavfilter.' Subject: Re: [Libav-user] Problem with using libavcodec with AV_CODEC_ID_H264 If you did not make any changes to the open_video and add_video functions of the decoding_encoding example, it cannot work. For H264 you need to manually define a set a of H264 private settings before opening the codec. http://stackoverflow.com/questions/3553003/encoding-h-264-with-libavcodec-x2 64 Harry Von: libav-user-boun...@ffmpeg.org [mailto:libav-user-boun...@ffmpeg.org] Im Auftrag von Ashwin Chandra - SISA Gesendet: Freitag, 08. Februar 2013 00:29 An: This list is about using libavcodec, libavformat, libavutil, libavdevice and libavfilter. Betreff: Re: [Libav-user] Problem with using libavcodec with AV_CODEC_ID_H264 To be clearer, I modified the decoding_encoding.c example in ffmpeg to cause the problem. I basically changed the video_encode_example() to encode 1 second worth of video and then flush the delayed frame. The code below is exactly the same except 25 frames was replaced with 1 frame. Now if I take this code block and duplicate it again, so that it basically runs twice, the second avcodec_encode_video2() will hang. /* encode 1 second of video */ for(i=0;i<1;i++) { av_init_packet(&pkt); pkt.data = NULL; // packet data will be allocated by the encoder pkt.size = 0; fflush(stdout); /* prepare a dummy image */ /* Y */ for(y=0;y<c->height;y++) { for(x=0;x<c->width;x++) { frame->data[0][y * frame->linesize[0] + x] = x + y + i * 3; } } /* Cb and Cr */ for(y=0;y<c->height/2;y++) { for(x=0;x<c->width/2;x++) { frame->data[1][y * frame->linesize[1] + x] = 128 + y + i * 2; frame->data[2][y * frame->linesize[2] + x] = 64 + x + i * 5; } } frame->pts = i; /* encode the image */ ret = avcodec_encode_video2(c, &pkt, frame, &got_output); if (ret < 0) { fprintf(stderr, "Error encoding frame\n"); exit(1); } if (got_output) { printf("Write frame %3d (size=%5d)\n", i, pkt.size); fwrite(pkt.data, 1, pkt.size, f); av_free_packet(&pkt); } } /* get the delayed frames */ for (got_output = 1; got_output; i++) { fflush(stdout); ret = avcodec_encode_video2(c, &pkt, NULL, &got_output); if (ret < 0) { fprintf(stderr, "Error encoding frame\n"); exit(1); } if (got_output) { printf("Write frame %3d (size=%5d)\n", i, pkt.size); fwrite(pkt.data, 1, pkt.size, f); av_free_packet(&pkt); } } From: libav-user-boun...@ffmpeg.org [mailto:libav-user-boun...@ffmpeg.org] On Behalf Of Ashwin Chandra - SISA Sent: Thursday, February 07, 2013 3:08 PM To: libav-user@ffmpeg.org Subject: [Libav-user] Problem with using libavcodec with AV_CODEC_ID_H264 I have some code that takes a running stream of uncompressed video data and encodes it using AV_CODEC_ID_H264. The sequence I follow is 1. Call avcodec_encode_video2 on the AVFrame which contains my uncompressed frame. 2. Call avcodec_encode_video2 again passing NULL in the AVFrame parameter. 3. Repeat 2. Until a frame arrives from the encoder. This seems to work fine if the codec is MPEG2, but with H264, it hangs inside avcodec_encode_video2 at step 2) on the second frame. I don't have debug symbols and can't figure out why. Does there need to be a minimum set of uncompressed data in the encoder before trying to flush out an encoded frame for H264? If so, how do I know when it is safe to flush a frame?
_______________________________________________ Libav-user mailing list Libav-user@ffmpeg.org http://ffmpeg.org/mailman/listinfo/libav-user