Example #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());
                    }
                }
            }
        }