当前位置:网站首页>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;
}
边栏推荐
- 拆一辆十万元的比亚迪“元”,快来看看里面的有哪些元器件。
- What's wrong with SD card data damage? How to recover SD card data damage
- Design and implementation of JSP logistics center storage information management system
- [free completion] development of course guidance platform (source code +lunwen)
- xrandr修改分辨率與刷新率
- Mila, University of Ottawa | molecular geometry pre training with Se (3) invariant denoising distance matching
- Social phobia of contemporary young people (III)
- Asp access teaching management system design finished product
- 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
- Five elements of user experience
猜你喜欢
[graduation season · aggressive technology Er] Confessions of workers
300+篇文献!一文详解基于Transformer的多模态学习最新进展
What are the Bluetooth headsets with good sound quality in 2022? Inventory of four high-quality Bluetooth headsets
Joint set search: merge intervals and ask whether two numbers are in the same set
JS realizes the animation effect of text and pictures in the visual area
[pat (basic level) practice] - [simple simulation] 1063 calculate the spectral radius
Busycal latest Chinese version
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
[brush questions] connected with rainwater (one dimension)
Web - Information Collection
随机推荐
[free completion] development of course guidance platform (source code +lunwen)
Design and implementation of kubelet garbage collection mechanism to protect nodes from being preempted by containers image GC high threshold
Five elements of user experience
leetcode:297. Serialization and deserialization of binary tree
Sklearn data preprocessing
拆一辆十万元的比亚迪“元”,快来看看里面的有哪些元器件。
Daily question - ugly number
[literature reading] sparse in deep learning: practicing and growth for effective information and training in NN
因子选股-打分模型
How to use kotlin to improve productivity: kotlin tips
How to process the current cell with a custom formula in conditional format- How to address the current cell in conditional format custom formula?
What are the Bluetooth headsets with good sound quality in 2022? Inventory of four high-quality Bluetooth headsets
[brush questions] find the number pair distance with the smallest K
Joint set search: merge intervals and ask whether two numbers are in the same set
Joint search set: the number of points in connected blocks (the number of points in a set)
商城系统搭建完成后需要设置哪些功能
Js/ts bottom implementation double click event
Fcpx template: sweet memory electronic photo album photo display animation beautiful memory
Know that Chuangyu cloud monitoring - scanv Max update: Ecology OA unauthorized server request forgery and other two vulnerabilities can be detected
一名外包仔的2022年中总结