After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 308312 - Make mp3parse plugin implement GST_SEEK_FLAG_ACCURATE
Make mp3parse plugin implement GST_SEEK_FLAG_ACCURATE
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-plugins-ugly
0.10.0
Other Linux
: Normal enhancement
: 0.10.7
Assigned To: Sebastian Dröge (slomo)
GStreamer Maintainers
: 345971 373190 395054 455477 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2005-06-19 15:35 UTC by Akos Maroy
Modified: 2008-06-28 03:59 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
sample code demonstrating the problem (4.78 KB, text/plain)
2005-06-19 15:37 UTC, Akos Maroy
  Details
mp3-accurate-seek.diff (17.97 KB, patch)
2007-07-05 19:46 UTC, Sebastian Dröge (slomo)
none Details | Review
mp3-accurate-seek.diff (18.63 KB, patch)
2007-07-07 19:38 UTC, Sebastian Dröge (slomo)
none Details | Review
mad-buffer-clipping.diff (7.78 KB, patch)
2007-07-08 19:19 UTC, Sebastian Dröge (slomo)
none Details | Review
mad-buffer-clipping.diff (7.81 KB, patch)
2007-07-08 19:32 UTC, Sebastian Dröge (slomo)
none Details | Review
mp3-accurate-seek.diff (19.35 KB, patch)
2007-07-08 19:32 UTC, Sebastian Dröge (slomo)
none Details | Review
mad-buffer-clipping.diff (7.84 KB, patch)
2007-07-12 20:31 UTC, Sebastian Dröge (slomo)
committed Details | Review
mp3-accurate-seek.diff (17.08 KB, patch)
2007-07-12 20:32 UTC, Sebastian Dröge (slomo)
committed Details | Review

Description Akos Maroy 2005-06-19 15:35:39 UTC
when seeking and playing an mp3 file with the mad plugin, both seeking and
playing is quite inprecise.
Comment 1 Akos Maroy 2005-06-19 15:37:03 UTC
Created attachment 48002 [details]
sample code demonstrating the problem

see the sample program demonstrating the problem.

usage: ./seek <mp3 filename> <seek to secs> [<play until secs>]
Comment 2 Akos Maroy 2005-06-19 15:38:22 UTC
for example, running the sample code on a 5 second, fixed bitrate mp3 file gives
me the following output:

 ./seek /tmp/5seccounter.mp3 2
tried to seek to:          2000000000
time after seek:           2193696145
seek error:                 193696145
played until:              4786553287
total time played:         2592857142
intended playtime:         3070125000
playtime error:            -477267858
file total playtime:       5070125000


which means that seeking was off by 10% (.2 secs), and it didn't play the last
.2 secs of the file. thus the intended playtme of 3 seconds shrunk to 2.6
second, which is over 10% in error
Comment 3 Ronald Bultje 2005-06-20 06:48:06 UTC
I'm ok with mad implementing precise seeking, but not by default. As you may
have noticed, we have a flag GST_SEEK_FLAG_ACCURATE, and that is intended for
such behaviour. So make mad implement that flag and use it in your application,
and you're set.
Comment 4 Andy Wingo 2006-01-12 18:17:17 UTC
Akos, any word on this? Could you port it to 0.10?
Comment 5 Akos Maroy 2006-01-12 21:07:13 UTC
seems like the same inaccuracy in 0.10

didn't yet have time to implement a more accurate solution :(
Comment 6 Andy Wingo 2006-01-13 10:29:11 UTC
Cool. Well if you get back to it you might want to look at Jan's mp3 plugin as well -- just a thought.
Comment 7 Edward Hervey 2006-02-09 10:46:03 UTC
Akos, after chatting with Jan, the proper way to implement this behaviour:

* Generate an index of the mp3 frames [offset, time, duration] as you go along. This works both for push-based and pull-based behaviours.

* If you want to seek back to a certain position, you know which frame you need, for which you can request upstream for the frames' time of offset.

* If you want to seek to a position you haven't parsed yet, you keep parsing the incoming frames (without decoding them) until you have the frame containing the requested seek start position.

For both behaviours (seek back or forward), you will have to crop the decoded frame so it starts from the requested seek start position.

Hopes this helps
Comment 8 Tim-Philipp Müller 2006-06-28 15:04:00 UTC
*** Bug 345971 has been marked as a duplicate of this bug. ***
Comment 9 Christian Fredrik Kalager Schaller 2006-08-09 11:40:56 UTC
Fixing this would be very good as it would improve transcoding with Pitivi a lot. There are tons of movie clips out there using mp3 audio and without this working correctly Pitivi borks on transcoding them.
Comment 10 Jono Bacon 2006-08-09 12:49:14 UTC
Not wanting to just add a Me Too! entry here, but this would be really useful for Jokosher too for a number of areas.
Comment 11 Laszlo Pandy 2007-02-08 01:33:45 UTC
This is a very popular Jokosher bug[1], and I have linked here from the Jokosher bug in launchpad. As more people use Jokosher and Pitivi this bug is going to become a real pain for users. I am sure everyone is aware of how popular mp3s are.

