English 中文(简体)
How can I determine the length of an mp3 file s header?
原标题:
  • 时间:2010-02-01 22:24:07
  •  标签:
  • c#
  • mp3
  • id3

I am writing a program to diff, and copy entire files or segments based on changes on either end (Rsync-esque... but more like Unison). The main idea is to keep my music folder (all mp3s) up to date over multiple locations.

I d like to send segmented updates if only small portions of the file have changed, as opposed to copying the entire file. For this, I need a way to diff segments of the file.

I initially tried generating hashes for blocks of every file (Every n bytes I d hash the segment). I noticed that when I changed one attribute (id3v2 tag on an mp3) all the hashed blocks would change. This makes sense, as I would guess the header is growing as it acquired new information.

This leads me to my actual question. I would like to know how to determine the length of an mp3 s header, so I could create 2 comparable hashes.

1) The meta info of the file (header)

2) The actual mpeg stream with audio (This hash should remain unchanged if all I do is alter tag info)

Am I missing anything else?

Thanks!

Ty

最佳回答

I wound up using TagLibSharp. developer.novell.com/wiki/index.php/TagLib_Sharp

问题回答

If all you want to check the length of is id3v2 tags, then you can find out information about its structure at http://www.id3.org/id3v2.4.0-structure.

If you read the first 3 bytes, and they are equal to "ID3", then skip to the 7th byte, then read the header size. Be careful though, because the size is stored as a "synchsafe integer".

If you want to determine the header information, you ll either:

  • a) need to use a mp3 library that can do the parsing for you, or
  • b) go to the mp3 specification and parse it out as needed.




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签