本文整理汇总了C++中BMediaTrack::CountFrames方法的典型用法代码示例。如果您正苦于以下问题:C++ BMediaTrack::CountFrames方法的具体用法?C++ BMediaTrack::CountFrames怎么用?C++ BMediaTrack::CountFrames使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BMediaTrack
的用法示例。
在下文中一共展示了BMediaTrack::CountFrames方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: audioDone
void
MediaFileInfoView::_GetFileInfo(BString* audioFormat, BString* videoFormat,
BString* audioDetails, BString* videoDetails, BString* duration)
{
fDuration = 0;
if (fMediaFile == NULL)
return;
BMediaTrack* track;
media_format format;
memset(&format, 0, sizeof(format));
media_codec_info codecInfo;
bool audioDone(false), videoDone(false);
bigtime_t audioDuration = 0;
bigtime_t videoDuration = 0;
int32 tracks = fMediaFile->CountTracks();
int64 videoFrames = 0;
int64 audioFrames = 0;
for (int32 i = 0; i < tracks && (!audioDone || !videoDone); i++) {
track = fMediaFile->TrackAt(i);
if (track != NULL) {
track->EncodedFormat(&format);
if (format.IsVideo()) {
memset(&format, 0, sizeof(format));
format.type = B_MEDIA_RAW_VIDEO;
track->DecodedFormat(&format);
media_raw_video_format *rvf = &(format.u.raw_video);
track->GetCodecInfo(&codecInfo);
*videoFormat << codecInfo.pretty_name;
videoDuration = track->Duration();
videoFrames = track->CountFrames();
*videoDetails << (int32)format.Width() << "x" << (int32)format.Height()
<< " " << (int32)(rvf->field_rate / rvf->interlace)
<< " fps / " << videoFrames << " frames";
videoDone = true;
} else if (format.IsAudio()) {
memset(&format, 0, sizeof(format));
format.type = B_MEDIA_RAW_AUDIO;
track->DecodedFormat(&format);
media_raw_audio_format *raf = &(format.u.raw_audio);
char bytesPerSample = (char)(raf->format & 0xf);
if (bytesPerSample == 1) {
*audioDetails << "8 bit ";
} else if (bytesPerSample == 2) {
*audioDetails << "16 bit ";
} else {
*audioDetails << bytesPerSample << "byte ";
}
track->GetCodecInfo(&codecInfo);
*audioFormat << codecInfo.pretty_name;
audioDuration = track->Duration();
audioFrames = track->CountFrames();
*audioDetails << (float)(raf->frame_rate / 1000.0f) << " kHz";
if (raf->channel_count == 1) {
*audioDetails << " mono / ";
} else if (raf->channel_count == 2) {
*audioDetails << " stereo / ";
} else {
*audioDetails << (int32)raf->channel_count << " channel / " ;
}
*audioDetails << audioFrames << " frames";
audioDone = true;
}
fMediaFile->ReleaseTrack(track);
}
}
fDuration = MAX(audioDuration, videoDuration);
*duration << (int32)(fDuration / 1000000)
<< " seconds";
}
示例2: destWindow
status_t
MainView::LoadWave(const entry_ref& ref)
{
bigtime_t startLoadWave = system_time();
fDestCursor = 0;
fSourceCursor = 0;
fAverage = 0.0f;
fAverageCursor = 0;
fDownsamplingWidth = 0;
fDownsampleCount = 0;
// instantiate a BMediaFile object, and make sure there was no error.
/*BEntry entry("./song.wav");
entry_ref ref;
entry.GetRef(&ref);*/
BMediaFile* mediaFile = new BMediaFile(&ref);
status_t err = mediaFile->InitCheck();
if (err != B_OK) {
printf("cannot contruct BMediaFile object -- %s\n", strerror(err));
return err;
}
for (int32 i = 0; i < mediaFile->CountTracks(); i++) {
BMediaTrack* track = mediaFile->TrackAt(i);
if (track == NULL) {
printf("cannot contruct BMediaTrack object\n");
return B_ERROR;
}
media_format format;
format.type = B_MEDIA_RAW_AUDIO;
format.u.raw_audio.format = media_raw_audio_format::B_AUDIO_FLOAT;
err = track->DecodedFormat(&format);
if (err != B_OK) {
printf("BMediaTrack::DecodedFormat error -- %s\n", strerror(err));
return err;
}
if (format.type == B_MEDIA_RAW_AUDIO) {
// get the actual sourceWindow.left obtained by seeking
bigtime_t start = system_time();
int64 actualSeekFrame = fSourceWindow.left;
err = track->SeekToFrame(&actualSeekFrame);
if (err != B_OK) {
printf("BMediaTrack::SeekToFrame(%lli) error -- %s\n", fSourceWindow.left, strerror(err));
return err;
}
printf("BMediaTrack::SeekToFrame(%lli) seekedto=%lli in %llims\n", fSourceWindow.left, actualSeekFrame, (system_time() - start) / 1000);
fSourceWindow.left = actualSeekFrame;
frame_range destWindow(0, (uint64) fWaveFrame.Width());
int64 totalSourceFrameCount = track->CountFrames();
fDownsamplingWidth = fSourceWindow.Width() / destWindow.Width();
printf("Source window left=%lli right=%lli width=%lli (total=%lli)\n", fSourceWindow.left, fSourceWindow.right, fSourceWindow.Width(), totalSourceFrameCount);
printf("Dest window left=%lli right=%lli width=%lli\n", destWindow.left, destWindow.right, destWindow.Width());
printf("Downsampling width=%lli\n", fDownsamplingWidth);
delete [] fWave;
fWave = NULL;
fWave = new(std::nothrow) float[fSourceWindow.Width() / fDownsamplingWidth]; // ATT: on en prend plus que la largeur de dest car downsampling width entier
if (fWave == NULL)
return B_NO_MEMORY;
char* buffer = new(std::nothrow) char[format.u.raw_audio.buffer_size];
if (buffer == NULL)
return B_NO_MEMORY;
int64 readFrameCount = 0;
media_header mediaHeader;
fSourceCursor = fSourceWindow.left;
for(int64 j = 0; j < fSourceWindow.Width(); j += readFrameCount) {
err = track->ReadFrames(buffer, &readFrameCount, &mediaHeader);
if (err) {
printf("BMediaTrack::ReadFrames error -- %s\n", strerror(err));
delete [] buffer;
break;
// TODO fatal error?
}
if (fSourceCursor + readFrameCount >= fSourceWindow.right) {
readFrameCount = fSourceWindow.right - fSourceCursor;
printf("yes readFrameCount = %lli\n", readFrameCount);
}
_ProcessAudio(buffer, &format, readFrameCount);
}
printf("Source cursor %li (read %li)\n", fSourceCursor, fSourceCursor - fSourceWindow.left);
printf("Dest cursor %li\n", fDestCursor);
delete [] buffer;
}
mediaFile->ReleaseTrack(track);
}
delete mediaFile;
//.........这里部分代码省略.........
示例3: if
int32
MediaView::MediaPlayer(
void *arg)
{
MediaView* view = (MediaView *)arg;
BWindow* window = view->Window();
BBitmap* bitmap = view->fBitmap;
BMediaTrack* videoTrack = view->fVideoTrack;
BMediaTrack* audioTrack = view->fAudioTrack;
BMediaTrack* counterTrack = (videoTrack != NULL) ? videoTrack : audioTrack;
AudioOutput* audioOutput = view->fAudioOutput;
void* adBuffer = view->fAudioDumpingBuffer;
int64 numFrames = counterTrack->CountFrames();
int64 numFramesToSkip = 0;
int64 numSkippedFrames = 0;
bool scrubbing = false;
bool seekNeeded = false;
int64 dummy;
media_header mh;
bigtime_t vStartTime, aStartTime, seekTime, snoozeTime, startTime;
bigtime_t curScrubbing, lastScrubbing, lastTime;
curScrubbing = lastScrubbing = system_time();
seekTime = 0LL;
// Main processing loop (handle stop->start->stop)
while (acquire_sem(view->fPlaySem) == B_OK) {
release_sem(view->fPlaySem);
// as we are doing stop->start, restart audio if needed.
if (audioTrack != NULL)
audioOutput->Play();
startTime = system_time()-counterTrack->CurrentTime();
// This will loop until the end of the stream
while ((counterTrack->CurrentFrame() < numFrames) || scrubbing) {
// We are in scrub mode
if (acquire_sem(view->fScrubSem) == B_OK) {
curScrubbing = system_time();
// We are entering scrub mode
if (!scrubbing) {
if (audioTrack != NULL)
audioOutput->Stop();
scrubbing = true;
}
// Do a seek.
seekNeeded = true;
seekTime = view->fScrubTime;
}
// We are not scrubbing
else if (scrubbing) {
if (audioTrack != NULL)
audioOutput->Play();
scrubbing = false;
}
// Handle seeking
if (seekNeeded) {
if (videoTrack) {
// Seek the seekTime as close as possible
vStartTime = seekTime;
videoTrack->SeekToTime(&vStartTime);
// Read frames until we get less than 50ms ahead.
lastTime = vStartTime;
do {
bitmap->LockBits();
status_t err = videoTrack->ReadFrames((char*)bitmap->Bits(), &dummy, &mh);
bitmap->UnlockBits();
if (err != B_OK) break;
vStartTime = mh.start_time;
if ((dummy == 0) || (vStartTime <= lastTime))
break;
lastTime = vStartTime;
} while (seekTime - vStartTime > 50000);
}
if (audioTrack) {
// Seek the extractor as close as possible
aStartTime = seekTime;
audioOutput->SeekToTime(&aStartTime);
// Read frames until we get less than 50ms ahead.
lastTime = aStartTime;
while (seekTime - aStartTime > 50000) {
if (audioTrack->ReadFrames((char *)adBuffer, &dummy, &mh) != B_OK)
break;
aStartTime = mh.start_time;
if ((dummy == 0) || (aStartTime <= lastTime))
break;
lastTime = aStartTime;
}
}
else startTime = system_time() - vStartTime;
// Set the current time
view->fCurTime = seekTime;
//.........这里部分代码省略.........
示例4: audioDone
status_t
MediaFileInfo::LoadInfo(BMediaFile* file)
{
_Reset();
if (!file)
return B_BAD_VALUE;
BMediaTrack* track;
media_format format;
memset(&format, 0, sizeof(format));
media_codec_info codecInfo;
bool audioDone(false), videoDone(false);
bigtime_t audioDuration = 0;
bigtime_t videoDuration = 0;
int32 tracks = file->CountTracks();
int64 videoFrames = 0;
int64 audioFrames = 0;
status_t ret = B_OK;
for (int32 i = 0; i < tracks && (!audioDone || !videoDone); i++) {
track = file->TrackAt(i);
if (track == NULL)
return B_ERROR;
ret = track->InitCheck();
if (ret != B_OK)
return ret;
ret = track->EncodedFormat(&format);
if (ret != B_OK)
return ret;
if (format.IsVideo()) {
memset(&format, 0, sizeof(format));
format.type = B_MEDIA_RAW_VIDEO;
ret = track->DecodedFormat(&format);
if (ret != B_OK)
return ret;
media_raw_video_format *rvf = &(format.u.raw_video);
ret = track->GetCodecInfo(&codecInfo);
if (ret != B_OK)
return ret;
video.format << codecInfo.pretty_name;
videoDuration = track->Duration();
videoFrames = track->CountFrames();
BString details;
snprintf(details.LockBuffer(256), 256,
B_TRANSLATE_COMMENT("%u x %u, %.2ffps / %Ld frames",
"Width x Height, fps / frames"),
format.Width(), format.Height(),
rvf->field_rate / rvf->interlace, videoFrames);
details.UnlockBuffer();
video.details << details;
videoDone = true;
} else if (format.IsAudio()) {
memset(&format, 0, sizeof(format));
format.type = B_MEDIA_RAW_AUDIO;
ret = track->DecodedFormat(&format);
if (ret != B_OK)
return ret;
media_raw_audio_format *raf = &(format.u.raw_audio);
char bytesPerSample = (char)(raf->format & 0xf);
BString details;
if (bytesPerSample == 1 || bytesPerSample == 2) {
snprintf(details.LockBuffer(16), 16,
B_TRANSLATE("%d bit "), bytesPerSample * 8);
} else {
snprintf(details.LockBuffer(16), 16,
B_TRANSLATE("%d byte "), bytesPerSample);
}
details.UnlockBuffer();
audio.details << details;
ret = track->GetCodecInfo(&codecInfo);
if (ret != B_OK)
return ret;
audio.format << codecInfo.pretty_name;
audioDuration = track->Duration();
audioFrames = track->CountFrames();
BString channels;
if (raf->channel_count == 1) {
snprintf(channels.LockBuffer(64), 64,
B_TRANSLATE("%.1f kHz mono / %lld frames"),
raf->frame_rate / 1000.f, audioFrames);
} else if (raf->channel_count == 2) {
snprintf(channels.LockBuffer(64), 64,
B_TRANSLATE("%.1f kHz stereo / %lld frames"),
raf->frame_rate / 1000.f, audioFrames);
} else {
snprintf(channels.LockBuffer(64), 64,
B_TRANSLATE("%.1f kHz %ld channel / %lld frames"),
raf->frame_rate / 1000.f, raf->channel_count, audioFrames);
//.........这里部分代码省略.........
示例5: sizeof
//.........这里部分代码省略.........
ret = B_ERROR;
}
if (fCancel) {
// don't have any video or audio tracks here, or cancelled
printf("MediaConverterApp::_ConvertFile()"
" - user canceled before transcoding\n");
ret = B_CANCELED;
}
if (ret < B_OK) {
delete[] audioBuffer;
delete[] videoBuffer;
delete outFile;
return ret;
}
outFile->CommitHeader();
// this is where you would call outFile->AddCopyright(...)
int64 framesRead;
media_header mh;
int32 lastPercent, currPercent;
float completePercent;
BString status;
int64 start;
int64 end;
int32 stat = 0;
// read video from source and write to destination, if necessary
if (outVidTrack != NULL) {
lastPercent = -1;
videoFrameCount = inVidTrack->CountFrames();
if (endDuration == 0 || endDuration < startDuration) {
start = 0;
end = videoFrameCount;
} else {
inVidTrack->SeekToTime(&endDuration, stat);
end = inVidTrack->CurrentFrame();
inVidTrack->SeekToTime(&startDuration, stat);
start = inVidTrack->CurrentFrame();
if (end > videoFrameCount)
end = videoFrameCount;
if (start > end)
start = 0;
}
framesRead = 0;
for (int64 i = start; (i <= end) && !fCancel; i += framesRead) {
if ((ret = inVidTrack->ReadFrames(videoBuffer, &framesRead,
&mh)) != B_OK) {
fprintf(stderr, "Error reading video frame %" B_PRId64 ": %s\n", i,
strerror(ret));
snprintf(status.LockBuffer(128), 128,
B_TRANSLATE("Error read video frame %" B_PRId64), i);
status.UnlockBuffer();
SetStatusMessage(status.String());
break;
}
if ((ret = outVidTrack->WriteFrames(videoBuffer, framesRead,
mh.u.encoded_video.field_flags)) != B_OK) {
fprintf(stderr, "Error writing video frame %" B_PRId64 ": %s\n", i,
strerror(ret));