当前位置:网站首页>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;
}
边栏推荐
- RSRS指标择时及大小盘轮动
- How do you use lodash linking function- How do you chain functions using lodash?
- [fairseq] error: typeerror:_ broadcast_ coalesced(): incompatible function arguments
- Interface in TS
- Deep dive kotlin synergy (19): flow overview
- 重绘和回流
- Drf--- quick start 01
- [set theory] set operation (Union | intersection | disjoint | relative complement | symmetric difference | absolute complement | generalized union | generalized intersection | set operation priority)
- [set theory] set identities (idempotent law | exchange law | combination law | distribution rate | De Morgan law | absorption rate | zero law | identity | exclusion law | contradiction law | complemen
- Jincang KFS data bidirectional synchronization scenario deployment
猜你喜欢

Five elements of user experience

Asp access teaching management system design finished product

The time has come for the domestic PC system to complete the closed loop and replace the American software and hardware system

Which Bluetooth headset is good about 400? Four Bluetooth headsets with strong noise reduction are recommended

China Mobile Internet of things oneos and onenet were selected in the list of 2021 Internet of things demonstration projects

CVPR 2022 | 大連理工提出自校准照明框架,用於現實場景的微光圖像增强

Introduction of pointer variables in function parameters

Redis persistence principle

"Final review" 16/32-bit microprocessor (8086) basic register

竞品分析撰写
随机推荐
智能合约安全审计公司选型分析和审计报告资源下载---国内篇
MongoDB 慢查询语句优化分析策略
The longest subarray length with a positive product of 1567 recorded by leecode
[brush questions] connected with rainwater (one dimension)
vulnhub HA: Natraj
重绘和回流
Smart contract security audit company selection analysis and audit report resources download - domestic article
[set theory] set concept and relationship (set represents | number set | set relationship | contains | equality | set relationship property)
[free completion] development of course guidance platform (source code +lunwen)
有监督预训练!文本生成又一探索!
How to use kotlin to improve productivity: kotlin tips
P35-P41 fourth_ context
使用BENCHMARKSQL工具对KingbaseES预热数据时执行:select sys_prewarm(‘NDX_OORDER_2 ‘)报错
Preliminary cognition of C language pointer
Deep dive kotlin synergy (19): flow overview
Practical operation of vim
因子选股-打分模型
Analysis of the reason why the server cannot connect remotely
Basic types of data in TS
Deep dive kotlin synergy (20): build flow