当前位置:网站首页>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;
}
边栏推荐
- How to process the current cell with a custom formula in conditional format- How to address the current cell in conditional format custom formula?
- Joint set search: merge intervals and ask whether two numbers are in the same set
- Which Bluetooth headset is cost-effective? Four Bluetooth headsets with high cost performance are recommended
- [untitled] 2022 safety production supervisor examination question bank and simulated safety production supervisor examination questions
- [NLP]—sparse neural network最新工作简述
- [set theory] Cartesian product (concept of Cartesian product | examples of Cartesian product | properties of Cartesian product | non commutativity | non associativity | distribution law | ordered pair
- xrandr修改分辨率與刷新率
- 树莓派如何连接WiFi
- China Mobile Internet of things oneos and onenet were selected in the list of 2021 Internet of things demonstration projects
- [fxcg] market analysis today
猜你喜欢
[free completion] development of course guidance platform (source code +lunwen)
[brush questions] find the number pair distance with the smallest K
GFS分布式文件系统(光是遇见已经很美好了)
FFMpeg filter
A outsourcing boy's mid-2022 summary
Nat. Comm. | 使用Tensor-cell2cell对细胞通讯进行环境感知去卷积
Basic MySQL operations
Design and implementation of JSP logistics center storage information management system
C language series - Section 3 - functions
The time has come for the domestic PC system to complete the closed loop and replace the American software and hardware system
随机推荐
[Chongqing Guangdong education] reference materials for design and a better life of Zhongyuan Institute of science and technology
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
Dive into deep learning - 2.1 data operation & Exercise
[set theory] set operation (Union | intersection | disjoint | relative complement | symmetric difference | absolute complement | generalized union | generalized intersection | set operation priority)
[literature reading] sparse in deep learning: practicing and growth for effective information and training in NN
How to connect WiFi with raspberry pie
Basic MySQL operations
MySQL timestampdiff interval
Deep dive kotlin synergy (19): flow overview
How to retrieve the password for opening word files
[no title] 2022 chlorination process examination content and free chlorination process examination questions
"Final review" 16/32-bit microprocessor (8086) basic register
解决bp中文乱码
Xrandr modify resolution and refresh rate
The longest subarray length with a positive product of 1567 recorded by leecode
X-ray normal based contour rendering
金仓KFS数据双向同步场景部署
[pat (basic level) practice] - [simple simulation] 1063 calculate the spectral radius
Deep dive kotlin synergy (20): build flow
P35-P41 fourth_ context