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

feat: get start number from muxer and specify initial sequence number #879

Merged
merged 10 commits into from
May 2, 2024

Conversation

sr1990
Copy link
Contributor

@sr1990 sr1990 commented Jan 9, 2021

@kqyang Have merged #818 and #519 by @sammirata along with the changes mentioned in #519.
Example:
../packager 'in=Sintel-1280x720.mp4,stream=video,init_segment=h264_1280p/init.mp4,segment_templa te=h264_1280p/$Number$.m4s' --mpd_output h264.mpd --mp4_initial_sequence_number 0
Please review and let me know.
Thanks.

@vish91
Copy link
Contributor

vish91 commented Jan 10, 2021

@sr1990 thanks for putting in PR. Initial testing looks good to me. I can try and run more variants if I get time.
Command:

./packager 'in=/home/vshah/shaka/sample.mp4,stream=video,init_segment=/tmp/shaka/dash/init.m4v,segment_template=/tmp/shaka/dash/output/sample/seg_$Number$.m4s' --segment_duration 6 --fragment_duration 6 --mp4_initial_sequence_number 0 --mpd_output /home/vshah/shaka/output/stream-sr1990.mpd
<SegmentTemplate timescale="12800" initialization="/tmp/shaka/dash/init.m4v" 
   media="/tmp/shaka/dash/output/sample/seg_$Number$.m4s" startNumber="0">

@jigneshdhruv
Copy link

@kqyang Do you think this PR can be merged? Our initial testing looks good. We are waiting on this patch do deliver dash manifest to ps4 devices. Thanks.

@sr1990 sr1990 changed the title Getting start number from muxer and specify initial sequence number though option. [DASH] Getting start number from muxer and specify initial sequence number though option. Jan 15, 2021
@@ -17,3 +17,8 @@ MP4 output options
template).

Default enabled.

--mp4_initial_sequence_number
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this feature. Here is my high level feedback.

There are two concepts in this CL.

  1. mp4_initial_sequence_number which specifies the initial sequence number in moof->mfhd.

  2. the starting segment index.

They are different concepts. They may not have the same value as a segment can contain multiple fragments.

Can we have a separate flag for segment index, e.g. start_segment_number to match the startNumber in DASH SegmentTemplate?

I think we can remove the initial sequence number from this PR (or move it to a separate PR).

I also think that it can be a ChunkingParam as it is not restricted to mp4.

Copy link
Contributor Author

@sr1990 sr1990 Jan 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback.
They are different concepts. They may not have the same value as a segment can contain multiple fragments.
You are right. My mistake. What is the use-case for specifying moof->mfhd sequence number?
I do not see exoplayer's FragmentedMp4Extractor.java parsing it
https://github.com/google/ExoPlayer/blob/03263db378392385e290c40505d80e990c85a5cb/library/extractor/src/main/java/com/google/android/exoplayer2/extractor/mp4/FragmentedMp4Extractor.java#L708

Can we have a separate flag for segment index, e.g. start_segment_number 
to match the startNumber in DASH SegmentTemplate?
I also think that it can be a ChunkingParam as it is not restricted to mp4.

Yes that makes sense. Will look into it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the use-case for specifying moof->mfhd sequence number?

I don't really know. None of the players and devices I know care about the sequence number in mfhd. That is actually the question I have in the original PR (#270) too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that makes sense.. we can keep it out. I don't know of use-cases either where it would be needed to change the initial sequence number of moof -> mfhd.
From what I understand was that segment index start should be enough to fix console platform issues and align us with the DASH spec, that should be the only validation happening player side. Beyond that it just uses either index ranges or the indexed fragmented files from origin for delivery.

@sr1990
Copy link
Contributor Author

sr1990 commented Jan 31, 2021

@vish91, @kqyang, I have added a start_segment_number flag to indicate startNumber in SegmentTemplate.
Example:

../packager \                                                                   
  'in=bear-640x360.mp4,stream=video,init_segment=bear_360p/init.mp4,segment_template=bear_360p/$Number$.m4s' \
  'in=bear-640x360.mp4,stream=audio,init_segment=bear_audio/init.mp4,segment_template=bear_audio/$Number$.m4s' \
  'in=bear-english-text.vtt,stream=text,init_segment=bear_text/init.mp4,segment_template=bear_text/$Number$.m4s' \
  --mpd_output bear.mpd --generate_static_live_mpd --start_segment_number 0

Please review and let me know.

Copy link
Contributor

@kqyang kqyang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating the code. It looks mostly good.

I left a number of comments, with most of them as formatting issues.

As I have suggested in your earlier PRs, you can use clang-format to format the code properly:

$ git clang-format

If HEAD^ is the original commit:

$ git clang-format HEAD^


--start_segment_number

