Невозможно объединить видео с помощью медиа-кодека

Я пытаюсь объединить видео с разным разрешением, частотой кадров, разным количеством аудиоканалов. Я масштабировал все видео с помощью mp4Composer и объединял их с помощью mp4Parser. В этом случае, если все видео имеют одинаковое количество аудиоканалов, тогда оно будет работать совершенно иначе. он показывает "Преобразование частоты дискретизации аудио еще не поддерживается". Я попытался повторно сэмплировать звук перед слиянием

public byte[] reSample(byte[] sourceData, int bitsPerSample, int sourceRate, int targetRate) {

    // make the bytes to amplitudes first
    int bytePerSample = bitsPerSample / 8;
    int numSamples = sourceData.length / bytePerSample;
    short[] amplitudes = new short[numSamples]; // 16 bit, use a short to store

    int pointer = 0;
    for (int i = 0; i < numSamples; i++) {
        short amplitude = 0;
        for (int byteNumber = 0; byteNumber < bytePerSample; byteNumber++) {
            // little endian
            amplitude |= (short) ((sourceData[pointer++] & 0xFF) << (byteNumber * 8));
        }
        amplitudes[i] = amplitude;
    }
    // end make the amplitudes

    // do interpolation
    LinearInterpolation reSample=new LinearInterpolation();
    short[] targetSample = reSample.interpolate(sourceRate, targetRate, amplitudes);
    int targetLength = targetSample.length;
    // end do interpolation

    // TODO: Remove the high frequency signals with a digital filter, leaving a signal containing only half-sample-rated frequency information, but still sampled at a rate of target sample rate. Usually FIR is used

    // end resample the amplitudes

    // convert the amplitude to bytes
    byte[] bytes;
    if (bytePerSample==1){
        bytes= new byte[targetLength];
        for (int i=0; i<targetLength; i++){
            bytes[i]=(byte)targetSample[i];
        }
    }
    else{
        // suppose bytePerSample==2
        bytes= new byte[targetLength*2];
        for (int i=0; i<targetSample.length; i++){
            // little endian
            bytes[i*2] = (byte)(targetSample[i] & 0xff);
            bytes[i*2+1] = (byte)((targetSample[i] >> 8) & 0xff);
        }
    }
    // end convert the amplitude to bytes

    return bytes;
}

'public short[] интерполировать (int oldSampleRate, int newSampleRate, short[] samples) {

    if (oldSampleRate==newSampleRate){
        return samples;
    }

    int newLength=(int)Math.round(((float)samples.length/oldSampleRate*newSampleRate));
    float lengthMultiplier=(float)newLength/samples.length;
    short[] interpolatedSamples = new short[newLength];

    // interpolate the value by the linear equation y=mx+c
    for (int i = 0; i < newLength; i++){

        // get the nearest positions for the interpolated point
        float currentPosition = i / lengthMultiplier;
        int nearestLeftPosition = (int)currentPosition;
        int nearestRightPosition = nearestLeftPosition + 1;
        if (nearestRightPosition>=samples.length){
            nearestRightPosition=samples.length-1;
        }

        float slope=samples[nearestRightPosition]-samples[nearestLeftPosition]; // delta x is 1
        float positionFromLeft = currentPosition - nearestLeftPosition;

        interpolatedSamples[i] = (short)(slope*positionFromLeft+samples[nearestLeftPosition]); // y=mx+c
    }

    return interpolatedSamples;
}`

Но это показывает, что ООН поддерживает работу. Можете ли вы помочь слить видео.

0 ответов

Другие вопросы по тегам