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

Video MP4 output #646

Merged

Conversation

WojciechBarczynski
Copy link
Member

@WojciechBarczynski WojciechBarczynski commented Jul 24, 2024

The video output works fine.
Opus audio fails to write file trailer and logs an invalid extradata size error.
I'll implement an AAC encoder in another PR and test it after.

Merging:
I created the @WojciechBarczynski/mp4 branch to which I'll merge all MP4 output-related PRs. Then I'll merge it to master without squashing.
PRs adding AAC encoder, MP4 outputs, etc. are large enough to be separate PRs/commits, but I don't want to merge to master before testing it out.

@WojciechBarczynski WojciechBarczynski self-assigned this Jul 24, 2024
@WojciechBarczynski WojciechBarczynski changed the base branch from master to @WojciechBarczynski/mp4 July 24, 2024 18:46
Copy link
Member Author

Choose a reason for hiding this comment

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

I'll refactor types once I know what is needed for AAC decoding.

@WojciechBarczynski WojciechBarczynski marked this pull request as ready for review July 24, 2024 18:56
Copy link
Member Author

Choose a reason for hiding this comment

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

This'll be modified in next PRs

@WojciechBarczynski WojciechBarczynski changed the title MP4 output Video MP4 output Jul 24, 2024
@WojciechBarczynski
Copy link
Member Author

I'll address review suggestions in the next PRs

@WojciechBarczynski WojciechBarczynski merged commit 0082b85 into @WojciechBarczynski/mp4 Jul 25, 2024
2 checks passed
@WojciechBarczynski WojciechBarczynski deleted the @WojciechBarczynski/add_mp4_output branch July 25, 2024 09:44
Comment on lines +61 to +63
std::thread::Builder::new()
.name(format!("mp4 writer thread for output {}", output_id))
.spawn(move || {
Copy link
Member Author

Choose a reason for hiding this comment

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

TODO: Add here log span

Copy link
Member

@wkozyra95 wkozyra95 left a comment

Choose a reason for hiding this comment

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

Usually when creating a feature branch that will later merged I would create a branch without @username prefix. I would expect branches like this to be open for cooperation.

I know that I also merge stuff like this without waiting for review, but I'm trying to do that only if:

  • I can't expect review withtin 1-2 days
  • I have already multiple PRs stacked one on the other
  • I have a reasonable expectation that there wont be any changes as a result of the review and they will be cosmetic.

Merging stuff too early even to your own branch is causing that some of the changes that should be in this PR will be part of the AAC PR or totally separate one. It's not a problem for cosmetic changes, but if it is significant it defeats the purpose of spliting this feature into separate PRs

@@ -34,6 +34,7 @@ pub use component::View;
pub use component::WebView;

pub use register_input::Mp4;
pub use register_output::Mp4Output;
Copy link
Member

Choose a reason for hiding this comment

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

If this is a user-facing value, use Mp4 too. If it not user-facing, I would rename input mp4 for consistency

@@ -93,7 +93,7 @@ fn run_encoder_thread(
let chunk = EncodedChunk {
data,
pts: batch.start_pts,
dts: None,
dts: Some(batch.start_pts),
Copy link
Member

Choose a reason for hiding this comment

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

why?

@@ -160,32 +173,36 @@ impl OutputOptionsExt<RawDataReceiver> for RawDataOutputOptions {
impl Output {
pub fn frame_sender(&self) -> Option<&Sender<PipelineEvent<Frame>>> {
match &self {
Output::Rtp { encoder, .. } => encoder.frame_sender(),
Output::EncodedData { encoder } => encoder.frame_sender(),
Output::Rtp { encoder, .. }
Copy link
Member

Choose a reason for hiding this comment

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

personal opinion(here and below), but I think is less readable than the previous version and very annoying when you need to change anything

Comment on lines +74 to +75
EncoderOutputEvent::AudioEOS => playing_streams -= 1,
EncoderOutputEvent::VideoEOS => playing_streams -= 1,
Copy link
Member

Choose a reason for hiding this comment

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

Storing whether EOS was received via number seems wrong, if semantically this is bool it either was received or not. I would use Option<bool> per stream where None represents no stream, Some(true) received EOS, Some(false) not EOS yet

EncoderOutputEvent::VideoEOS => playing_streams -= 1,
};

if playing_streams == 0 {
Copy link
Member

Choose a reason for hiding this comment

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

With above suggestion this would be

if received_audio_eos.unwrap_or(true) && eceived_video_eos.unwrap_or(true) {

.field("pts", &self.pts)
.field("dts", &self.dts)
.field("kind", &self.kind)
.finish()
Copy link
Member

Choose a reason for hiding this comment

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

I usually in overrides like this print len of the data that is not printed


#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
#[serde(deny_unknown_fields)]
pub struct OutputVideoOptions {
Copy link
Member

Choose a reason for hiding this comment

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

You can't unify those values, after you add AAC here it will be incorrect for RTP. Start by duplicating and unifying when you know you can support unified interface everywhere.

Copy link
Member Author

@WojciechBarczynski WojciechBarczynski Jul 26, 2024

Choose a reason for hiding this comment

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

  1. After implementing AAC I want to add support from AAC audio output in both: RTP and MP4
  2. I purposefully left types refactoring for later. AAC encoder has a lot of options and I need to test which of them should be available.
  3. Since writing opus audio into MP4 via FFmpeg didn't work and I couldn't easily debug it, I want to implement AAC encoding first, then debug what's wrong / test if it works with AAC, and modify types later on (maybe writing opus into MP4 won't be available).

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

Successfully merging this pull request may close these issues.

2 participants