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

Lossless trimming to avoid frozen frames at start of videos #9

Open
wants to merge 21 commits into
base: master
Choose a base branch
from

Conversation

chrominance
Copy link
Collaborator

This PR attempts to fix a few minor problems with nhk-record:

  • nhk-record attempts to cut an MPEG-TS stream at exact timestamps instead of on keyframes, and it does this in a naive fashion. This creates problems with the final file, where the first few frames of a video will be missing the prior keyframe and thus can appear to be "frozen" to the next available keyframe. This doesn't affect playback too much but it is noticeable, and can also affect the beginning of audio playback in extreme circumstances.
  • Sometimes nhk-record also snags the very end of the previous episode (or channel promos) when trimming. This is due to how the boundary detection works: nhk-record looks for silences and black-frame sections of the video stream, and then trims at the start point of a black-frame section. Sometimes ffmpeg will "detect" a black frame that isn't truly black, i.e. when the previous show fades to black.

To sum up the changes:

  • Following the implementation from other programs like Lossless Cut, we take the video stream and detect the keyframes right after the requested start point and right before the requested end point of an episode. Then we re-render the bits before the first keyframe and after the last keyframe, and do a stream copy of everything in between. Finally, we merge the three clips back together into one video.
  • The way the start point of an episode (and end point of an episode) is calculated has changed slightly; now, instead of taking the very beginning of a section of black frames as the cutpoint, we find a point in between (basically 25% of the interval between the beginning and the end of the detected blank section).

I've been running this version of nhk-record for several months now, fixing things along the way, and I think it's ready for wider use. That said, there's a lot going on here so no hard feelings if you'd rather decline this or don't have the time to review!

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.

1 participant