简体   繁体   English

GStreamer-从MP4文件生成音频波形

[英]GStreamer - Generate audio waveform from MP4 file

I have a two-part question, 我有一个两部分的问题,

  • 1) I have an MP4 file and want to generate it's audio waveform. 1)我有一个MP4文件,想要生成它的音频波形。

  • 2) I have another MP4 file which has audio at channel [0] and channel [1] 2)我还有另一个MP4文件,该文件在通道[0]和通道[1]上有音频
    and a video track too, I want to generate waveforms for both channels as separate images. 还有一个视频轨道,我想将两个通道的波形生成为单独的图像。

How can I achieve both of the above by using GSteamer? 如何使用GSteamer达到以上两个目标?

Is the raw audio in 16-bit or 32-bit format? 原始音频是16位还是32位格式? What is the sample rate (44100 hz) and what is time duration? 采样率(44100 Hz)是多少?持续时间是多少?

Anyways assuming 44.1khz at 10 second duration... since you can't draw 44 thousand samples as pixel width so choose a final display size (eg: width = 800px and height = 600px) and do math : 无论如何,假设在10秒的持续时间为44.1khz ...因为您无法绘制44,000个样本作为像素宽度,所以请选择最终的显示尺寸(例如:width = 800px和height = 600px)并进行数学运算:

//# is (samplerate / duration) / width...
(44100 / 10) / 800 = 551;

After reading first 2 values, you will jump ahead by 551 bytes and repeat until total of (. 读取前2个值后,您将向前跳551个字节并重复直到总计(。

So in your raw data starting from pos = 0; 因此,在原始数据中,从pos = 0; ... ...

  • 1) Check this and next sample, then multiply their values together ( sample[pos] x sample[pos+1] ). 1)检查该样本和下一个样本,然后将它们的值相乘( sample[pos] x sample[pos+1] )。

  • 2) Take that result and divide by 65335 (maximum value of 16-bits or 2 bytes). 2)将结果除以65335(16位或2字节的最大值)。
    That's the final value of your first sample or point. 那是您第一个样本或点的最终值。

  • 3) Draw a line to fit according to image height ( eg: 600px) so if sample = 0.83 then: 3)画一条线以适合图像高度( 例如: 600px),因此,如果sample = 0.83则:

    line_height = (600 x 0.83); //# gives 498 as line height
    line_count += 1; //# add plus 1 to line count (stop when it reaches 800)

  • 4) Skip ahead from position [pos] by +551 bytes and repeat step (1) until line_count == 800; 4)从位置[pos]向前跳过+551字节,然后重复步骤(1),直到line_count == 800;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM