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;
  }

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