Indicates the startNumber in DASH SegmentTemplate.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically it applies to HLS as well. Can we rephrase it to something like:

Indicates the startNumber in DASH SegmentTemplate and HLS segment name.

Same elsewhere.

Comment on lines 332 to 335
if (chunking_params.start_segment_number < 0) {
LOG(ERROR) << "Negative --start_segment_number not allowed.";
return base::nullopt;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check should be moved to packager.cc, e.g. in ValidateParams

@@ -478,7 +478,8 @@ def _GetFlags(self,
default_language=None,
segment_duration=1.0,
use_fake_clock=True,
allow_codec_switching=False):
allow_codec_switching=False,
start_segment_number=-1):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use None to indicate that it is not set:

start_segment_number=None

Comment on lines 792 to 793
self.assertPackageSuccess(streams, self._GetFlags(output_dash=True,
start_segment_number=0))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you align it properly?

@@ -49,7 +49,7 @@ Status TextMuxer::Finalize() {

muxer_listener()->OnNewSegment(
options().output_file_name, 0,
duration_seconds * streams()[0]->time_scale(), size);
duration_seconds * streams()[0]->time_scale(), size, 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you define a named constant or add a comment here for better readability?

e.g.

// The segment index does not matter for single segment output.
const uint32_t kArbitrarySegmentIndex = 0;

OnNewSegment(....,, kArbitrarySegmentIndex);

// startNumber attribute for SegmentTemplate.
// Starts from 1.
uint32_t start_number_ = 1;
bool stream_just_started_ = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it part of this this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed it.

Comment on lines 459 to 460
if (start_segment_index_ == -1)
start_segment_index_ = start_time / duration;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Removed it.

Comment on lines 156 to 158
segment_info->segment_index = current_segment_index_ +
num_segments_before_last_cue_ +
chunking_params_.start_segment_number - 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a potential behavior change.

  1. In the original code, the segment_index starts with 0 and is always monotonically increasing.
  2. In the new code, the segment_index is related to the segment timestamp.

Can we move the behavior change to a separate PR and focus this PR on start segment number?

So in this PR, we can just set the initial segment_index to chunking_params_.start_segment_number - 1 and increases by 1 for every new segment.

The comment applies to text_chunker below too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Let's do that.

TextChunker::TextChunker(double segment_duration_in_seconds,
int64_t start_segment_number)
: segment_duration_in_seconds_(segment_duration_in_seconds),
start_segment_number_(start_segment_number){};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs to be reformatted

@@ -42,7 +42,8 @@ class CombinedMuxerListener : public MuxerListener {
void OnNewSegment(const std::string& file_name,
int64_t start_time,
int64_t duration,
uint64_t segment_file_size) override;
uint64_t segment_file_size,
int64_t segment_index) override;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer segment_number so it matches with the file_name. What do you think? A number of files will need to be updated.

Copy link
Contributor Author

@sr1990 sr1990 Feb 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kqyang Do you prefer changing segment_index in struct SegmentInfo, SegmentEventInfo, and kSegmentIndex in unit tests to kSegmentNumberl? Or just the methods with file_name parameter in it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should. There should be as few unnecessary "+1" or "-1" as possible. (If I have overlooked anything, let me know)

Copy link
Contributor

@kqyang kqyang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

const char kSegment2Name[] = "memory://test_2.aac";
const char kSegment124Name[] = "memory://test_124.aac";
const char kSegment125Name[] = "memory://test_125.aac";
const int64_t kSegmentIndex123 = 123;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, didn't notice that. It is fine to keep it as is then.

@@ -271,8 +268,11 @@ base::Optional<xml::XmlNode> Representation::GetXml() {
}

if (HasLiveOnlyFields(media_info_) &&
!representation.AddLiveOnlyInfo(media_info_, segment_infos_,
start_number_)) {
!representation.AddLiveOnlyInfo(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or perhaps adding start_number only if segment_infos is not empty, e.g.

  if (media_info.has_segment_template_url() && !segment_infos.empty()) {

@@ -42,7 +42,8 @@ class CombinedMuxerListener : public MuxerListener {
void OnNewSegment(const std::string& file_name,
int64_t start_time,
int64_t duration,
uint64_t segment_file_size) override;
uint64_t segment_file_size,
int64_t segment_index) override;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should. There should be as few unnecessary "+1" or "-1" as possible. (If I have overlooked anything, let me know)

@vish91
Copy link
Contributor

vish91 commented Feb 10, 2021

Hey @sr1990 or @kqyang just noticed that we are also implementing HLS for this flag.
Would you know why or if that was a requirement for some scenario ?
Not worried since it's an optional flag but curious because for HLS I assumed players always look for the #EXT-X-MEDIA-SEQUENCE tag in playlist.https://tools.ietf.org/html/rfc8216#section-4.3.3.2

@sr1990
Copy link
Contributor Author

sr1990 commented Feb 11, 2021

@vish91 Looks like there is already a flag to specify EXT-X-MEDIA-SEQUENCE explicitly.
bldsoft@2584ffb
Maybe we can set it's value to start_segment_number if the stream is HLS. What do you think @kqyang?

packager/media/chunking/chunking_handler.cc Outdated Show resolved Hide resolved
packager/mpd/base/mock_mpd_notifier.h Outdated Show resolved Hide resolved
packager/mpd/base/representation.cc Outdated Show resolved Hide resolved
packager/mpd/base/xml/xml_node.cc Show resolved Hide resolved
@kqyang
Copy link
Contributor

kqyang commented Feb 16, 2021

Would you know why or if that was a requirement for some scenario ?

@vish91 Can you clarify what you mean? The current change does not affect the media sequence number.

@vish91 Looks like there is already a flag to specify EXT-X-MEDIA-SEQUENCE explicitly.
bldsoft@2584ffb
Maybe we can set it's value to start_segment_number if the stream is HLS. What do you think @kqyang?

Yes, there are overlaps. We could set the media sequence number to start_segment_number; we could also just keep them separate. I prefer having them separate for now to avoid affecting the current behavior.

@vish91
Copy link
Contributor

vish91 commented Feb 17, 2021

Yes, there are overlaps. We could set the media sequence number to start_segment_number; we could also just keep them separate. I prefer having them separate for now to avoid affecting the current behavior.

Yes agree. I prefer it separate as well.

Would you know why or if that was a requirement for some scenario ?
@vish91 Can you clarify what you mean? The current change does not affect the media sequence number.

I meant to ask do we even need a feature like this for HLS in first place ? since HLS uses the Media Sequence tag which already starts from 0 and isn't really affected by sequence ID on the segment name.
Or to put it in other words do we have an example of what will this flag start_segment_number do when applied on an HLS packager command ?

@vish91
Copy link
Contributor

vish91 commented Mar 23, 2021

@kqyang and @sr1990 please take a look when you have some time.

@sr1990
Copy link
Contributor Author

sr1990 commented Mar 24, 2021

@kqyang I have updated the PR to change segment number as 1 based. Please review and let me know. 

@sr1990 sr1990 requested a review from kqyang April 5, 2021 20:20
@ProIcons
Copy link

Looks good to me. And it would be useful when the packager restarts for any reason to "continue" from where it left off.
Also a good other solution would be the ability to define the segment offsetting in unix epoch timestamps.
While that would increase the manifest size, it would allow you in case of an interruption instead of resetting the offsets to 0 , to have them consecutively so you won't have to change periods on the manifest if you want to keep on streaming.

@Vinayk93
Copy link

When can we expect to be merged.

@joeyparrish
Copy link
Member

This can't be merged as-is. There are many merge conflicts, and that doesn't even account for the changes coming from the cmake branch when that work is complete.

Please be patient with us as we clean up and modernize the code, its dependencies, and its build system. Then we can work with PR authors to fix/reimplement their changes and merge them.

@cosmin cosmin changed the title [DASH] Getting start number from muxer and specify initial sequence number though option. feat: get start number from muxer and specify initial sequence number though option May 1, 2024
@cosmin cosmin changed the title feat: get start number from muxer and specify initial sequence number though option feat: get start number from muxer and specify initial sequence number May 1, 2024
@cosmin cosmin requested a review from joeyparrish May 1, 2024 04:47
@cosmin
Copy link
Contributor

cosmin commented May 1, 2024

I rebased this and made a few updates and all tests seem to pass locally.

@@ -575,6 +575,9 @@ def _GetFlags(self,
elif force_cl_index is False:
flags += ['--noforce_cl_index']

if start_segment_number:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe if start_segment_number is not None: so that a start number of 0 is permitted.

packager/app/test/packager_test.py Outdated Show resolved Hide resolved
@cosmin cosmin removed the request for review from kqyang May 2, 2024 20:24
@cosmin cosmin merged commit bb104fe into shaka-project:main May 2, 2024
35 checks passed
cosmin pushed a commit that referenced this pull request May 4, 2024
🤖 I have created a release *beep* *boop*
---


##
[3.1.0](v3.0.4...v3.1.0)
(2024-05-03)


### Features

* add missing DASH roles from ISO/IEC 23009-1 section 5.8.5.5
([#1390](#1390))
([fe885b3](fe885b3))
* get start number from muxer and specify initial sequence number
([#879](#879))
([bb104fe](bb104fe))
* teletext formatting
([#1384](#1384))
([4b5e80d](4b5e80d))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
@github-actions github-actions bot added the status: archived Archived and locked; will not be updated label Jul 1, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: archived Archived and locked; will not be updated
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants