Skip to content

recording: Fix processing hangs from seeking in screenshare files with video - #25252

Merged
antobinary merged 2 commits into
bigbluebutton:v3.0.x-developfrom
kepstin:rec-mixed-audio-video
Jun 11, 2026
Merged

antobinary merged 2 commits into
bigbluebutton:v3.0.x-developfrom
kepstin:rec-mixed-audio-video

Conversation

@kepstin

@kepstin kepstin commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

I discovered a recording which was hanging during audio processing following the gap removal changes in #24776. Upon investigation, I located two problems that could cause this issue:

  • When seeking in a screenshare recording file containing both audio and video, ffmpeg seeks to the nearest video frame (not audio frame), resulting in cases of seeking into gaps or past the end of the audio, both of which result in memory issues or recording processing hanging.
  • When determining the "end of file" gap, the duration of the media file is used, but the duration that actually matters is the time between the start and stop events in the BBB events.xml file.

To resolve this issues, I've done the following:

I've restored (corrected functionality of, and added where missing) the code the calculates "original_duration" for audio and video tracks in the EDL. This restores the functionality of some workarounds for legacy recording bugs (from BBB 0.9 and earlier), and I added code to forward the original duration to the gap detection logic to allow it to detect (and trim) more cases where there might be an EDL cut that tries to seek past the end of the media.

I've also added a step which extracts the audio from the screenshare recordings to a separate audio-only file. With the audio-only file, ffmpeg is forced to seek based on audio timestamps, and this avoids cases where ffmpeg would sometimes seek into audio gaps or past the end of the audio even tho the provided seek time was within a non-gap audio section.

How to test

Check is that recordings containing audio and video (especially recordings with screenshare audio) process without hanging, and verify that the audio is in sync.

The specific case that led me to discovering the bug was from a customer's live recording, and I am unable to share an example file which triggers the bug.

More

  • Added/updated documentation

@kepstin
kepstin requested a review from germanocaumo June 9, 2026 19:44
@coderabbitai

coderabbitai Bot commented Jun 9, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 31261c2f-d3bc-467a-95f7-fc57b7a2784c

📥 Commits

Reviewing files that changed from the base of the PR and between febaa97 and fb9e841.

📒 Files selected for processing (4)
  • record-and-playback/core/lib/recordandplayback/edl/audio.rb
  • record-and-playback/core/lib/recordandplayback/edl/video/video_source.rb
  • record-and-playback/core/lib/recordandplayback/generators/audio.rb
  • record-and-playback/core/lib/recordandplayback/generators/events.rb

Walkthrough

This PR implements original_duration tracking throughout the record-and-playback EDL pipeline. Event handlers record segment start/stop timestamps and compute original_durations for audio and video segments, attaching those values to EDL entries. During audio rendering, referenced files are probed, A/V inputs with video streams are remuxed to audio-only outputs, remux metadata is re-probed with original_duration preserved, and EDL filenames are rewritten. Downstream logic uses original_duration for gap detection, speed correction, and pts gap calculations.

Sequence Diagram(s)

sequenceDiagram
  participant Generator as EDL Generator
  participant Renderer as EDL Render
  participant Remuxer as FFmpeg Remux
  participant Probe as Metadata Probe
  Generator->>Renderer: Emit EDL entries (with original_duration when available)
  Renderer->>Probe: Probe referenced media files
  Probe-->>Renderer: Return streams/duration or mark corrupt
  Renderer->>Remuxer: Remux A/V inputs -> -audio.mkv
  Remuxer->>Probe: Re-probe remuxed outputs
  Probe-->>Renderer: Return remux metadata (carry original_duration)
  Renderer->>Renderer: Rewrite EDL audio filenames -> remuxed paths
  Renderer->>Generator: Use original_duration for gap/speed corrections
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested reviewers

  • germanocaumo
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: fixing processing hangs from seeking in screenshare files with video, which is the core problem addressed across all file modifications.
Description check ✅ Passed The description is directly related to the changeset, explaining the root causes (ffmpeg seeking to video frames, incorrect duration used for gap detection) and the solutions implemented (restoring original_duration calculations, extracting audio to separate files).
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
record-and-playback/core/lib/recordandplayback/generators/events.rb (1)

541-551: 💤 Low value

Line 543 is now dead code.

The condition at line 543 sets original_durations[filename] from the XML <duration> element, but line 551 unconditionally overwrites it with the timestamp-based calculation whenever a start time exists. This makes line 543's assignment dead code.

Based on the PR objectives (preferring event timestamps over media file duration), this appears intentional. Consider removing lines 542-543 to avoid confusion.

🧹 Suggested cleanup
         when %w[Deskshare DeskshareStoppedEvent], %w[bbb-webrtc-sfu StopWebRTCDesktopShareEvent]
           raise "Couldn't determine video filename" if filename.nil?

