如何在C ++中使用ffmpeg提取音频形式的视频? [英] How to extract audio form video using ffmpeg in C++?
本文介绍了如何在C ++中使用ffmpeg提取音频形式的视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个使用FFmpeg播放音频/视频的C ++应用程序.现在,我想增强该应用程序,以允许用户从视频中提取音频. FFmpeg如何用于此目的?我对此进行了很多搜索,但找不到有关它的教程.
I'm developing a C++ app that uses FFmpeg to play audio/video. Now I want to enhance the application to allow the users to extract audio from video. How can FFmpeg can be used for this? I searched a lot about this but I was not able to find a tutorial regarding it.
推荐答案
您需要
- 打开输入上下文[
avformat_open_input
] - 获取流信息[
avformat_find_stream_info
] - 获取音频流:
- Open the input context [
avformat_open_input
] - Get the stream information [
avformat_find_stream_info
] - Get the audio stream:
if (inputFormatContext->streams[index]->codec->codec_type ==
AVMEDIA_TYPE_AUDIO) {
inputAudioStream = inputFormatContext->streams[index];
}
- 读取每个数据包. AVPacket数据包;
- Read each packet. AVPacket packet;
int ret = av_read_frame(inputFormatContext, &packet);
if (ret == 0) {
if (packet.stream_index == inputAudioStream->index) {
// packet.data will have encoded audio data.
}
}
这篇关于如何在C ++中使用ffmpeg提取音频形式的视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文