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

Fix recording of audio only or video only streams #1254

Closed

Conversation

nvazquezg
Copy link

Description

ExternalOutput was discarding streams that didn't have video and audio.
This commit enables the output for streams that have at least one of them.

This PR should solve issues #1203 and #1185.

[] It needs and includes Unit Tests

Changes in Client or Server public APIs

[] It includes documentation for these changes in /doc.

nvazquezg added 3 commits July 3, 2018 20:01
ExternalOutput was discarding streams that didn't have video and audio.
This commit enables the output for streams that have at least one stream.
@zafergurel
Copy link
Contributor

This fixes screensharing and audio recording.
But it breaks video recording.
The following error occurs in the logs:

Only audio, video, and subtitles are supported for Matroska

The result recording file includes just audio data when webcam is shared.

context_->streams[0] = video_stream_;
// TODO(nvazquezg): this 'if' is to avoid a matroska error when no video available: 'Invalid packet stream index: 1'
if (!init_video) {
context_->streams[0] = avformat_new_stream(context_, nullptr);
Copy link
Contributor

@kekkokk kekkokk Jul 9, 2018

Choose a reason for hiding this comment

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

This is quite ugly

I would rather set global var hasAudio and hasVideo and set the correct index when writing the packet:

av_packet.stream_index = 1;

and
av_packet.stream_index = 0;

Copy link
Author

Choose a reason for hiding this comment

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

Couldn't agree more, I'll try with a global hasAudio and hasVideo. Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @nvazquezg and @kekkokk,
Regarding your comments, I've made a new pull request (#1265).
Could you please review it?
With this commit, licode records audio-only and video-only streams correctly as well as video-audio streams.


context_->streams[0] = video_stream_;
// TODO(nvazquezg): this 'if' is to avoid a matroska error when no video available: 'Invalid packet stream index: 1'
if (!init_video) {
Copy link
Contributor

Choose a reason for hiding this comment

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

When we use init_video to set video stream to null, we don't have a proper recorded video.
The init_context is called more than once. If video_stream_ has been initialized before some audio data are being written, init_video stays as false and context->streams[0] is set to null stream which garbles the recording file.

As far as I understand, if video_codec_ is null, it means we won't receive video data.
Also same for audio. if audio_codec_ is null, there will be no audio data.

So instead of using init_video to check if this is just an audio stream, we can check video_codec_:

`

//TODO: this 'if' is to avoid a matroska error when no video available: 'Invalid packet stream index: 1'
if (video_codec_ == AV_CODEC_ID_NONE) {
    // To avoid the following matroska errors, we add CODEC_FLAG_GLOBAL_HEADER...
    // - Codec for stream 0 does not use global headers but container format requires global headers
    // - Only audio, video, and subtitles are supported for Matroska.
    video_stream_ = avformat_new_stream(context_, nullptr);
    video_stream_->codec->flags |= CODEC_FLAG_GLOBAL_HEADER;
    context_->streams[0] = video_stream_;
}

`
That fixed my problem. Now, video is also being recorded properly.
Also, setting the global header is required to avoid some matrosko errors.

Copy link
Contributor

Choose a reason for hiding this comment

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

After some tests, I've realized that recorded video is shorter than expected.
Using the master branch version (without this fix), the video is 5 seconds shorter (for a 15 second recording). I think that's because the remaining video frames in the queue cannot be recorded properly.

With this fix, 5 second part is missing at the start as well. I think that's because the audio data come after and re-writes the file. That's a guess, I'm not sure.

I couldn't get the recording feature work in a stable mode.

I think some work needs to be done about recording feature.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the feedback, I'll try to improve this behaviour and come back.

@zevarito
Copy link
Contributor

@nvazquezg @zafergurel Could you check this PR[0] when you have chance?
It is a replacement of libav with ffmpeg but has a sustancial rework around ExternalOutput, it might solve some of the issues you are mention or at least it is probably much easier to take care of them now.

[0] #1218

@nvazquezg
Copy link
Author

@zevarito I've tested it a couple of weeks ago and I found no problems. But the issue I'm trying to fix here is related to the recording of outputs with only audio or video stream and this was not working in your PR.
The main reason is this if that discards outputs that don't have both streams:

https://github.com/zevarito/licode/blob/8dcf31b2ba5a004cc45890b662e7baa781ecb54f/erizo/src/erizo/media/ExternalOutput.cpp#L420-L422

I'm just starting to understand the inner workings of ExternalOutput, but I'll check if I find an easier solution to this problem in your PR.

@zevarito
Copy link
Contributor

zevarito commented Jul 12, 2018 via email

@nvazquezg
Copy link
Author

This PR #1265 offers a better solution to this problem than this one.

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.

4 participants