embedded-framework/external/ffmpeg/README.md
2024-06-22 14:07:39 +08:00

74 lines
2.1 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 1. ffmpeg开发文档
## 1.1. ffplay命令使用
* 播放G711a音频文件
```code
$ ffplay -i audio.g711a -f alaw -ac 1 -ar 8000
```
ffmpeg -i input.g711a -acodec alaw output.wav
* 播放h264视频文件
```code
$ ffplay video.h264
```
* g711a音频文件转wav音频文件
```code
$ fmpeg -f mulaw -ar 8000 -i audio.g711a audio.wav
```
* 将h264和wav文件合成mp4文件
**注意未发现可以将h264和g711a文件合成mp4文件**
```code
$ ffmpeg -i video.h264 -i audio.wav -c:v copy -c:a aac -b:a 96k test.mp4
```
## 1.2. 问题记录
### 1.2.1. avformat_open_input 执行失败
&emsp;&emsp;在执行avformat_open_input时返回-1094995529<0错误
解决在Ubuntu编译时使能所有的编译选项并且把--arch=赋值为linux
```code
# 详见://external/ffmpeg/CMakeLists.txt
set(CONFIGURE_COMMAND "--enable-cross-compile --target-os=linux --arch=linux \
--cc=${CMAKE_C_COMPILER} \
--cxx=${CMAKE_CXX_COMPILER} \
--prefix=${EXTERNAL_LIBS_OUTPUT_PATH}/ffmpeg \
--enable-parsers --enable-decoder=h264 \
--enable-ffmpeg --enable-shared --enable-static \
--enable-gpl --enable-nonfree --enable-version3 --enable-small \
--enable-muxer=mov --enable-muxer=mp4 \
--enable-decoder=aac \
--enable-demuxer=mov \
--enable-protocol=file --enable-bsf=aac_adtstoasc --enable-bsf=h264_mp4toannexb --enable-bsf=hevc_mp4toannexb")
```
### 1.2.2. avformat_open_input 执行失败
&emsp;&emsp;打开g711a文件时提示无效数据如下
**Invalid data found when processing input**
解决
调用 avformat_open_input 函数时指定输入文件的格式第三个参数g711a文件格式为alaw
```code
# //utils/MediaBase/src/MediaBaseImpl.cpp
const AVInputFormat *iformat = av_find_input_format(InputFormat(mType));
AVFormatContext *pFormatCtx = nullptr;
if ((result = avformat_open_input(&pFormatCtx, path.c_str(), iformat, nullptr)) < 0) {
char error_str[AV_ERROR_MAX_STRING_SIZE] = {0};
av_make_error_string(error_str, AV_ERROR_MAX_STRING_SIZE, result);
LogError("Couldn't open file: %s, result=%s\n", path.c_str(), error_str);
return CreateStatusCode(STATUS_CODE_NOT_OK);
}
```