当前位置:网站首页>Ffmpeg mix
Ffmpeg mix
2022-07-03 04:23:00 【Step base】
To realize mixing, the format of two audio streams should be ensured ( Sampling rate 、 Bit depth and number of channels ) Exactly the same , If different , You need to resample the original audio data before mixing .
ffmpeg command :
2 individual pcm Mixing , The input and output formats are the same :48k, Two channel ,16bit
ffmpeg -f s16le -ar 48000 -ac 2 -i 11.pcm -f s16le -ar 48000 -ac 2 -i 22.pcm -filter_complex amix=inputs=2:duration=first:dropout_transition=0 -f s16le -ar 48000 -ac 2 mix.pcm
code:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define IN_FILE1 "E:\\doc\\VA_tool\\11.pcm"
#define IN_FILE2 "E:\\doc\\VA_tool\\22.pcm"
#define OUT_FILE "E:\\doc\\VA_tool\\remix.pcm"
#define SIZE_AUDIO_FRAME (2)
void Mix(char sourseFile[10][SIZE_AUDIO_FRAME], int number, char* objectFile)
{
// Normalized mixing
int const MAX = 32767;
int const MIN = -32768;
double f = 1;
int output;
int i = 0, j = 0;
for (i = 0; i < SIZE_AUDIO_FRAME / 2; i++)
{
int temp = 0;
for (j = 0; j < number; j++)
{
temp += *(short*)(sourseFile[j] + i * 2);
}
output = (int)(temp * f);
if (output > MAX)
{
f = (double)MAX / (double)(output);
output = MAX;
}
if (output < MIN)
{
f = (double)MIN / (double)(output);
output = MIN;
}
if (f < 1)
{
f += ((double)1 - f) / (double)32;
}
*(short*)(objectFile + i * 2) = (short)output;
}
}
int main()
{
FILE* fp1, * fp2, * fpm;
fopen_s(&fp1,IN_FILE1, "rb");
fopen_s(&fp2,IN_FILE2, "rb");
fopen_s(&fpm,OUT_FILE, "wb");
short data1, data2, date_mix;
int ret1, ret2;
char sourseFile[10][2];
while (1)
{
ret1 = fread(&data1, 2, 1, fp1);
ret2 = fread(&data2, 2, 1, fp2);
*(short*)sourseFile[0] = data1;
*(short*)sourseFile[1] = data2;
if (ret1 > 0 && ret2 > 0)
{
Mix(sourseFile, 2, (char*)&date_mix);
/*
if( data1 < 0 && data2 < 0)
date_mix = data1+data2 - (data1 * data2 / -(pow(2,16-1)-1));
else
date_mix = data1+data2 - (data1 * data2 / (pow(2,16-1)-1));*/
if (date_mix > pow(2, 16 - 1) || date_mix < -pow(2, 16 - 1))
printf("mix error\n");
}
else if ((ret1 > 0) && (ret2 == 0))
{
date_mix = data1;
}
else if ((ret2 > 0) && (ret1 == 0))
{
date_mix = data2;
}
else if ((ret1 == 0) && (ret2 == 0))
{
break;
}
fwrite(&date_mix, 2, 1, fpm);
}
fclose(fp1);
fclose(fp2);
fclose(fpm);
std::cout << "done!\n";
system("pause");
return 0;
}
边栏推荐
- Practical operation of vim
- mysql字段userid逗号分开保存按userid查询
- [set theory] ordered pair (ordered pair | ordered triple | ordered n ancestor)
- [brush questions] most elements (super water king problem)
- Bugku CTF daily question baby_ flag. txt
- The latest activation free version of Omni toolbox
- Nat. Comm. | 使用Tensor-cell2cell对细胞通讯进行环境感知去卷积
- Social phobia of contemporary young people (III)
- Preliminary cognition of C language pointer
- Web - Information Collection
猜你喜欢

When using the benchmarksql tool to test the concurrency of kingbasees, there are sub threads that are not closed in time after the main process is killed successfully

Some information about the developer environment in Chengdu
![[pat (basic level) practice] - [simple simulation] 1063 calculate the spectral radius](/img/01/c118725f74e39742df021b5dbcc33b.jpg)
[pat (basic level) practice] - [simple simulation] 1063 calculate the spectral radius

300+ documents! This article explains the latest progress of multimodal learning based on transformer

Nat. Comm. | use tensor cell2cell to deconvolute cell communication with environmental awareness

Basic MySQL operations

JS实现图片懒加载
![[fxcg] inflation differences will still lead to the differentiation of monetary policies in various countries](/img/56/386f0fd6553b8b9711e14c54705ae3.jpg)
[fxcg] inflation differences will still lead to the differentiation of monetary policies in various countries

用户体验五要素

BMZCTF simple_ pop
随机推荐
How to retrieve the password for opening word files
When writing a web project, SmartUpload is used for file upload and new string () is used for transcoding, but in the database, there will still be random codes similar to poker
跨境电商多商户系统怎么选
使用BENCHMARKSQL工具对kingbaseES执行灌数据提示无法找到JDBC driver
Basic MySQL operations
2022 beautician (intermediate) new version test questions and beautician (intermediate) certificate examination
Competitive product analysis and writing
Basic types of data in TS
Two points -leetcode-540 A single element in an ordered array
Design and implementation of kubelet garbage collection mechanism to protect nodes from being preempted by containers image GC high threshold
"Final review" 16/32-bit microprocessor (8086) basic register
金仓数据库KingbaseES 插件kdb_date_function
DAPP for getting started with eth
[brush questions] most elements (super water king problem)
Basic syntax of class
Joint set search: merge intervals and ask whether two numbers are in the same set
vulnhub HA: Natraj
Leecode swipe questions and record LCP 18 breakfast combination
Kubernetes源码分析(一)
Causal AI, a new paradigm for industrial upgrading of the next generation of credible AI?