Hi

I am trying to encode to FLV with H264 and AAC. I am manually encoding each frame as a key frame and specifying a PTS value for that frame. The problem is that when I play back the FLV through FLVPlayer/VLC the last 5 frames seem to be missing even though I am encoding delayed frames, the strange thing is that the file plays fine through FFPlay and Media Player Classic.

I include a version of the method I am using to encode, it's not that big do I haven't used PasteBin (hope that's OK). Any help would be appreciated.

I am using the following Codec setup:
        c = st->codec;
        c->codec_id = codec_id;
        c->codec_type = AVMEDIA_TYPE_VIDEO;
        c->bit_rate=400000;
        c->time_base.num=1;
        c->time_base.den=1000;
        c->gop_size=0;
        c->height=height;
        c->width=width;
        c->max_b_frames=0;
        c->max_qdiff=4;
        c->me_range=5;
        c->qmin=20;
        c->qmax=30;
        c->qcompress=0.6;
        c->trellis=0;
        c->level=13; //Level 1.3
        c->profile=66; //Baseline
        c->me_method=7;
        c->thread_count=2;
        c->qblur=0.1f;
        c->pix_fmt=STREAM_PIX_FMT; //YUV420P
        c->flags = CODEC_FLAG_LOW_DELAY;

And here is my method:
void FLVAuditTranscoder::TranscodeJPEGFrame(array<unsigned char>^ data, AVFormatContext *oc, AVStream *st, double timeStampInMilliseconds)
    {
        AVFrame* pFrame = avcodec_alloc_frame();
        int finished = 0;
        pin_ptr<unsigned char> dataSegment = &data[0];
        int size = data->Length;

int len = avcodec_decode_video(imageContext, pFrame, &finished, dataSegment, size);

        if (finished > 0)
        {
            int out_size, ret;
            AVCodecContext *c;
            static struct SwsContext *img_convert_ctx;

            c = st->codec;

            //pFrame->pts = timeStamp;
            c->coded_frame->pts = timeStamp;
out_size = avcodec_encode_video(c, video_outbuf, video_outbuf_size, pFrame);

            /* if zero size, it means the image was buffered */
            if (out_size > 0)
            {
                AVPacket pkt;
                av_init_packet(&pkt);

                if (c->coded_frame->pts != AV_NOPTS_VALUE)
pkt.pts = av_rescale_q(c->coded_frame->pts, c->time_base, st->time_base);

                if(c->coded_frame->key_frame)
                    pkt.flags |= AV_PKT_FLAG_KEY;

                pkt.stream_index= st->index;
                pkt.data= video_outbuf;
                pkt.size= out_size;

                /* write the compressed frame in the media file */
                ret = av_interleaved_write_frame(oc, &pkt);
            }
            else
                ret = 0;

            if (ret != 0)
            {
                fprintf(stderr, "Error while writing video frame\n");
                exit(1);
            }
        }
    }

Thanks,
Mark.
_______________________________________________
libav-api mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-api

Reply via email to