如何在c++中使用ffmpeg动态更改视频的音轨
How to change the audio track of a video on the fly using ffmpeg in c++?
我正在尝试在android中开发一个媒体播放器应用程序。我使用海豚玩家的代码作为参考。但我不知道如何在播放视频时更改音频和字幕音轨。使用ffmpeg的命令行是可能的,但是如何使用ffmpegc++代码呢?
视频文件是一个包含一堆流的容器。首先,您必须打开视频文件并提取流信息(避免对较小代码进行错误检查):
AVFormatContext *pFormatCtx;
av_open_input_file( &pFormatCtx, argv[1], NULL, 0, NULL );
av_find_stream_info( pFormatCtx );
现在您可以迭代流并找到所有音频流:
for ( i=0; i != pFormatCtx->nb_streams; i++ )
{
if (pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_AUDIO) audioStreams.push_back( i );
}
选择要播放的流,并获取指向编解码器的指针并打开它:
AVCodecContext* aCodecCtx = pFormatCtx->streams[SelectedAudioStream]->codec;
AVCodec* aCodec = avcodec_find_decoder(aCodecCtx->codec_id);
avcodec_open(aCodecCtx, aCodec);
然后像往常一样解码流。
相关文章:
- std::向量与传递值的动态数组
- 在c++中用vector填充一个简单的动态数组
- C++中的动态铸造故障
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 内联映射初始化的动态atexit析构函数崩溃
- 使用动态分配的数组会导致代码分析发出虚假的C6386缓冲区溢出警告
- 控制允许动态运行c++的并发操作数
- 如何将这个C++哈希表转换为动态扩展和收缩,而不是使用硬设置的最大值
- 在调用FreeLibrary后,释放动态链接到具有相同版本的CRT堆的DLL的内存
- 输出没有重复元素的动态数组(收缩数组)C++
- C++为线程工作动态地分割例程
- 正在插入动态数组
- 如何在c++中录制具有精确帧时间戳的视频
- 在c++中使用动态分配的问题
- C++中的动态对象与非动态对象
- 开放 CV 中的动态内存分配,用于视频处理
- 如何为 OpenCV 的视频编写器动态选择可用的编解码器?
- 如何使用opencvc++拍摄动态视频图像和深度图像
- 如何在c++中使用ffmpeg动态更改视频的音轨
- 在QGraphicScene中动态调整视频大小