none
视频采样率 RRS feed

答案

  • Hi Jx,

    GetSamplingRate()
    {
    //header chunk of the wave file which has the sample rate
    struct
    {
    char wFormatTag[4]; // Format category
    WORD wChannels; // Number of channels
    DWORD dwSamplesPerSec; // Sampling rate
    DWORD dwAvgBytesPerSec; // For buffer estimation
    WORD wBlockAlign; // Data block size
    } FormatChunk;
    
    char ch[1];
    CFile waveFile;
    if(waveFile.Open("hello.wav",CFile::modeRead)==FALSE)
    {
    TRACE("Error opening file");
    return;
    }
    //read till we get to the start of above chunk header
    while(1)
    {
    waveFile.Read(ch,1);
    TRACE("%c\n",ch[0]);
    if(ch[0] == 'E')
    break;
    }
    waveFile.Read(&FormatChunk,sizeof(FormatChunk));
    
    //FormatChunk.dwAvgBytesPerSec holds the sampling rate 
    TRACE("Sampling rate is : %ld\n",FormatChunk.dwAvgBytesPerSec);
    
    waveFile.Close();
    }

    From here: http://forums.codeguru.com/showthread.php?107339-Sample-rate-of-wav-file  


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2013年5月30日 6:08
    版主
  • And this:  http://www.dreamincode.net/forums/topic/212021-audio-video-bitrate/

    using System.Windows.Forms;  
    using System;  
    using System.IO;  
      
    ///  
    <summary>  
    /// This class gets the movie file's details using the windows shell  
    /// </summary>  
      
    public class MovieFileDetails  
    {  
        private Shell32.Shell Sh = new Shell32.Shell();  
        private Shell32.Folder F;  
        private Shell32.FolderItem FI;  
      
        ///  
    <summary>  
        /// The runtime (play time) of the movie  
        /// </summary>  
      
        public readonly string Runtime;  
      
        ///  
    <summary>  
        /// The screen resolution of movie (Format: Width X Height)  
        /// </summary>  
      
        public readonly string Resolution;  
      
        ///  
    <summary>  
        /// The file size in MB of the movie  
        /// </summary>  
      
        public readonly string FileSize;  
      
        ///  
    <summary>  
        /// The audio bitrate of the movie (Example: 127kbps)  
        /// </summary>  
      
        public readonly string Audio;  
      
        ///  
    <summary>  
        /// Frame rates per second and total bitrate  
        /// </summary>  
      
        public readonly string Video;  
      
        public MovieFileDetails(string MovieFile)  
        {  
            //Got this using Windows Vista, didnt try it in XP or earlier releases  
            //1 file size = 702 MB  
            //27 length = 01:33:45  
            //28 Audio Bitrate= 127kbps  
            //262 data rate= 3kbps  
            //263 frame height = 416  
            //265 frame rate = 23 frames/second  
            //265 frame width = 560  
            //266 total bitrate = 130kbps  
      
            if (System.IO.File.Exists(MovieFile))  
            {  
                try {  
                    F = Sh.NameSpace(System.IO.Path.GetDirectoryName(MovieFile));  
                    FI = F.ParseName(System.IO.Path.GetFileName(MovieFile));  
      
                    //set the fields  
                    Runtime = F.GetDetailsOf(FI, 27);  
                    Resolution = F.GetDetailsOf(FI, 265) + " X " +  
                        F.GetDetailsOf(FI, 263);  
      
                    //remove formatting, i.e. '701' instead of '701 MB'  
                    FileSize = F.GetDetailsOf(FI, 1).Substring(0,4).Trim();    
      
                    Audio = F.GetDetailsOf(FI, 28);  
                    Video = F.GetDetailsOf(FI, 265) + ", Total BitRate: " +  
                        F.GetDetailsOf(FI,266);  
                }  
                catch (Exception ex) {  
                    const string MSG = "Could not get movie file information. ";  
                    MSG += "Please make sure the right codecs are installed";  
                    MessageBox.Show(MSG, Application.ProductName,  
                        MessageBoxButtons.OK, MessageBoxIcon.Exclamation);  
                }  
            }  
            else  
            {  
                MessageBox.Show("The file does not exist.", Application.ProductName,  
                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);  
            }  
        }  
    }  
    

     

    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2013年5月30日 6:12
    版主

