当前位置:网站首页>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;
}
边栏推荐
- Joint search set: the number of points in connected blocks (the number of points in a set)
- MySQL timestampdiff interval
- 竞品分析撰写
- Basic MySQL operations
- Mongodb slow query optimization analysis strategy
- 2022 beautician (intermediate) new version test questions and beautician (intermediate) certificate examination
- Square root of X
- [brush questions] connected with rainwater (one dimension)
- Some information about the developer environment in Chengdu
- A outsourcing boy's mid-2022 summary
猜你喜欢

redis 持久化原理

Know that Chuangyu cloud monitoring - scanv Max update: Ecology OA unauthorized server request forgery and other two vulnerabilities can be detected

Jincang KFS data bidirectional synchronization scenario deployment

竞品分析撰写

深潜Kotlin协程(十九):Flow 概述

Supervised pre training! Another exploration of text generation!

2022-07-02: what is the output of the following go language code? A: Compilation error; B:Panic; C:NaN。 package main import “fmt“ func main() { var a =
![[free completion] development of course guidance platform (source code +lunwen)](/img/14/7c1c822bda050a805fa7fc25b802a4.jpg)
[free completion] development of course guidance platform (source code +lunwen)

Solve BP Chinese garbled code

vulnhub HA: Natraj
随机推荐
Deep dive kotlin synergy (19): flow overview
使用BENCHMARKSQL工具对KingbaseES预热数据时执行:select sys_prewarm(‘NDX_OORDER_2 ‘)报错
P35-P41 fourth_ context
金仓KFS数据双向同步场景部署
[set theory] set concept and relationship (set family | set family examples | multiple sets)
xrandr修改分辨率与刷新率
[brush questions] find the number pair distance with the smallest K
Bugku CTF daily question baby_ flag. txt
深潜Kotlin协程(二十):构建 Flow
MongoDB 慢查询语句优化分析策略
X-ray normal based contour rendering
BMZCTF simple_ pop
[literature reading] sparse in deep learning: practicing and growth for effective information and training in NN
国产PC系统完成闭环,替代美国软硬件体系的时刻已经到来
类的基础语法
Feature_selection
220214c language learning diary
Analysis of the reason why the server cannot connect remotely
竞品分析撰写
Pdf editing tool movavi pdfchef 2022 direct download