Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract key frames from fragment_buffer #1454

Open
baassisnos opened this issue Dec 4, 2024 · 0 comments
Open

Extract key frames from fragment_buffer #1454

baassisnos opened this issue Dec 4, 2024 · 0 comments

Comments

@baassisnos
Copy link

baassisnos commented Dec 4, 2024

System info

Operating System: Oracle Linux 9
Shaka Packager Version: 3.2.0

I would like to change the FinalizeSegment method of the segmenter.c class to save all key frames in key_frame_infos_ .

Ex:
FROM:

`

bool first_key_frame = true;
for (const std::unique_ptr<Fragmenter>& fragmenter : fragmenters_) {
// https://goo.gl/xcFus6 6. Trick play requirements
// 6.10. If using fMP4, I-frame segments must include the 'moof' header
// associated with the I-frame. It also implies that only the first key
// frame can be included.
if (!fragmenter->key_frame_infos().empty() && first_key_frame) {
  const KeyFrameInfo& key_frame_info =
      fragmenter->key_frame_infos().front();
  first_key_frame = false;
  key_frame_infos_.push_back(
      {key_frame_info.timestamp, moof_start_offset,
       fragment_buffer_->Size() - moof_start_offset + key_frame_info.size});
}
fragment_buffer_->AppendBuffer(*fragmenter->data());
  }`

TO:
`

for (const std::unique_ptr<Fragmenter>& fragmenter : fragmenters_) {
  for (const KeyFrameInfo& key_frame_info : fragmenter->key_frame_infos()) {
    if (key_frame_info.start_byte_offset > 0) {
        key_frame_infos_.push_back(
            {key_frame_info.timestamp, moof_start_offset + key_frame_info.start_byte_offset,
             fragment_buffer_->Size() - moof_start_offset + key_frame_info.size});
    } else {
        key_frame_infos_.push_back(
            {key_frame_info.timestamp, moof_start_offset,
             fragment_buffer_->Size() - moof_start_offset + key_frame_info.size});
    }
  }
  fragment_buffer_->AppendBuffer(*fragmenter->data());
}`

My intention is that in the WriteSegment method of the multi_segment_segmenter.c class I save these values ​​in a list as per the example below.
Ex:
FROM:
`

if (muxer_listener()) {
for (const KeyFrameInfo& key_frame_info : key_frame_infos()) {
  muxer_listener()->OnKeyFrame(
      key_frame_info.timestamp,
      segment_header_size + key_frame_info.start_byte_offset,
      key_frame_info.size);
}`

TO:
`

std::vector<std::pair<int, int>> iframe_list;
if (muxer_listener()) {
  int current_offset = segment_header_size;

  for (const KeyFrameInfo& key_frame_info : key_frame_infos()) {
    int key_frame_offset = current_offset + key_frame_info.start_byte_offset;

    muxer_listener()->OnKeyFrame(
        key_frame_info.timestamp,
        key_frame_offset,
        key_frame_info.size);

        iframe_list.emplace_back(key_frame_offset, key_frame_info.size);
    

  }
}	`

With this, I intend to perform a search on the final segment, extracting the key frames to a separate file.
The first key frame is extracted successfully, but I can't get the position of the second one right.
Can you see what I'm doing wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant