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

[MM-53432] Improve recording start time accuracy #44

Merged
merged 14 commits into from
Nov 21, 2023
Merged

Conversation

streamer45
Copy link
Contributor

@streamer45 streamer45 commented Sep 14, 2023

Summary

PR improves the accuracy of the recording job start time so that it becomes a little easier to synchronize future transcriptions.
We do this by plugging into ffmpeg's progress log and send a ws event to the stream when the actual transcoding process starts.

Semantically the change is that a recording doesn't start any longer when the bot connects via websocket but when it sends this new job_started event since it could happen a few seconds later as the transcoding process needs a couple of seconds to initialize.

Other notable changes included here:

  • Start using the generic /data dir to store files. Same happens on the transcriber and it makes it just easier to generalize jobs at the offloader level.
  • Bumping Chromium (finally) to fix a recent SEGFAULT on Debian.
  • Generally tried to make the whole stop sequence a little more robust but still need to implement proper cancellation (MM-54485)

Ticket Link

https://mattermost.atlassian.net/browse/MM-53432

@streamer45 streamer45 added the 2: Dev Review Requires review by a core committer label Sep 14, 2023
@streamer45 streamer45 requested a review from cpoile September 14, 2023 22:32
@streamer45 streamer45 self-assigned this Sep 14, 2023
@streamer45 streamer45 added the Do Not Merge Should not be merged until this label is removed label Sep 14, 2023
@streamer45
Copy link
Contributor Author

To note, this requires a few more PRs to work (offloader, calls plugin and rtcd) but need to polish so many things so I am starting from the one with the fewer dependencies.

Copy link
Member

@cpoile cpoile left a comment

Choose a reason for hiding this comment

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

This is really nice, great work.

@@ -201,7 +228,58 @@ func (rec *Recorder) runBrowser(recURL string) error {
}

func (rec *Recorder) runTranscoder(dst string) error {
args := fmt.Sprintf(`-y -thread_queue_size 4096 -f alsa -i default -r %d -thread_queue_size 4096 -f x11grab -draw_mouse 0 -s %dx%d -i :%d -c:v h264 -preset %s -vf format=yuv420p -b:v %dk -b:a %dk -movflags +faststart %s`,
ln, err := net.Listen("unix", transcoderProgressSocketPath)
Copy link
Member

Choose a reason for hiding this comment

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

This whole method is pretty cool, I learned a lot. Thanks.

@@ -181,6 +201,13 @@ func (rec *Recorder) runBrowser(recURL string) error {
return nil
}
continue
case <-rec.transcoderStartedCh:
if err := chromedp.Run(ctx,
chromedp.Evaluate("window.callsClient?.ws?.send('job_started');", nil),
Copy link
Member

Choose a reason for hiding this comment

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

Clever

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Slightly too clever for my taste but it was the quickest way to achieve what I needed. I am actually thinking of redesigning this a bit and make a proper HTTP endpoint since we have another requirement to inform back the plugin side in case of pre-connection failures. Will think some more on this.

Comment on lines +259 to +260
n, err := conn.Read(buf)
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

So if I'm reading this correctly, we wait until the transcoder fills up one progress buffer, then we send out the started event? Just wondering if that will cause a timing mismatch (transcoding started, but there's a delay in sending out the started ws event), or is the delay so little it won't matter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, so the logic here is trivial, ffmpeg will output one progress line per processed video frame so we act as soon as we receive the first one. To be more accurate we could parse the actual output but so far I don't think it's needed.

And yes, there's always going to be some latency to account for but fortunately we are not looking for lip-sync accuracy here. Delay here should be a few milliseconds at most.

@cpoile cpoile added 3: Reviews Complete All reviewers have approved the pull request and removed 2: Dev Review Requires review by a core committer labels Sep 29, 2023
@streamer45 streamer45 removed the Do Not Merge Should not be merged until this label is removed label Nov 21, 2023
@streamer45 streamer45 merged commit e6ce35b into master Nov 21, 2023
@streamer45 streamer45 deleted the MM-53432 branch November 21, 2023 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3: Reviews Complete All reviewers have approved the pull request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants