timheuer / taglib-sharp-portable

.NET Portable Class Library implementation of TagLib# (forked from TagLib# main project)
Other
58 stars 33 forks source link

File.Save() takes minutes to finish when writing tags to a 16.5MB mp3 file #17

Open MrCSharp22 opened 8 years ago

MrCSharp22 commented 8 years ago

Hello everyone, months ago issue #13 detailed how File.Save() would take around 20 seconds to complete. Today, i finally got to witness it in my new app. The mp3 file is 16.5MB and takes about 3-4 minutes to finish writing the tags. A similar file with 4.4MB needs only 2 seconds to finish.

I went through the code and found that inside the File.Insert (ByteVector data, long start, long replace) method, the File.RemoveBlock(long, long) is the one causing this huge delay. At first i thought this was due to the small buffer size (1024) so i changed it to (4096) but still had the same issue. From what i understood from that code is that the remove block helps in getting rid of the extra bytes remaining in the file after writing a smaller tag than the previous one.

I am trying to solve this issue but with no luck. If anyone has any info that might help, please share it here so we can solve this.

Edit: #12 is a similar case

MrCSharp22 commented 8 years ago

Just a quick update. After playing a bit with values for the buffer_length variable used in the RemoveBlock method, i found that setting the buffer length to 16KB (16384) reduces the wait time to 1 second.

Here is a small part of my test:

File Size = 16.5MB Buffer Length (Bytes) Duration (MS) 8192 -> 76,256 ~ 75,621 16384 -> 1,305 ~ 1,209

@timheuer can you confirm if this is a good workaround or would it affect other operations? So far i don't see any problems.

korimato commented 7 years ago

@RafaelYousuf I was getting the same issue in UWP with a duration around 1 minute to save a 9MB file (320kbps). I read your solution but accidentally I found another one that improve too. At least in my case. I configure the tagFile in this way:

TagLib.Id3v2.Tag.DefaultVersion = 3; TagLib.Id3v2.Tag.ForceDefaultVersion = true;

Since I put this, I got better perfomance. I don't know if was this change or was other of the 1,000 I made.

tgreve15 commented 6 years ago

I came across this problem today, where I had about 100 .avi/.mp4 movies between 500k and 2gb, and the update was running for an hour or so, only getting through 20 videos. I implemented @korimato suggestion and unfortunately no silver bullet in my case