-          # Save the original duration of the deskshare video if provided (it will be added to the EDL later)
-          duration = event.at_xpath('duration')
-          original_durations[filename] = duration.content.to_i * 1000 if duration

           # Create a new EDL entry with the deskshare video removed
           last_entry = deskshare_edl.last
           new_entry = offset_entry.call(last_entry, timestamp - last_entry[:timestamp])
           new_entry[:timestamp] = timestamp
           new_entry[:areas][:deskshare].reject! { |file| file[:filename] == filename }
           deskshare_edl << new_entry
           original_durations[filename] = timestamp - start_times[filename] if start_times.include?(filename)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@record-and-playback/core/lib/recordandplayback/generators/events.rb` around
lines 541 - 551, The assignment that sets original_durations[filename] from the
XML duration node (the local variable duration and the line using
duration.content.to_i * 1000) is dead because later code unconditionally
overwrites original_durations[filename] using timestamp and start_times; remove
that duration-based assignment and its surrounding nil-check (the duration local
and the conditional that assigns to original_durations) in
recordandplayback/generators/events.rb so only the timestamp-based calculation
(the later original_durations[filename] = timestamp - start_times[filename])
remains; keep the rest of the block that builds new_entry via offset_entry,
updates deskshare_edl, and references start_times as-is.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@record-and-playback/core/lib/recordandplayback/generators/events.rb`:
- Around line 541-551: The assignment that sets original_durations[filename]
from the XML duration node (the local variable duration and the line using
duration.content.to_i * 1000) is dead because later code unconditionally
overwrites original_durations[filename] using timestamp and start_times; remove
that duration-based assignment and its surrounding nil-check (the duration local
and the conditional that assigns to original_durations) in
recordandplayback/generators/events.rb so only the timestamp-based calculation
(the later original_durations[filename] = timestamp - start_times[filename])
remains; keep the rest of the block that builds new_entry via offset_entry,
updates deskshare_edl, and references start_times as-is.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 92b01cdc-d919-430d-b6a0-13005c53089c

📥 Commits

Reviewing files that changed from the base of the PR and between a41d0b9 and febaa97.

📒 Files selected for processing (4)
  • record-and-playback/core/lib/recordandplayback/edl/audio.rb
  • record-and-playback/core/lib/recordandplayback/edl/video/video_source.rb
  • record-and-playback/core/lib/recordandplayback/generators/audio.rb
  • record-and-playback/core/lib/recordandplayback/generators/events.rb

Comment on lines +242 to +246
corrupt_audios << filename
out_filename = "#{process_dir}/#{File.basename(filename, '.*')}-audio.mkv"
extract_cmd = [*FFMPEG, '-copyts', '-i', filename, '-map', '0:a:0', '-c', 'copy', '-f', 'matroska', out_filename]
exitstatus = BigBlueButton.exec_ret(*extract_cmd)
next if exitstatus != 0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if the extraction fails, the original file will be removed from the edl, wouln't be better to fail the processing instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In general, we've decided that corrupt media files in recordings should cause the media to be dropped from the recording (but the recording should continue to process), and the only notable cases where this copy command could fail would be if the input file is corrupt, or if the server runs out of disk space (which will cause the processing to fail in a later step anyways)

@antobinary antobinary added this to the Release 3.0 milestone Jun 10, 2026
kepstin added 2 commits June 10, 2026 14:12
The "original_duration" property in the EDLs is present to provide a
way for the recording scripts to know what the duration of a recorded
media file, according to BigBlueButton as reported by events. But
following various refactoring of the EDL code, it was no longer
populated for audio files or most video files.

I've rearranged the format of the audio EDL so the original_duration
is tracked separately for each audio file (the original design assumed
only one audio file active at a time), and restored or corrected the
code which populates the original_duration field for both audio and
video files. The media file gap checking code is now passed the
original_duration field where available, allowing it to to a better job
of avoiding seeking past the end of an input file.
Files from deskshare can contain both audio and video, but due to
browser quirks and strange timing issues, there can be portions of the
file which contain either only audio or only video. The ffmpeg command
line tool always seeks based on video if video is present, even if
video processing is disabled using the '-vn' option, which causes some
issues (hangs) in recording processing on seeks which should be valid
for audio, but where ffmpeg ended up starting at different point in the
file.

The easiest way to fix this issue is to copy the audio out of the
deskshare files to a separate audio-only file, and use that as the input
for the audio processing.
@kepstin
kepstin force-pushed the rec-mixed-audio-video branch from febaa97 to fb9e841 Compare June 10, 2026 18:13
@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

🚨 Automated tests failed

@antobinary
antobinary merged commit 564efff into bigbluebutton:v3.0.x-develop Jun 11, 2026
32 of 33 checks passed
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.

3 participants