예제 #1
0
        private static void decodeMP4(string inFile, string outFile)
        {
            using (var inFileStream = File.OpenRead(inFile))
            {
                var cont = new MP4Container(inFileStream);

                var movie = cont.getMovie();

                // --- read cover-picture if exists ---
                if (movie.containsMetaData())
                {
                    var meta = movie.getMetaData();
                    if (meta.contains(MetaData.Fields.COVER_ARTWORKS))
                    {
                        coverPicture = meta.get(MetaData.Fields.COVER_ARTWORKS).First().getImage();
                    }
                }


                var tracks = movie.getTracks(AudioTrack.AudioCodec.CodecType.AAC);
                if (tracks.Length == 0)
                {
                    throw new Exception("movie does not contain any AAC track");
                }
                var track = (AudioTrack)tracks[0];

                using (var wav = new WaveFileWriter(File.Create(outFile), track.getSampleRate(), track.getChannelCount(), track.getSampleSize()))
                {
                    var dec = new Decoder(track.getDecoderSpecificInfo());

                    var buf = new SampleBuffer();
                    while (track.hasMoreFrames())
                    {
                        if (track.currentFrame % 10 == 0)
                        {
                            Console.WriteLine(track.currentFrame.ToString("N0") + " / " + track.frames.Count.ToString("N0"));
                        }
                        var frame = track.readNextFrame();
                        dec.decodeFrame(frame.getData(), buf);
                        wav.write(buf.getData());
                    }
                }
            }
        }
        public void sendToOutput(SampleBuffer buffer)
        {
            bool be = buffer.isBigEndian();

            int chs    = data.Length;
            int mult   = (sbrPresent && config.isSBREnabled()) ? 2 : 1;
            int length = mult * config.getFrameLength();
            int freq   = mult * config.getSampleFrequency().getFrequency();

            byte[] b = buffer.getData();
            if (b.Length != chs * length * 2)
            {
                b = new byte[chs * length * 2];
            }

            float[] cur;
            int     i, j, off;
            short   s;

            for (i = 0; i < chs; i++)
            {
                cur = data[i];
                for (j = 0; j < length; j++)
                {
                    s   = (short)Math.Max(Math.Min(Math.Round(cur[j]), short.MaxValue), short.MinValue);
                    off = (j * chs + i) * 2;
                    if (be)
                    {
                        b[off]     = (byte)((s >> 8) & BYTE_MASK);
                        b[off + 1] = (byte)(s & BYTE_MASK);
                    }
                    else
                    {
                        b[off + 1] = (byte)((s >> 8) & BYTE_MASK);
                        b[off]     = (byte)(s & BYTE_MASK);
                    }
                }
            }

            buffer.setData(b, freq, chs, 16, bitsRead);
        }