[1]https://launchpad.net/jokosher/+bug/73327
Comment 12 Luca Ferretti 2007-02-08 14:42:14 UTC
Note that Jokosher bug[1] occurs also using Fluendo MP3 decoder plugin. I tried it just now.

[1]https://launchpad.net/jokosher/+bug/73327
Comment 13 Edward Hervey 2007-02-08 20:36:44 UTC
*** Bug 395054 has been marked as a duplicate of this bug. ***
Comment 14 Christian Fredrik Kalager Schaller 2007-05-31 09:31:17 UTC
Updated title of this bug to talk about mp3parse instead of mad. With the new mp3parse plugin in place it only needs to be fixed there and it will work with
mad, fluendo mp3 and probably also ffmpeg mp3.

Comment 15 Sebastian Dröge (slomo) 2007-07-05 19:46:19 UTC
Created attachment 91270 [details] [review]
mp3-accurate-seek.diff

The attached patch somewhat implements accurate seeking but still has some problems, especially the segment handling.

Also, for testing purposes, every seek with that patch will be an accurate seek. Would be nice if someone could look at it, give suggestions, ideas, find bugs, etc...
Comment 16 Sebastian Dröge (slomo) 2007-07-07 19:38:25 UTC
Created attachment 91369 [details] [review]
mp3-accurate-seek.diff

Ok, this does it it seems... only problem I see now is that at least the mad plugin doesn't clip the decoded buffers so only the sink will do the clipping. This should be implemented in mad ASAP, I'll look into it.

Also one could improve the "frame_offset" variable by actually looking at the mp3 frames and calculating the real amount of frames that are necessary to decode the one we want. 9 (or 29) as the theoretical maximums are working fine though.
Comment 17 Sebastian Dröge (slomo) 2007-07-08 19:19:52 UTC
Created attachment 91442 [details] [review]
mad-buffer-clipping.diff

Patch to make mad clip it's buffers appropiately. With these two patches we have accurate time seeking for MP3.
Comment 18 Sebastian Dröge (slomo) 2007-07-08 19:32:42 UTC
Created attachment 91443 [details] [review]
mad-buffer-clipping.diff

a bit of cleanup
Comment 19 Sebastian Dröge (slomo) 2007-07-08 19:32:58 UTC
Created attachment 91444 [details] [review]
mp3-accurate-seek.diff
Comment 20 Edward Hervey 2007-07-10 09:51:43 UTC
*** Bug 455477 has been marked as a duplicate of this bug. ***
Comment 21 Sebastian Dröge (slomo) 2007-07-12 20:31:50 UTC
Created attachment 91697 [details] [review]
mad-buffer-clipping.diff

new versions, should be perfect now. What do you think, Edward?
Comment 22 Sebastian Dröge (slomo) 2007-07-12 20:32:30 UTC
Created attachment 91698 [details] [review]
mp3-accurate-seek.diff

(well, every seek is accurate still but this will be changed before committing)
Comment 23 Edward Hervey 2007-07-13 09:45:15 UTC
works perfectly here. Only issues I can see are in fact with mpeg streams (using mpegdemux)... but that's another matter altogether.

COMMIT !
Comment 24 Jan Schmidt 2007-07-13 10:29:15 UTC
Perhaps we should consider adding a function like the mad clip_buffer one to the gstaudio library as a helper function - we're certainly making enough copies of it...
Comment 25 Sebastian Dröge (slomo) 2007-07-13 16:33:45 UTC
I'll care for the clip_buffer function in gstaudio later, good idea.

These two patches are committed now... flump3dec still needs buffer clipping though... someone here who wants to implement it? :)

2007-07-13  Sebastian Dröge  <slomo@circular-chaos.org>

	* gst/mpegaudioparse/gstmpegaudioparse.c: (gst_mp3parse_reset),
	(gst_mp3parse_init), (gst_mp3parse_dispose),
	(gst_mp3parse_sink_event), (mp3parse_seek_table_last_entry),
	(gst_mp3parse_emit_frame), (gst_mp3parse_chain),
	(mp3parse_handle_seek), (mp3parse_src_query):
	* gst/mpegaudioparse/gstmpegaudioparse.h:
	Implement accurate seeking in mpegaudioparse. Fixes #308312.
	Also implement segment seeks.

2007-07-13  Sebastian Dröge  <slomo@circular-chaos.org>

	* ext/mad/gstmad.c: (_do_init), (gst_mad_init), (index_seek),
	(normal_seek), (gst_mad_sink_event), (clip_outgoing_buffer),
	(gst_mad_chain), (gst_mad_change_state):
	* ext/mad/gstmad.h:
	Implement buffer clipping and use GST_BOILERPLATE instead of manual
	GType magic. Part one of bug #308312.
Comment 26 Sebastian Dröge (slomo) 2007-07-13 17:05:01 UTC
The gstaudio clip_buffer function is now bug #456656 if someone cares.
Comment 27 Jonathan Matthew 2008-06-28 03:59:04 UTC
*** Bug 373190 has been marked as a duplicate of this bug. ***