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

Audio seg duration #153

Open
elv-reza opened this issue Oct 27, 2023 · 5 comments
Open

Audio seg duration #153

elv-reza opened this issue Oct 27, 2023 · 5 comments
Assignees

Comments

@elv-reza
Copy link

elv-reza commented Oct 27, 2023

The function calcSegDuration() has a bug in setting audio seg duration.

 calcSegDuration({sourceTimescale}) {

    let videoStream = this.getStreamDataForCodecType("video");
    let frameRate = videoStream.frame_rate;

    let seg ={};
    switch (frameRate) {
      case "24":
        seg.video = 30 * sourceTimescale;
        seg.audio = 30 * 48000;
        seg.keyint = 48;
        seg.duration = "30";
        break;
      case "25":
        seg.video = 30 * sourceTimescale;
        seg.audio = 30 * 48000;
        seg.keyint = 50;
        seg.duration = "30";
        break;
      case "30":
        seg.video = 30 * sourceTimescale;
        seg.audio = 30 * 48000;
        seg.keyint = 60;
        seg.duration = "30";
        break;
      case "30000/1001":
        seg.video = 30.03 * sourceTimescale;
        seg.audio = 29.76 * 48000;
        seg.keyint = 60;
        seg.duration = "30.03";
        break;
      case "48":
        seg.video = 30 * sourceTimescale;
        seg.audio = 30 * 48000;
        seg.keyint = 96;
        seg.duration = "30";
        break;
      case "50":
        seg.video = 30 * sourceTimescale;
        seg.audio = 30 * 48000;
        seg.keyint = 100;
        seg.duration = "30";
        break;
      case "60":
        seg.video = 30 * sourceTimescale;
        seg.audio = 30 * 48000;
        seg.keyint = 120;
        seg.duration = "30";
        break;
      case "60000/1001":
        seg.video = 30.03 * sourceTimescale;
        seg.audio = 29.76 * 48000;
        seg.keyint = 120;
        seg.duration = "30.03";
        break;
      default:
        console.log("Unsupported frame rate", frameRate);
        break;
    }
    return seg;
  }

The function can simply set the audio seg duration to 29.76 * 48000 for all the cases as follows. Notice that the audio seg duration does not have dependency to video frame rate at all and must not be determined by that.

 calcSegDuration({sourceTimescale}) {

    let videoStream = this.getStreamDataForCodecType("video");
    let frameRate = videoStream.frame_rate;

    let seg ={};
    seg.audio = 29.76 * 48000;

    switch (frameRate) {
      case "24":
        seg.video = 30 * sourceTimescale;
        seg.keyint = 48;
        seg.duration = "30";
        break;
      case "25":
        seg.video = 30 * sourceTimescale;
        seg.keyint = 50;
        seg.duration = "30";
        break;
      case "30":
        seg.video = 30 * sourceTimescale;
        seg.keyint = 60;
        seg.duration = "30";
        break;
      case "30000/1001":
        seg.video = 30.03 * sourceTimescale;
        seg.keyint = 60;
        seg.duration = "30.03";
        break;
      case "48":
        seg.video = 30 * sourceTimescale;
        seg.keyint = 96;
        seg.duration = "30";
        break;
      case "50":
        seg.video = 30 * sourceTimescale;
        seg.keyint = 100;
        seg.duration = "30";
        break;
      case "60":
        seg.video = 30 * sourceTimescale;
        seg.keyint = 120;
        seg.duration = "30";
        break;
      case "60000/1001":
        seg.video = 30.03 * sourceTimescale;
        seg.keyint = 120;
        seg.duration = "30.03";
        break;
      default:
        console.log("Unsupported frame rate", frameRate);
        break;
    }
    return seg;
  }

linke to the code:

calcSegDuration({sourceTimescale}) {

@elv-gerald
Copy link
Contributor

added these changes with #154

@elv-reza
Copy link
Author

elv-reza commented Oct 27, 2023

@elv-gerald, @elv-zenia The above solution that I gave is very simple and it covers most of the use cases that we have. But to cover all the cases we need more work to be done.

  • When you probe the input stream you obtain input_sample_rate for audio. If the input audio is AAC and input_sample_rate is in {8000, 12000, 16000, 22050, 24000, 32000, 44100, 48000, 88200, 96000} then we use the input_sample_rate and set sample_rate = input_sample_rate.
  • Otherwise we set sample_rate = 48000
  • Now audio seg duration is calculated by: audio_seg_duration = 29.76 * sample_rate
  • Notice that input stream might have multiple audio streams, in above input_sample_rate refers to sample rate of selected audio stream (i.e index 1 or 2 ...).

This should cover all the cases and we need to test it with many different input streams (close the issue after testing).

@elv-reza elv-reza reopened this Oct 27, 2023
@elv-gerald
Copy link
Contributor

Does the above apply to both udp and rtmp?

@elv-reza
Copy link
Author

Applies to both.

@elv-zenia
Copy link
Contributor

Will make other necessary changes but for now, updated the live stream app to use the fixed value 29.76 * 48000. Deployed on demo, prod-dev, and prod.

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

3 participants