Пример #1
0
        static string GetUIntProperty(IMFMetadata metadata, string name)
        {
            PropVariant value = new PropVariant();

            metadata.GetProperty(name, value);
            return(value.GetVariantType() == ConstPropVariant.VariantType.UInt32 ? value.GetUInt().ToString() : null);
        }
Пример #2
0
    public HResult GetMFMetadata(
        IMFPresentationDescriptor pPresentationDescriptor,
        int dwStreamIdentifier,
        int dwFlags,
        out IMFMetadata ppMFMetadata)
    {
        ppMFMetadata = this;

        return(HResult.S_OK);
    }
        /// <summary>
        /// Gets a list of all the metadata property names on this object.
        /// </summary>
        /// <param name="metadata">A valid IMFMetadata instance.</param>
        /// <param name="propertyNames">Receives an array strings.</param>
        /// <returns>If this function succeeds, it returns the S_OK member. Otherwise, it returns another HResult's member that describe the error.</returns>
        public static HResult GetAllPropertyNames(this IMFMetadata metadata, out string[] propertyNames)
        {
            if (metadata == null)
                throw new ArgumentNullException("metadata");

            propertyNames = null;

            using(PropVariant results = new PropVariant())
            {
                HResult hr = metadata.GetAllPropertyNames(results);
                if (hr.Succeeded())
                {
                    propertyNames = results.GetStringArray();
                }

                return hr;
            }
        }
Пример #4
0
        static void ConvertFile(string sourceFileName, string destFileName)
        {
            Console.WriteLine($"------------------------------------------------------------");
            Console.WriteLine($"      Source: {sourceFileName}");

            IMFMediaSource mediaSource = GetMediaSource(sourceFileName);
            int            bitRate     = GetBitRate(mediaSource);
            IMFMetadata    metadata    = GetMetadata(mediaSource);

            ID3TagData tagData = new ID3TagData()
            {
                Title       = GetStringProperty(metadata, "Title"),
                Artist      = GetStringProperty(metadata, "Author"),
                Album       = GetStringProperty(metadata, "WM/AlbumTitle"),
                Year        = GetStringProperty(metadata, "WM/Year"),
                Genre       = GetStringProperty(metadata, "WM/Genre"),
                Track       = GetUIntProperty(metadata, "WM/TrackNumber"),
                AlbumArtist = GetStringProperty(metadata, "WM/AlbumArtist")
            };

            COMBase.SafeRelease(metadata);
            metadata = null;
            COMBase.SafeRelease(mediaSource);
            mediaSource = null;

            Console.WriteLine($"       Title: {tagData.Title}");
            Console.WriteLine($"Album artist: {tagData.AlbumArtist}");
            Console.WriteLine($"      Artist: {tagData.Artist}");
            Console.WriteLine($"       Album: {tagData.Album}");
            Console.WriteLine($"        Year: {tagData.Year}");
            Console.WriteLine($"       Genre: {tagData.Genre}");
            Console.WriteLine($"       Track: {tagData.Track}");
            Console.WriteLine($"    Bit rate: {bitRate}");

            using (AudioFileReader reader = new AudioFileReader(sourceFileName))
            {
                using (LameMP3FileWriter writer = new LameMP3FileWriter(destFileName, reader.WaveFormat, bitRate, tagData))
                {
                    reader.CopyTo(writer);
                }
            }

            Console.WriteLine($" Destination: {destFileName}");
        }