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

stsc: single entry #313

Closed
3052 opened this issue Jan 7, 2024 · 2 comments
Closed

stsc: single entry #313

3052 opened this issue Jan 7, 2024 · 2 comments

Comments

@3052
Copy link

3052 commented Jan 7, 2024

some code like this seems to work fine:

inMp4, err := mp4.DecodeFile(src)
if err != nil {
   panic(err)
}
inMp4.Moov.Trak.Mdia.Minf.Stbl.Stco.ChunkOffset = []uint32{40}
inMp4.Moov.Trak.Mdia.Minf.Stbl.Stsc.Entries = []mp4.StscEntry{
   {
      FirstChunk  : 1,
      SamplesPerChunk : 14416,
   },
}
if err := inMp4.Encode(dst); err != nil {
   panic(err)
}

where the above basically dumps all the samples into a single chunk. the resulting file seems to be fine, I tested with FFmpeg, MPC-HC, and Firefox. maybe this is off topic, but I was just wondering if using a single chunk has some drawback. I checked the standard, and this is literally all it says:

Samples within the media data are grouped into chunks. Chunks can be of different sizes, and the samples within a chunk can have different sizes. This table can be used to find the chunk that contains a sample, its position, and the associated sample description.

The table is compactly coded. Each entry gives the index of the first chunk of a run of chunks with the same characteristics. By subtracting one entry here from the previous one, it is possible to compute how many chunks are in this run. This can be converted to a sample count by multiplying by the appropriate samples-per-chunk.

samples_per_chunk is an integer that gives the number of samples in each of these chunks

@tobbee
Copy link
Collaborator

tobbee commented Jan 8, 2024

Yeah, if you have a file with a single media, you should be able to make a big chunk instead of having a lot of consecutive small chunks. As you have done, you need to adjust the offset of that single chunk. All the other values like sample sizes, and durations are not influenced.

The only reason to have multiple chunks is for interleaving audio and video so that you can have a progressively playable file where you can start playing after you have received, e.g. 1s of audio and video.
If you only have video, the file is progressively playable anyway provided that the moov box is at the start.

Nice that you found a good solution.

@3052 3052 mentioned this issue Jan 8, 2024
@3052
Copy link
Author

3052 commented Jan 9, 2024

closing this, as it seems with a fragmented file, you can just leave the file fragmented, and have one big fragment, which should involve less code than converting a file to progressive

@3052 3052 closed this as completed Jan 9, 2024
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

2 participants