tutorial05.c 和tutorial06.c

tutorial05 是要把音频可以同步到视频,也为下一步快进,快退做准备。

 因为是音频所以不是简单的delay,需要进行音频缓冲的管理,synchronize_audio 返回的是一个同步好的缓冲区。

 

tutorial06.c 是要用一些API,实现快进或者快退。注意我们要清空我们自己的缓存。

 

    if(is->seek_req) {
      int stream_index= -1;
      int64_t seek_target = is->seek_pos;

      if     (is->videoStream >= 0) stream_index = is->videoStream;
      else if(is->audioStream >= 0) stream_index = is->audioStream;

      if(stream_index>=0){
            seek_target= av_rescale_q (seek_target, AV_TIME_BASE_Q, pFormatCtx->streams[stream_index]->time_base);
      }
      if(!av_seek_frame (is->pFormatCtx, stream_index, seek_target, is->seek_flags)) {
            fprintf(stderr, "%s: error while seeking/n", is->pFormatCtx->filename);
      } else {
            if(is->audioStream >= 0) {
                 packet_queue_flush(&is->audioq);
                 packet_queue_put(&is->audioq, &flush_pkt);
             }
             if(is->videoStream >= 0) {
                 packet_queue_flush(&is->videoq);
                 packet_queue_put(&is->videoq, &flush_pkt);  //放入清除FFmpeg buffer请求包
              }
      }
       is->seek_req = 0;
    }

 

//video:

    if(packet->data == flush_pkt.data) {
      avcodec_flush_buffers(is->video_st->codec);
      continue;
    }

//audio:

if(pkt->data == flush_pkt.data) {
      avcodec_flush_buffers(is->audio_st->codec);
      continue;
    }

 

//对清除指令特殊处理

if(pkt != &flush_pkt && av_dup_packet(pkt) < 0) {
    return -1;
  }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章