全部回复

  • Hi Jx,

    GetSamplingRate()
    {
    //header chunk of the wave file which has the sample rate
    struct
    {
    char wFormatTag[4]; // Format category
    WORD wChannels; // Number of channels
    DWORD dwSamplesPerSec; // Sampling rate
    DWORD dwAvgBytesPerSec; // For buffer estimation
    WORD wBlockAlign; // Data block size
    } FormatChunk;
    
    char ch[1];
    CFile waveFile;
    if(waveFile.Open("hello.wav",CFile::modeRead)==FALSE)
    {
    TRACE("Error opening file");
    return;
    }
    //read till we get to the start of above chunk header
    while(1)
    {
    waveFile.Read(ch,1);
    TRACE("%c\n",ch[0]);
    if(ch[0] == 'E')
    break;
    }
    waveFile.Read(&FormatChunk,sizeof(FormatChunk));
    
    //FormatChunk.dwAvgBytesPerSec holds the sampling rate 
    TRACE("Sampling rate is : %ld\n",FormatChunk.dwAvgBytesPerSec);
    
    waveFile.Close();
    }

    From here: http://forums.codeguru.com/showthread.php?107339-Sample-rate-of-wav-file  


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2013年5月30日 6:08
    版主
  • And this:  http://www.dreamincode.net/forums/topic/212021-audio-video-bitrate/

    using System.Windows.Forms;  
    using System;  
    using System.IO;  
      
    ///  
    <summary>  
    /// This class gets the movie file's details using the windows shell  
    /// </summary>  
      
    public class MovieFileDetails  
    {  
        private Shell32.Shell Sh = new Shell32.Shell();  
        private Shell32.Folder F;  
        private Shell32.FolderItem FI;  
      
        ///  
    <summary>  
        /// The runtime (play time) of the movie  
        /// </summary>  
      
        public readonly string Runtime;  
      
        ///  
    <summary>  
        /// The screen resolution of movie (Format: Width X Height)  
        /// </summary>  
      
        public readonly string Resolution;  
      
        ///  
    <summary>  
        /// The file size in MB of the movie  
        /// </summary>  
      
        public readonly string FileSize;  
      
        ///  
    <summary>  
        /// The audio bitrate of the movie (Example: 127kbps)  
        /// </summary>  
      
        public readonly string Audio;  
      
        ///  
    <summary>  
        /// Frame rates per second and total bitrate  
        /// </summary>  
      
        public readonly string Video;  
      
        public MovieFileDetails(string MovieFile)  
        {  
            //Got this using Windows Vista, didnt try it in XP or earlier releases  
            //1 file size = 702 MB  
            //27 length = 01:33:45  
            //28 Audio Bitrate= 127kbps  
            //262 data rate= 3kbps  
            //263 frame height = 416  
            //265 frame rate = 23 frames/second  
            //265 frame width = 560  
            //266 total bitrate = 130kbps  
      
            if (System.IO.File.Exists(MovieFile))  
            {  
                try {  
                    F = Sh.NameSpace(System.IO.Path.GetDirectoryName(MovieFile));  
                    FI = F.ParseName(System.IO.Path.GetFileName(MovieFile));  
      
                    //set the fields  
                    Runtime = F.GetDetailsOf(FI, 27);  
                    Resolution = F.GetDetailsOf(FI, 265) + " X " +  
                        F.GetDetailsOf(FI, 263);  
      
                    //remove formatting, i.e. '701' instead of '701 MB'  
                    FileSize = F.GetDetailsOf(FI, 1).Substring(0,4).Trim();    
      
                    Audio = F.GetDetailsOf(FI, 28);  
                    Video = F.GetDetailsOf(FI, 265) + ", Total BitRate: " +  
                        F.GetDetailsOf(FI,266);  
                }  
                catch (Exception ex) {  
                    const string MSG = "Could not get movie file information. ";  
                    MSG += "Please make sure the right codecs are installed";  
                    MessageBox.Show(MSG, Application.ProductName,  
                        MessageBoxButtons.OK, MessageBoxIcon.Exclamation);  
                }  
            }  
            else  
            {  
                MessageBox.Show("The file does not exist.", Application.ProductName,  
                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);  
            }  
        }  
    }  
    

     

    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2013年5月30日 6:12
    版主