ffmpeg的pcm、yuv小知识点
pcm、yuv保存调用,写个通用工具方法,平时快速保存,和调用方便查看自己bug
ffmpeg的AVFrame存储 yuv
调用方法
保存方法
void save_yuv420p_file(unsigned char *y_buf , unsigned char *u_buf,unsigned char *v_buf,int linesizey,int linesizevu, int width,int height,char *filename)
{
int i = 0;
static FILE *f= NULL;
if(f == NULL){
f = fopen(filename,"wb");
}
int height_half = height / 2, width_half = width / 2;
int y_wrap = linesizey;
int u_wrap = linesizevu;
//int u_wrap = pFrame->linesize[0];
//int v_wrap = pFrame->linesize[0];
int v_wrap = linesizevu;
if (f != NULL) {
//save y
for (i = 0; i < height; i++)
fwrite(y_buf + i * y_wrap, 1, width, f);
//save u
for (i = 0; i < height_half; i++)
fwrite(u_buf + i * u_wrap, 1, width_half, f);
//save v
for (i = 0; i < height_half; i++)
fwrite(v_buf + i * v_wrap, 1, width_half, f);
fflush(f);
}
}
ffmpeg命令播放yuv:(修改对应宽高和yuv文件路径)
ffplay -video_size 720x1280 -i /Users/shenjianbin/Downloads/camera2_tencent.yuv
ffmpeg的AVFrame存储 pcm
void savess_file(uint8_t *buf, int size,char *filename)
{
static FILE *f= NULL;
if(f == NULL){
f = fopen(filename,"wb");
}
if (f != NULL) {
fwrite(buf, sizeof(uint8_t), size, f);
fflush(f);
}
}
命令行操控
ffplay -ar 44100 -ac 2 -f f32le /Users/songlin/audio/qt_record/05_05_23_05_35.pcm
ar: 采样率
ac: 声道数
f: 采样格式
s16le:PCM signed 16-bit little-endian
更多PCM的采样格式可以使用命令查看
Windows:ffmpeg -formats | findstr PCM
Mac:ffmpeg -formats | grep PCM