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

FFmpeg Quirks in LPMS #275

Merged
merged 6 commits into from
Dec 6, 2021
Merged

FFmpeg Quirks in LPMS #275

merged 6 commits into from
Dec 6, 2021

Conversation

oscar-davids
Copy link
Contributor

This document outlines how LPMS tweaks FFmpeg transcoding pipeline to address some specific problems.

Copy link
Contributor

@jailuthra jailuthra left a comment

Choose a reason for hiding this comment

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

Would be good to have links and references to issues and PRs around these topics, as a time-saver for engineers who on-board later on.

QUIRKS.md Outdated

FPS filter expects monotonic increase in input frame's PTS. We cannot rely on the input to be monotonic thus:
i. Set a dummy PTS before the frame is sent into filtergraph, that we manually increase monotonically.
ii. OR use SETPTS filter in the filtergraph before FPS filter, which would do the same thing.
Copy link
Contributor

Choose a reason for hiding this comment

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

We should remove this from the documentation, as we did not take the approach of SETPTS filter due to reasons mentioned here #201 (comment)

QUIRKS.md Outdated

### Solution
To solve the flushing problem while still reusing the session, we introduced so called sentinel-packets. Sentinel packets are dummy frames with -1 timestamps. We insert these packets at the end of each segment to make sure that the packets that are sent to the buffer earlier always get popped out. We wait until we receive the sentinel packets pack and if we receive sentinel packet we know that this is the end of the segment.

Copy link
Contributor

@jailuthra jailuthra Nov 30, 2021

Choose a reason for hiding this comment

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

We should probably add links to the code snippet that implements this.
We can also note the fact that we give up flushing after sending SENTINEL_MAX packets, which is a pre-processor constant defined as 5 for now.

QUIRKS.md Outdated
Instead of erroring on such segments, let's accept them and send back audio-only tracks. The audio output should be exactly the same as the audio input.

### Our Solution
We bypass the usual transcoding process for audio-only segments and just return them back. To do this, we check if video frame is present, and if not present just copy the frames to the output as it is. The bypassing is done by forcing the copy transcoder https://github.com/livepeer/lpms/commit/8bc28e3f702049a17c24ab2041857a47d8af51bf for such segments.
Copy link
Contributor

Choose a reason for hiding this comment

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

While the by-pass check code is still implemented in LPMS we no longer use this function on the transcoder directly, or set the 'copy' encoder.

lpms/ffmpeg/extras.c

Lines 110 to 117 in 46f7030

// Bypass Check
// this is needed to handle streams that have first few segments that are
// audio-only (i.e. have a video stream but no frames)
// returns: 0 if both audio/video streams valid
// 1 for video with 0-frame, that needs bypass
// <0 invalid stream(s) or internal error
//
int lpms_is_bypass_needed(char *fname)

We instead moved the calling logic on the Broadcaster side in livepeer/go-livepeer#1933 and the document should reflect that.

@cyberj0g
Copy link
Contributor

cyberj0g commented Dec 3, 2021

Amazing write-up, @jailuthra @oscar-davids! Hijacking this branch to add a small section on reusing transcoding session with HW codecs. I believe much of the information on this is already in the document.

@jailuthra jailuthra merged commit 91b94f8 into master Dec 6, 2021
@yondonfu yondonfu deleted the oc/quirks branch December 6, 2021 13:45
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.

None yet

3 participants