FFMPEG get video PTS

 When the video does not have PTS information, use DTS instead of PTS

When the PTS does not exist, the printout is    -9223372036854775808

if(packet->dts == AV_NOPTS_VALUE && packet->pts && packet->pts != AV_NOPTS_VALUE){
      VideoPTS = packet->pts;
}else if(packet->dts != AV_NOPTS_VALUE){
       VideoPTS = packet->dts;
}else{
      VideoPTS = 0;
}

VideoPTS *= av_q2d(formatContext->streams[video_stream_index]->time_base);

Audio and video synchronization

Three ways: the essence is to get the time difference and let the thread sleep sleep usleep

Synchronize audio to video to obtain PTS difference

Video to Audio Sync

Synchronize audio and video to system clock

multithreaded decoding

After ffmpeg  internal avcodec_open2, the number of m_pVideoCodecContext->thread_count is the same as the number of cpu cores. Therefore, if the number of encoded and decoded videos is too large, and the number of cpu cores is also large, it is easy to increase the number of threads in the entire process. And when the number of threads of a process is greater than 1000, the process will be automatically killed by the system.

Therefore, you can manually set the number of thread_count before calling the avcodec_open2 function.

AVCodecContext *codecContext = avcodec_alloc_context3(videoDecoder);
codecContext->thread_count = 4;

Android MediaCodec hard decoding, ffmpeg soft decoding, taking into account the model consistency and performance - Short Book (jianshu.com)

C language to get the system timestamp

millisecond level

long long GetSysCurrentTime(){
    struct timeval tv;
    gettimeofday(&tv, NULL);
    long long milliseconds = (long long)tv.tv_sec * 1000 + (long long)tv.tv_usec / 1000;
    //LOGE(LOG_TAG,"start_time %lld",milliseconds);
    return milliseconds;
}

 (291 messages) C language - get system time_c language get current time_hskwcy's blog-CSDN blog

Guess you like

Origin blog.csdn.net/xiaowang_lj/article/details/129931088