----- 영상 -------------------------------------------
FPS 구하기 : 비디오스트림의 r_frame_rate를 변환하면 fps를 구할 수 있다.
double fps   = av_q2d(pFormatCtx->streams[videoStream]->r_frame_rate);

동영상 길이 구하기 : 
 비디오스트림의 time_base는 프레임당 시간값이 저장되어 있다.
 그리고 비디오스트림의 duration에는 총 프레임 수가 저장되어 있다.

 이 두 값을 곱하면 동영상의 총 길이를 구할 수 있다.
double dur = av_q2d(pFormatCtx->streams[videoStream]->time_base) * pFormatCtx->streams[videoStream]->duration;


----- 음성 -------------------------------------------
audioStream의 데이터 값 중 duration 값에는 오디오에 할당된 실제 바이트가 입력되어 있다.
pFormatCtx->streams[audioStream]->duration

따라서 wave header를 생성시 이 값을 그대로 넣으면 된다.

wf.nSubChunk2Size = (DWORD)( pFormatCtx->streams[audioStream]->duration );

audio의 시간을 알고 싶다면 

pFormatCtx->streams[audioStream]->duration / wf.nAvgBytesPerSec

하면 초단위의 시간이 나온다.

---------------------------------------------------------------------------------------------
// FFMPEG을 이용한 웨이브 헤더 생성

MY_WAVEFORMATEX wf;
wf.Riff   = 0x46464952;    // "RIFF" { 'R', 'I', 'F', 'F' };
wf.Wave   = 0x45564157;    // "WAVE" { 'W', 'A', 'V', 'E' };
wf.Fmt   = 0x20746D66;    // "fmt " { 'f', 'm', 't', ' ' };
wf.nSubChunk1Size = 16;
wf.wFormatTag  = WAVE_FORMAT_PCM;  // PCM_WAVE = 1
wf.nChannels  = pCodecCtx_a->channels > 2 ? 2 : pCodecCtx_a->channels;
wf.nSamplesPerSec = pCodecCtx_a->sample_rate;
switch(pCodecCtx_a->sample_fmt) {
    case SAMPLE_FMT_U8 :     wf.wBitsPerSample = 8;     break;
    case SAMPLE_FMT_S16 :    wf.wBitsPerSample = 16;   break;
    case SAMPLE_FMT_S32 :    wf.wBitsPerSample = 32;   break;
    default :    bAudio = false;                                           break;
}
wf.nBlockAlign  = (wf.wBitsPerSample / 8) * wf.nChannels;
wf.nAvgBytesPerSec = wf.nSamplesPerSec * wf.nBlockAlign;
wf.Data    = 0x61746164;    // "data" { 'd', 'a', 't', 'a' };
wf.nSubChunk2Size = (DWORD)( pFormatCtx->streams[audioStream]->duration );
wf.nChunkSize  = wf.nSubChunk2Size + sizeof(MY_WAVEFORMATEX) - 8;

      
Posted by k_ben