Hello Guys,

I cut my mpeg2-material framebased with this algorithm at the beginning of a 
cut:

<snip>
  int bytesRemaining = mCodecPointer;
  int bytesDecoded = 0;
  int frameFinished = 0;
  int bufPointer = 0;
  AVFrame* frame = avcodec_alloc_frame();

  // Temporaerer VideoBuffer
  uint8_t* video_outbuf = (uint8_t*) av_malloc(SMALL_BUFFER);

  int pts = 120;
  int frameNr = 0;
  int out_size = -1;

  while (mCoDecFramePointer != mCoDecFrameSizes.end())
  {
    bytesRemaining = (int) *mCoDecFramePointer;
    cout << "Dekodiere ..." << bytesRemaining << endl;
    bytesDecoded += avcodec_decode_video(mPCodecCtx, frame, &frameFinished, 
&mCoDecBuffer[bufPointer], bytesRemaining);
    bufPointer += bytesRemaining; 
    pts += (40 * frameNr) * 90;

    if (frameFinished)
    {
        frame->pts += pts; // <= Hier liegt das Problem
        //frame->key_frame = PKT_FLAG_KEY;
        out_size = avcodec_encode_video(mPOutputCodecCtx, video_outbuf, 
SMALL_BUFFER, 
frame);
        frameNr++;
        cout << "Encoder: OutSize ist " << out_size << endl;
        if (out_size>0)
        {
                cout << "Frame kodiert" << endl;
                AVPacket pkt;
                av_init_packet(&pkt);
                pkt.size = out_size;
                pkt.data = video_outbuf;

                packetToCutBuffer(&pkt);
        }
    }

    mCoDecFramePointer++;
  }
  int i = 0;
  // Buffer leeren
  for (; out_size; i++)
  {
        out_size = avcodec_encode_video(mPOutputCodecCtx, video_outbuf, 
SMALL_BUFFER, 
NULL);
        if (out_size>0)
        {
                cout << "Letztes Frame kodiert" << endl;
                AVPacket pkt;
                av_init_packet(&pkt);
                pkt.size = out_size;
                pkt.data = video_outbuf;

                packetToCutBuffer(&pkt);
        }
  }

  av_free(video_outbuf);
<snap>

This code is placed in a method called encodeVideo and the background is to 
encode the beginning of a cut, if I cut framebased and if the cutin is not an 
I-Frame. My mPOutputCodecCtx looks like:

<snip>
  mPOutputCodecCtx = mAVStream->codec;
  mPOutputCodecCtx->codec_id = mPCodecCtx->codec_id;
  mPOutputCodecCtx->codec_type = CODEC_TYPE_VIDEO;

  /* resolution must be a multiple of two */
  mPOutputCodecCtx->width = mPCodecCtx->width; //mWidth;
  mPOutputCodecCtx->height = mPCodecCtx->height; //mHeight;
    
  /* time base: this is the fundamental unit of time (in seconds) in terms
  of which frame timestamps are represented. for fixed-fps content,
  timebase should be 1/framerate and timestamp increments should be
  identically 1. */
  mPOutputCodecCtx->time_base.den = mFrameRate; //mPCodecCtx->time_base.den;
  mPOutputCodecCtx->time_base.num = 1; //mPCodecCtx->time_base.num;
  //c->gop_size = 12; /* emit one intra frame every twelve frames at most */
  mPOutputCodecCtx->pix_fmt = mPCodecCtx->pix_fmt;
  mPOutputCodecCtx->sample_aspect_ratio = mPCodecCtx->sample_aspect_ratio;

  mPOutputCodecCtx->gop_size = mPCodecCtx->gop_size;
  mPOutputCodecCtx->max_b_frames = 5;
  mPOutputCodecCtx->bit_rate = mPCodecCtx->bit_rate;
  mPOutputCodecCtx->time_base= mPCodecCtx->time_base;
  mPOutputCodecCtx->palctrl = mPCodecCtx->palctrl;

  mAVStream->sample_aspect_ratio = mPCodecCtx->sample_aspect_ratio;

  mPOutputCodec = avcodec_find_encoder(mPOutputCodecCtx->codec_id);
  
  if (avcodec_open(mPOutputCodecCtx, mPOutputCodec) < 0)
  {
        cout << "[VIDEOTRACK]: Could not open OutputCodec!" << endl;
  }
  else
  {
        cout << "[VIDEOTRACK]: Ready for new encoding!" << endl; 
  }
<snap>

After the encoding I copy the next GOP's beginning with an I-Frame into the 
output stream and mux it into an mpg-file. This works, but I get a dirty 
noise if I watch my video. Some pictures get noisy and I see some dirty 
pixel-errors. What is the Problem? Could anyone give me an hint how I make it 
better?

Many thanks,
Sven
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to