Skip to content
This repository has been archived by the owner on Nov 19, 2020. It is now read-only.

VideoFileWriter.WriteAudioFrame - issue with stereo signal (3.8.2 prerelese) #1353

Open
1 of 3 tasks
Barrent opened this issue May 7, 2018 · 1 comment
Open
1 of 3 tasks

Comments

@Barrent
Copy link

Barrent commented May 7, 2018

What would you like to submit? (put an 'x' inside the bracket that applies)

  • question
  • bug report
  • feature request

Issue description

Hi,

Adding signal to video works fine if mono is used, but a bug appears when stereo input is used (stereo sound is two times slower and has a lot of distortion).

Here is the code:

            var decoder = new WaveDecoder(@"D:\SoundSample1Sec.wav");
            var stereo = decoder.Decode();
            decoder.Close();

            var mono = Signal.FromArray(stereo.InnerData.Cast<float>().Where((x, i) => i % 2 == 0).ToArray(), 1, stereo.SampleRate);

            var signal = stereo;

            var image = GetImage();
            var writer = new VideoFileWriter
            {
                Height = image.Height,
                Width = image.Width,
                FrameRate = 1,
                FrameSize = signal.Length,
                VideoCodec = VideoCodec.Mpeg4,
                AudioCodec = AudioCodec.Aac
            };

            writer.Open(@"D:\TestVideo.mp4");
            writer.WriteVideoFrame(image);
            writer.WriteAudioFrame(signal);
            writer.Close();

I dug into Accord sources a little bit and found that in method VideoFileWriter.send_audio_frame number of channel isn't taken into account properly. In a row
size_t sampleSize = m_input_audio_sample_size;
sampleSize is assigned to 4 (I think it should be 8 bytes in case of stereo data)
If multiply it by m_input_audio_channels then stereo signal is written to file properly.
Maybe this bug also can be fixed by updating Singal.SampleSize property (it returns 4 bytes for stereo signal).

@nesherhh
Copy link

I can confirm, this fix.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants