本文整理汇总了C++中AP4_Sample::IsSync方法的典型用法代码示例。如果您正苦于以下问题:C++ AP4_Sample::IsSync方法的具体用法?C++ AP4_Sample::IsSync怎么用?C++ AP4_Sample::IsSync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AP4_Sample
的用法示例。
在下文中一共展示了AP4_Sample::IsSync方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fprintf
/*----------------------------------------------------------------------
| AutoDetectFragmentDuration
+---------------------------------------------------------------------*/
static unsigned int
AutoDetectFragmentDuration(TrackCursor* cursor)
{
AP4_Sample sample;
unsigned int sample_count = cursor->m_Samples->GetSampleCount();
// get the first sample as the starting point
AP4_Result result = cursor->m_Samples->GetSample(0, sample);
if (AP4_FAILED(result)) {
fprintf(stderr, "ERROR: failed to read first sample\n");
return 0;
}
if (!sample.IsSync()) {
fprintf(stderr, "ERROR: first sample is not an I frame\n");
return 0;
}
for (unsigned int interval = 1; interval < sample_count; interval++) {
bool irregular = false;
unsigned int sync_count = 0;
unsigned int i;
for (i = 0; i < sample_count; i += interval) {
result = cursor->m_Samples->GetSample(i, sample);
if (AP4_FAILED(result)) {
fprintf(stderr, "ERROR: failed to read sample %d\n", i);
return 0;
}
if (!sample.IsSync()) {
irregular = true;
break;
}
++sync_count;
}
if (sync_count < 1) continue;
if (!irregular) {
// found a pattern
AP4_UI64 duration = sample.GetDts();
double fps = (double)(interval*(sync_count-1))/((double)duration/(double)cursor->m_Track->GetMediaTimeScale());
if (Options.verbosity > 0) {
printf("found regular I-frame interval: %d frames (at %.3f frames per second)\n",
interval, (float)fps);
}
return (unsigned int)(1000.0*(double)interval/fps);
}
}
return 0;
}
示例2: GetSampleDescription
/*----------------------------------------------------------------------
| AP4_Track::Clone
+---------------------------------------------------------------------*/
AP4_Track*
AP4_Track::Clone(AP4_Result* result)
{
AP4_SyntheticSampleTable* sample_table = new AP4_SyntheticSampleTable();
// default return value
if (result) *result = AP4_SUCCESS;
// add clones of the sample descriptions to the new sample table
for (unsigned int i=0; ;i++) {
AP4_SampleDescription* sample_description = GetSampleDescription(i);
if (sample_description == NULL) break;
sample_table->AddSampleDescription(sample_description->Clone());
}
AP4_Sample sample;
AP4_Ordinal index = 0;
while (AP4_SUCCEEDED(GetSample(index, sample))) {
AP4_ByteStream* data_stream;
data_stream = sample.GetDataStream();
sample_table->AddSample(*data_stream,
sample.GetOffset(),
sample.GetSize(),
sample.GetDuration(),
sample.GetDescriptionIndex(),
sample.GetDts(),
sample.GetCtsDelta(),
sample.IsSync());
AP4_RELEASE(data_stream); // release our ref, the table has kept its own ref.
index++;
}
// create the cloned track
AP4_Track* clone = new AP4_Track(GetType(),
sample_table,
GetId(),
GetMovieTimeScale(),
GetDuration(),
GetMediaTimeScale(),
GetMediaDuration(),
GetTrackLanguage(),
GetWidth(),
GetHeight());
return clone;
}
示例3: printf
/*----------------------------------------------------------------------
| ShowSample
+---------------------------------------------------------------------*/
static void
ShowSample(AP4_Sample& sample, unsigned int index, AP4_SampleDecrypter* sample_decrypter)
{
printf("[%06d] size=%6d duration=%6d",
index,
(int)sample.GetSize(),
(int)sample.GetDuration());
printf(" offset=%10lld dts=%10lld cts=%10lld ",
sample.GetOffset(),
sample.GetDts(),
sample.GetCts());
if (sample.IsSync()) {
printf(" [S] ");
} else {
printf(" ");
}
AP4_DataBuffer sample_data;
sample.ReadData(sample_data);
AP4_DataBuffer* data = &sample_data;
AP4_DataBuffer decrypted_sample_data;
if (sample_decrypter) {
sample_decrypter->DecryptSampleData(sample_data, decrypted_sample_data);
data = & decrypted_sample_data;
}
unsigned int show = data->GetDataSize();
if (show > 12) show = 12; // max first 12 chars
for (unsigned int i=0; i<show; i++) {
printf("%02x", data->GetData()[i]);
}
if (show == data->GetDataSize()) {
printf("\n");
} else {
printf("...\n");
}
}
示例4: input_file
//.........这里部分代码省略.........
fprintf(stderr, "ERROR: no audio, video, or subtitles track in the file\n");
return 1;
}
AP4_AvcSampleDescription* avc_desc = NULL;
if (video_track && (Options.force_i_frame_sync != AP4_FRAGMENTER_FORCE_SYNC_MODE_NONE)) {
// that feature is only supported for AVC
AP4_SampleDescription* sdesc = video_track->m_Track->GetSampleDescription(0);
if (sdesc) {
avc_desc = AP4_DYNAMIC_CAST(AP4_AvcSampleDescription, sdesc);
}
if (avc_desc == NULL) {
fprintf(stderr, "--force-i-frame-sync can only be used with AVC/H.264 video\n");
return 1;
}
}
// remember where the stream was
AP4_Position position;
input_stream->Tell(position);
// for fragmented input files, we need to populate the sample arrays
if (input_file.GetMovie()->HasFragments()) {
AP4_LinearReader reader(*input_file.GetMovie(), input_stream);
for (unsigned int i=0; i<cursors.ItemCount(); i++) {
reader.EnableTrack(cursors[i]->m_Track->GetId());
}
AP4_UI32 track_id;
AP4_Sample sample;
do {
result = reader.GetNextSample(sample, track_id);
if (AP4_SUCCEEDED(result)) {
for (unsigned int i=0; i<cursors.ItemCount(); i++) {
if (cursors[i]->m_Track->GetId() == track_id) {
cursors[i]->m_Samples->AddSample(sample);
break;
}
}
}
} while (AP4_SUCCEEDED(result));
} else if (video_track && (Options.force_i_frame_sync != AP4_FRAGMENTER_FORCE_SYNC_MODE_NONE)) {
AP4_Sample sample;
if (Options.force_i_frame_sync == AP4_FRAGMENTER_FORCE_SYNC_MODE_AUTO) {
// detect if this looks like an open-gop source
for (unsigned int i=1; i<video_track->m_Samples->GetSampleCount(); i++) {
if (AP4_SUCCEEDED(video_track->m_Samples->GetSample(i, sample))) {
if (sample.IsSync()) {
// we found a sync i-frame, assume this is *not* an open-gop source
Options.force_i_frame_sync = AP4_FRAGMENTER_FORCE_SYNC_MODE_NONE;
if (Options.debug) {
printf("this does not look like an open-gop source, not forcing i-frame sync flags\n");
}
break;
}
}
}
}
if (Options.force_i_frame_sync != AP4_FRAGMENTER_FORCE_SYNC_MODE_NONE) {
for (unsigned int i=0; i<video_track->m_Samples->GetSampleCount(); i++) {
if (AP4_SUCCEEDED(video_track->m_Samples->GetSample(i, sample))) {
if (IsIFrame(sample, avc_desc)) {
video_track->m_Samples->ForceSync(i);
}
}
}
}
}
// return the stream to its original position
input_stream->Seek(position);
// auto-detect the fragment duration if needed
if (auto_detect_fragment_duration) {
if (video_track) {
fragment_duration = AutoDetectFragmentDuration(video_track);
} else if (audio_track && input_file.GetMovie()->HasFragments()) {
fragment_duration = AutoDetectAudioFragmentDuration(*input_stream, audio_track);
}
if (fragment_duration == 0) {
if (Options.verbosity > 0) {
fprintf(stderr, "unable to autodetect fragment duration, using default\n");
}
fragment_duration = AP4_FRAGMENTER_DEFAULT_FRAGMENT_DURATION;
} else if (fragment_duration > AP4_FRAGMENTER_MAX_AUTO_FRAGMENT_DURATION) {
if (Options.verbosity > 0) {
fprintf(stderr, "auto-detected fragment duration too large, using default\n");
}
fragment_duration = AP4_FRAGMENTER_DEFAULT_FRAGMENT_DURATION;
}
}
// fragment the file
Fragment(input_file, *output_stream, cursors, fragment_duration, timescale, selected_track_id, create_segment_index);
// cleanup and exit
if (input_stream) input_stream->Release();
if (output_stream) output_stream->Release();
return 0;
}
示例5: mfra
//.........这里部分代码省略.........
target_dts = AP4_ConvertTime(fragment_duration*(anchor_position+1),
1000,
cursor->m_Track->GetMediaTimeScale());
} else {
target_dts = AP4_ConvertTime(anchor_cursor->m_Sample.GetDts(),
anchor_cursor->m_Track->GetMediaTimeScale(),
cursor->m_Track->GetMediaTimeScale());
if (target_dts <= cursor->m_Sample.GetDts()) {
// we must be at the end, past the last anchor sample, just use the target duration
target_dts = AP4_ConvertTime(fragment_duration*(cursor->m_FragmentIndex+1),
1000,
cursor->m_Track->GetMediaTimeScale());
if (target_dts <= cursor->m_Sample.GetDts()) {
// we're still behind, there may have been an alignment/rounding error, just advance by one segment duration
target_dts = cursor->m_Sample.GetDts()+AP4_ConvertTime(fragment_duration,
1000,
cursor->m_Track->GetMediaTimeScale());
}
}
}
unsigned int end_sample_index = cursor->m_Samples->GetSampleCount();
AP4_UI64 smallest_diff = (AP4_UI64)(0xFFFFFFFFFFFFFFFFULL);
AP4_Sample sample;
for (unsigned int i=cursor->m_SampleIndex+1; i<=cursor->m_Samples->GetSampleCount(); i++) {
AP4_UI64 dts;
if (i < cursor->m_Samples->GetSampleCount()) {
result = cursor->m_Samples->GetSample(i, sample);
if (AP4_FAILED(result)) {
fprintf(stderr, "ERROR: failed to get sample %d (%d)\n", i, result);
return;
}
if (!sample.IsSync()) continue; // only look for sync samples
dts = sample.GetDts();
} else {
result = cursor->m_Samples->GetSample(i-1, sample);
if (AP4_FAILED(result)) {
fprintf(stderr, "ERROR: failed to get sample %d (%d)\n", i-1, result);
return;
}
dts = sample.GetDts()+sample.GetDuration();
}
AP4_SI64 diff = dts-target_dts;
AP4_UI64 abs_diff = diff<0?-diff:diff;
if (abs_diff < smallest_diff) {
// this sample is the closest to the target so far
end_sample_index = i;
smallest_diff = abs_diff;
}
if (diff >= 0) {
// this sample is past the target, it is not going to get any better, stop looking
break;
}
}
if (cursor->m_Eos) continue;
if (Options.debug) {
if (cursor == anchor_cursor) {
printf("====");
} else {
printf("----");
}
printf(" Track ID %d - dts=%lld, target=%lld, start=%d, end=%d/%d\n",
cursor->m_Track->GetId(),
cursor->m_Sample.GetDts(),
示例6: GetSampleCount
/*----------------------------------------------------------------------
| AP4_SampleTable::GenerateStblAtom
+---------------------------------------------------------------------*/
AP4_Result
AP4_SampleTable::GenerateStblAtom(AP4_ContainerAtom*& stbl)
{
// create the stbl container
stbl = new AP4_ContainerAtom(AP4_ATOM_TYPE_STBL);
// create the stsd atom
AP4_StsdAtom* stsd = new AP4_StsdAtom(this);
// create the stsz atom
AP4_StszAtom* stsz = new AP4_StszAtom();
// create the stsc atom
AP4_StscAtom* stsc = new AP4_StscAtom();
// create the stts atom
AP4_SttsAtom* stts = new AP4_SttsAtom();
// create the stss atom
AP4_StssAtom* stss = new AP4_StssAtom();
// declare the ctts atom (may be created later)
AP4_CttsAtom* ctts = NULL;
// start chunk table
AP4_Ordinal current_chunk_index = 0;
AP4_Size current_chunk_size = 0;
AP4_Position current_chunk_offset = 0;
AP4_Cardinal current_samples_in_chunk = 0;
AP4_Ordinal current_sample_description_index = 0;
AP4_UI32 current_duration = 0;
AP4_Cardinal current_duration_run = 0;
AP4_UI32 current_cts_delta = 0;
AP4_Cardinal current_cts_delta_run = 0;
AP4_Array<AP4_Position> chunk_offsets;
// process all the samples
bool all_samples_are_sync = false;
AP4_Cardinal sample_count = GetSampleCount();
for (AP4_Ordinal i=0; i<sample_count; i++) {
AP4_Sample sample;
GetSample(i, sample);
// update DTS table
AP4_UI32 new_duration = sample.GetDuration();
if (new_duration != current_duration && current_duration_run != 0) {
// emit a new stts entry
stts->AddEntry(current_duration_run, current_duration);
// reset the run count
current_duration_run = 0;
}
++current_duration_run;
current_duration = new_duration;
// update CTS table
AP4_UI32 new_cts_delta = sample.GetCtsDelta();
if (new_cts_delta != current_cts_delta && current_cts_delta_run != 0) {
// create a ctts atom if we don't have one
if (ctts == NULL) ctts = new AP4_CttsAtom();
//emit a new ctts entry
ctts->AddEntry(current_cts_delta_run, current_cts_delta);
// reset the run count
current_cts_delta_run = 0;
}
++current_cts_delta_run;
current_cts_delta = new_cts_delta;
// add an entry into the stsz atom
stsz->AddEntry(sample.GetSize());
// update the sync sample table
if (sample.IsSync()) {
stss->AddEntry(i+1);
if (i==0) all_samples_are_sync = true;
} else {
all_samples_are_sync = false;
}
// see in which chunk this sample is
AP4_Ordinal chunk_index = 0;
AP4_Ordinal position_in_chunk = 0;
AP4_Result result = GetSampleChunkPosition(i, chunk_index, position_in_chunk);
if (AP4_SUCCEEDED(result)) {
if (chunk_index != current_chunk_index && current_samples_in_chunk != 0) {
// new chunk
chunk_offsets.Append(current_chunk_offset);
current_chunk_offset += current_chunk_size;
stsc->AddEntry(1,
current_samples_in_chunk,
current_sample_description_index+1);
current_samples_in_chunk = 0;
current_chunk_size = 0;
//.........这里部分代码省略.........