Skip to content

Audio GStreamer: added support .wav .flac audio formats#21264

Merged
alalek merged 4 commits intoopencv:4.xfrom
MaximMilashchenko:AudioGStreamer
Dec 16, 2021
Merged

Audio GStreamer: added support .wav .flac audio formats#21264
alalek merged 4 commits intoopencv:4.xfrom
MaximMilashchenko:AudioGStreamer

Conversation

@MaximMilashchenko
Copy link
Copy Markdown
Contributor

@MaximMilashchenko MaximMilashchenko commented Dec 15, 2021

I added audio support wav and flac formats in Gstreamer backend

force_builders=Linux AVX2,Custom

build_image:Linux AVX2=ubuntu:20.04

buildworker:Custom=linux-1,linux-4,linux-6
build_image:Custom=gstreamer:16.04

break;
}

return !dst.empty();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

empty result is valid in case when video stream is longer than audio.

Copy link
Copy Markdown
Contributor Author

@MaximMilashchenko MaximMilashchenko Dec 15, 2021

Choose a reason for hiding this comment

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

empty result is valid in case when video stream is longer than audio.

Within the framework of this functionality, such a case is not possible. I think this case should be considered separately by adding an additional condition when will audio + video support be implemented.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Anyway this error criteria is not correct. And the error handling above in "default:".

We just forget to change that properly (our testdata doesn't handle such cases).

Comment on lines +838 to +842
/*!
* \brief CvCapture_GStreamer::retrieveFrame
* \return IplImage pointer. [Transfer Full]
* Retrieve the previously grabbed buffer, and wrap it in an IPLImage structure
*/
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We can remove this outdated docstring

}

#endif // BUILD_PLUGIN
#endif // BUILD_PLUGIN No newline at end of file
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

return EOL back.

Don't introduce unnecessary whitespace changes.

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.

return EOL back.

Don't introduce unnecessary whitespace changes.

Sorry, I do not quite understand what this is about

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you see changed code here? - yes
Is it indented and necessary change? - no

Then revert it.

case CV_8S:
data = cv::Mat(1, audioFrame.rows, CV_8S);
for (int i = 0; i < audioFrame.rows; i++)
data.at<char>(0,i) = audioFrame.at<char>(i, index-audioBaseIndex);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(0,i)

Just (i).
.at(i) is agnostic to vector-rows or vector-cols.

Comment on lines +845 to +848
if (videoStream != -1)
return retrieveVideoFrame(index, dst);
else if (audioStream != -1)
return retrieveAudioFrame(index, dst);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This logic is not correct. Checks must be "index"-based.

What is the problem to write correct logic once instead of rewriting them again with adding video support?

break;
}

return !dst.empty();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Anyway this error criteria is not correct. And the error handling above in "default:".

We just forget to change that properly (our testdata doesn't handle such cases).

Mat(map_info.size/bpf, nAudioChannels, CV_32F, map_info.data).copyTo(audioFrame);
return true;
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

missing the error message about unsupported format.

Comment on lines +601 to +605
data = cv::Mat(1, audioFrame.rows, CV_8S);
for (int i = 0; i < audioFrame.rows; i++)
data.at<char>(0,i) = audioFrame.at<char>(i, index-audioBaseIndex);
data.copyTo(dst);
break;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

2 data copies are happened here.
We should avoid that to keep OpenCV effective library.

Use:

  • dst.create()
  • data = dst.getMat()
  • fill data

First 2 calls could be done outside of switch for successful path.

Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@alalek alalek merged commit db4ab1c into opencv:4.x Dec 16, 2021
@alalek alalek mentioned this pull request Dec 30, 2021
@alalek alalek mentioned this pull request Feb 22, 2022
a-sajjad72 pushed a commit to a-sajjad72/opencv that referenced this pull request Mar 30, 2023
Audio GStreamer: added support .wav .flac audio formats

* added support .wav, lossless compressed audio formats

* fixed docs

* fixes

* videoio(gstreamer-audio): extra tests, improve error handling

Co-authored-by: Alexander Alekhin <alexander.a.alekhin@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants