Home Database Mysql Tutorial [MP3学习]MP3标签信息之ID3v1,IDv2

[MP3学习]MP3标签信息之ID3v1,IDv2

Jun 07, 2016 pm 03:00 PM
mp3 information study Label

近来本着踏实努力一点一滴的原则,研究了下MP3,准备做一个了类于AIRPLAY的播放器,这是学习的第一篇,读取信息,做一个笔记。 参考资料:http://www.id3.org/ID3v1 http://en.wikipedia.org/wiki/ID3 ====================================================

       近来本着踏实努力一点一滴的原则,研究了下MP3,准备做一个了类似于AIRPLAY的播放器,这是学习的第一篇,读取信息,做一个笔记。

参考资料:http://www.id3.org/ID3v1       http://en.wikipedia.org/wiki/ID3

========================================================================

MP3歌曲信息(ID3v1)结构如下:

[MP3学习]MP3标签信息之ID3v1,IDv2

所以需要一个结构体存储MP3的歌曲信息,一般声明如下:

1

2

3

4

5

6

7

8

9

10

struct MP3INFO  //MP3的信息结构,固定的,存放在歌曲最后128个字节中

{  

    char     identify[3];          // TAG

    char     Title[30];            // 歌曲名,30个字节  

    char     Artist[30];           // 歌手名,30个字节  

    char     Album[30];         // 所属唱片,30个字节  

    char     Year[4];             // 年份,4个字符  

    char     Comment[30];   // 注释,28个字节,有些说是30个,但都没啥关系,只是保留位的大小要改改 

    char     reserved[1];   //保留,暂无用

};

Copy after login

知道了这些就很容易了,不敢用什么办法,只要读取到最后的128个字节,所有的相关信息就可以得到了,用VC6.0控制台程序测试如下(主代码):

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

#include "stdafx.h"

 

 

struct MP3INFO  //MP3的信息结构,固定的,存放在歌曲最后128个字节中

{  

    char     identify[3];          // TAG

    char     Title[30];            // 歌曲名,30个字节  

    char     Artist[30];           // 歌手名,30个字节  

    char     Album[30];         // 所属唱片,30个字节  

    char     Year[4];             // 年份,4个字符  

    char     Comment[30];   // 注释,28个字节,有些说是30个,但都没啥关系,只是保留位的大小要改改 

    char     reserved[1];   //保留,暂无用

};

 

 

int main(int argc, char* argv[])

{

    printf("读取一个MP3的信息,每个MP3的最后128个字节存储的,它有固定的结构,下面试读取之!\n");

    MP3INFO mp3;

 

    FILE *pf = fopen("H:/1.mp3","r");

    printf("打开文件:%d\n",pf);

 

    fseek(pf,-128,SEEK_END);

    fread(&mp3,sizeof(mp3),1,pf);

 

    printf("TAG标志:%s\n",mp3.identify);

    printf("曲名:%s\n",mp3.Title);

    printf("歌手:%s\n",mp3.Artist);

    printf("唱片:%s\n",mp3.Album);

    printf("年份:%s\n",mp3.Year);

    printf("注释:%s\n",mp3.Comment);

 

    fclose(pf);

 

    return 0;

}

Copy after login

效果如下:

[MP3学习]MP3标签信息之ID3v1,IDv2


读取的任务完成了。对于修改,知道了这些再做完善也很容易:(如下)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

memset(&mp3,0,sizeof(mp3));

    printf("修改信息:\n");

    mp3.Identify[0]='T';

    mp3.Identify[1]='A';

    mp3.Identify[2]='G';

     

    mp3.Flag='0';

    mp3.Track='5';

    mp3.Style='3';

     

    lstrcpy(mp3.Title,(LPCTSTR)"修改的名字");

    lstrcpy(mp3.Artist,(LPCTSTR)"修改的作者");

    lstrcpy(mp3.Album,(LPCTSTR)"修改的唱片");

    lstrcpy(mp3.Year,(LPCTSTR)"1989");

    lstrcpy(mp3.Comment,(LPCTSTR)"修改的注释");

     

    fseek(pf,-128,SEEK_END);

    fwrite(&mp3,sizeof(mp3),1,pf);

Copy after login

修改完成后,在UltraEdit中查看(16进制),信息格式完全正确。但是,用Windows自带的属性查看发现,其上面的内容不全是我们修改的,这是为什么呢?

经多方查找 http://en.wikipedia.org/wiki/ID3,http://baike.baidu.com/view/66078.html

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

/*

 * ID3v1是固定的128个字节,这个你不用担心。其实ID3v1是这样安排的:如果MP3的注释是大于28个字节的,那么就要借用126-127两个字节。

 * 所以ID3v1的注释部分可能是28个字节也可能是30个字节。那么,怎么区分到底是28个字节还是30个字节呢?很简单,126处就是管这个的,

 * 我们只要看看126处是不是0x00,如果是0x00那么注释就有28个字节。如果不等于0x00,那么就是说注释是30个字节。同时别忘了,

 * 由于第127字节存储了Track信息,那么如果注释是30个字节的时候,这首歌的ID3v1里的那个127处的信息自然就不是Track信息了。

 * Track自然就是没有地方存了,所以127处变的没有Track意义了,它只是Comment的一部分了。

 */

struct ID3v1    //MP3的信息结构,固定的,存放在歌曲最后128个字节中

{  

    char     Identify[3];   // ID3v1为TAG

    char     Title[30];     // 歌曲名,30个字节  

    char     Artist[30];    // 歌手名,30个字节  

    char     Album[30];     // 所属唱片,30个字节  

    char     Year[4];       // 年份,4个字符  

    char     Comment[28];   // 注释,28个字节,有时是30个, 

    char     Flag;          // 标志,为0说明有音轨(下一位),不一定有

    char     Track;         // 音轨,#,歌曲号,不一定有

char     Style;         // 风格流派,需要查询,不一定有

};

Copy after login

所以对读写取程序做些修改:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

void ReadID3v1(char* pfile)

{

    printf("读取一个MP3的信息,每个MP3的最后128个字节存储的,它有固定的结构,下面试读取之!\n");

    ID3v1 mp3;

     

    FILE *pf = fopen(pfile,"r+");

    printf("打开文件:%d\n",pf);

     

    fseek(pf,-128,SEEK_END);

    fread(&mp3,sizeof(mp3),1,pf);

    if (mp3.Identify[0]!='T' || mp3.Identify[1]!='A' || mp3.Identify[2]!='G' )

    {

        printf("此歌曲不支持ID3v2标准!\n");

        fclose(pf);

         

        return;

    }

    printf("TAG标志:%.3s\n",mp3.Identify);

    printf("曲名:%.30s\n",mp3.Title);

    printf("歌手:%.30s\n",mp3.Artist);

    printf("唱片:%.30s\n",mp3.Album);

    printf("年份:%.4s\n",mp3.Year);

    printf("注释:%.30s\n",mp3.Comment);

    if (mp3.Flag==0)

    {

        printf("歌曲序号:%d,流派标志:%d\n",mp3.Track,mp3.Style);

    }

     

    getchar();

 

    //下面试着修改信息

    memset(&mp3,0,sizeof(mp3));

    printf("修改信息:\n");

    mp3.Identify[0]='T';

    mp3.Identify[1]='A';

    mp3.Identify[2]='G';

     

    mp3.Flag='0';

    mp3.Track='5';

    mp3.Style='3';

     

    lstrcpy(mp3.Title,(LPCTSTR)"修改的名字");

    lstrcpy(mp3.Artist,(LPCTSTR)"修改的作者");

    lstrcpy(mp3.Album,(LPCTSTR)"修改的唱片");

    lstrcpy(mp3.Year,(LPCTSTR)"1989");

    lstrcpy(mp3.Comment,(LPCTSTR)"修改的注释");

     

    fseek(pf,-128,SEEK_END);

    fwrite(&mp3,sizeof(mp3),1,pf);

    printf("over,%s\n",mp3.Title);

     

    fclose(pf);

}

Copy after login

http://blog.csdn.net/bbdxf/article/details/7438006











Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to search for text across all tabs in Chrome and Edge How to search for text across all tabs in Chrome and Edge Feb 19, 2024 am 11:30 AM

This tutorial shows you how to find specific text or phrases on all open tabs in Chrome or Edge on Windows. Is there a way to do a text search on all open tabs in Chrome? Yes, you can use a free external web extension in Chrome to perform text searches on all open tabs without having to switch tabs manually. Some extensions like TabSearch and Ctrl-FPlus can help you achieve this easily. How to search text across all tabs in Google Chrome? Ctrl-FPlus is a free extension that makes it easy for users to search for a specific word, phrase or text across all tabs of their browser window. This expansion

How to convert qq music to mp3 format Convert qq music to mp3 format on mobile phone How to convert qq music to mp3 format Convert qq music to mp3 format on mobile phone Mar 21, 2024 pm 01:21 PM

QQ Music allows everyone to enjoy watching movies and relieve boredom. You can use this software every day to easily satisfy your needs. A large number of high-quality songs are available for everyone to listen to. You can also download and save them. The next time you listen to them, you don’t need an Internet connection. The songs downloaded here are not in MP3 format and cannot be used on other platforms. After the membership songs expire, there is no way to listen to them again. Therefore, many friends want to convert the songs into MP3 format. Here, the editor explains You provide methods so that everyone can use them! 1. Open QQ Music on your computer, click the [Main Menu] button in the upper right corner, click [Audio Transcoding], select the [Add Song] option, and add the songs that need to be converted; 2. After adding the songs, click to select Convert to [mp3]

Revealing the appeal of C language: Uncovering the potential of programmers Revealing the appeal of C language: Uncovering the potential of programmers Feb 24, 2024 pm 11:21 PM

The Charm of Learning C Language: Unlocking the Potential of Programmers With the continuous development of technology, computer programming has become a field that has attracted much attention. Among many programming languages, C language has always been loved by programmers. Its simplicity, efficiency and wide application make learning C language the first step for many people to enter the field of programming. This article will discuss the charm of learning C language and how to unlock the potential of programmers by learning C language. First of all, the charm of learning C language lies in its simplicity. Compared with other programming languages, C language

Getting Started with Pygame: Comprehensive Installation and Configuration Tutorial Getting Started with Pygame: Comprehensive Installation and Configuration Tutorial Feb 19, 2024 pm 10:10 PM

Learn Pygame from scratch: complete installation and configuration tutorial, specific code examples required Introduction: Pygame is an open source game development library developed using the Python programming language. It provides a wealth of functions and tools, allowing developers to easily create a variety of type of game. This article will help you learn Pygame from scratch, and provide a complete installation and configuration tutorial, as well as specific code examples to get you started quickly. Part One: Installing Python and Pygame First, make sure you have

Let's learn how to input the root number in Word together Let's learn how to input the root number in Word together Mar 19, 2024 pm 08:52 PM

When editing text content in Word, you sometimes need to enter formula symbols. Some guys don’t know how to input the root number in Word, so Xiaomian asked me to share with my friends a tutorial on how to input the root number in Word. Hope it helps my friends. First, open the Word software on your computer, then open the file you want to edit, and move the cursor to the location where you need to insert the root sign, refer to the picture example below. 2. Select [Insert], and then select [Formula] in the symbol. As shown in the red circle in the picture below: 3. Then select [Insert New Formula] below. As shown in the red circle in the picture below: 4. Select [Radical Formula], and then select the appropriate root sign. As shown in the red circle in the picture below:

How to add tags on Douyin to attract traffic? Which tags on the platform are easiest to attract traffic to? How to add tags on Douyin to attract traffic? Which tags on the platform are easiest to attract traffic to? Mar 22, 2024 am 10:28 AM

As a popular short video social platform, Douyin has a huge user base. For Douyin creators, using tags to attract traffic is an effective way to increase the exposure of content and attract attention. So, how does Douyin use tags to attract traffic? This article will answer this question in detail for you and introduce related techniques. 1. How to add tags on Douyin to attract traffic? When posting a video, make sure to choose tags that are relevant to the content. These tags should cover the topic and keywords of your video to make it easier for users to find your video through tags. Leveraging popular hashtags is an effective way to increase your video’s exposure. Research current popular tags and trends and incorporate them into your video descriptions and tags. These popular tags usually have higher visibility and can attract the attention of more viewers. 3. Label

What is the clock behind the TikTok label? How to tag Douyin account? What is the clock behind the TikTok label? How to tag Douyin account? Mar 24, 2024 pm 03:46 PM

When browsing Douyin works, we often see a clock icon behind the tag. So, what exactly is this clock? This article will focus on the discussion of "What is the clock behind the Douyin label", hoping to provide some useful reference for your use of Douyin. 1. What is the clock behind the Douyin label? Douyin will launch some hot topic challenges. When users participate, they will see a clock icon after the tag, which means that the work is participating in the topic challenge and displays the remaining time of the challenge. For some time-sensitive content, such as holidays, special events, etc., Douyin will attach a clock icon after the label to remind users of the validity period of the content. 3. Popular tags: When a tag becomes popular, Douyin will add a clock icon after the tag to indicate that the tag is

Learn the main function in Go language from scratch Learn the main function in Go language from scratch Mar 27, 2024 pm 05:03 PM

Title: Learn the main function in Go language from scratch. As a simple and efficient programming language, Go language is favored by developers. In the Go language, the main function is an entry function, and every Go program must contain the main function as the entry point of the program. This article will introduce how to learn the main function in Go language from scratch and provide specific code examples. 1. First, we need to install the Go language development environment. You can go to the official website (https://golang.org

See all articles