Skip to content
This repository has been archived by the owner on Nov 19, 2020. It is now read-only.

Bug fix for multi channel audio Signal #1992

Open
wants to merge 4 commits into
base: development
Choose a base branch
from

Conversation

Kjos
Copy link
Contributor

@Kjos Kjos commented Nov 22, 2019

Please disregard the changes to VideoFileReader. I'm pushing this from within Github and don't have the option to selectively create a PR.

The change in VideoFileWriter fixes a bug where sending a multi channel (2+) Signal will create noise as output. Since the unit test sends a 1 channel Signal to the video file, this wasn't caught.

Null will be returned when stream has finished. However with BitmapData null was not passed through. Checking on framecounter alone can lead to issues, so Bitmap should be returned even when using BitmapData.
Sample size was incorrect when Signal.channels was not 1.
The got_packet checks fails consistently at start when encoding with the H264 encoder. When this happens, the same frame is encoded several times avcodec_encode_video2. This will result in duplicated frames at start of the output video, as well as the error message "non monotonic PTS" for the first couple of frames.
Some more research might be required in how got_packet should be handled, however as I am experiencing myself, removing the check works better than leaving it (as the audio codec doesn't have this problem, audio and video will be unaligned)
@Kjos
Copy link
Contributor Author

Kjos commented Nov 22, 2019

Added got_packet check removal which was messing with PTS consistency

@Kjos
Copy link
Contributor Author

Kjos commented Nov 24, 2019

My hypothesis what seems to be happening with the got_packet check and the H264 encoder; it seems to be filling the buffer the first few frames and not wanting to spit out frames to the video file, as when got_packet check is removed, it will spit out frames but the end of the video will have frames missing (which are most likely still in the buffer, about 1 second regardless of video length).
I've tried flushing the buffer with av_interleaved_writeframe(oc, nullptr), but that doesn't resolve the issue. av_io_flush and av_codec_flush_buffers don't seem to resolve it either.
The summary log will announce the proper amount of frames written strangely.
Notably this problem doesn't occur for the audio, I figure because the buffer size is much smaller.

Flushes successfully for H264 video.
@Kjos
Copy link
Contributor Author

Kjos commented Nov 25, 2019

Added flushing. Tested with H264 video, seems to work fine. Might need to be moved to VideoFileWriter::Flush, but IMHO it's better in Close.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant