mpv-player / mpv

🎥 Command line video player
https://mpv.io
Other
28.43k stars 2.91k forks source link

libopus: Could not update timestamps for skipped samples #533

Closed haheute closed 10 years ago

haheute commented 10 years ago

When I play opus encoded audio (encoded with ffmpeg 2.1.3), I always get this message and skipping to next song is slow. But I don't know if this is a mpv issue. mplayer (MPlayer SVN-r36498-snapshot-4.8.2) does also throw some "Audio device got stuck!" messages.

mpv tt.mka 
Playing: tt.mka
Detected file format: Matroska
Clip info:
 ENCODER: Lavf55.19.104
[stream] Audio (+) --aid=1 (*) (opus)
Video: no video
[ffmpeg/audio] libopus: Could not update timestamps for skipped samples.
Selected audio codec: libopus Opus [lavc:libopus]
AO: [pulse] 48000Hz stereo 2ch s16
ghost commented 10 years ago

Not sure if this is related to this message. Pulse can be a bit flaky here. Does it happen with other AOs? What mpv version (you said ffmpeg and mplayer versions only)? Can you share a sample of the mka file? Also try with -demuxer=lavf.

haheute commented 10 years ago

Sorry, I don't know what an AO is. This also happens when the file is *.opus. "mpv -demuxer=lavf test.mka" brings the same message. the version of mpv is:

$ mpv --version
mpv 0.3.4 (C) 2000-2013 mpv/MPlayer/mplayer2 projects
 built on 2014-02-01T12:56:01
ffmpeg library versions:
   libavutil       52.48.101
   libavcodec      55.39.101
   libavformat     55.19.104
   libswscale      2.5.101
   libavfilter     3.90.100
   libavresample   1.1.0

system is archlinux:

3.12.9-2-ARCH #1 SMP PREEMPT Fri Jan 31 10:22:54 CET 2014 x86_64 GNU/Linux

here is such a mka file: http://www.file-upload.net/download-8601180/test.mka.html

qyot27 commented 10 years ago

AO = audio output. It refers to the audio output device.

As to the message itself, it's not restricted to Pulse, since it happens on Windows (DirectSound) and when using ALSA. It's been reporting that message ever since mpv started recognizing Opus content. At the time, I just took it as a quirk of the libavformat/codec support for libopus, but it seems that transcoding Opus content in ffmpeg doesn't show that message.

haheute commented 10 years ago

"but it seems that transcoding Opus content in ffmpeg doesn't show that message." what do you mean with this? I have tried creating opus files with ffmpeg and opusenc, they all show the error. No matter if I do mp3 --> opus or mp3 --> flac --> opus.

ghost commented 10 years ago

There are two issues. The message, which merely means the timestamps will be off to up about 80 or 90ms - which you really don't need to care about.

The second issue is that you said something is slow. I suspect this has nothing to do with the message, but with the used audio output (AO).

haheute commented 10 years ago

Yes, when I skip to the next song with "page up - key", it takes 1 or 2 seconds . (with opus or vorbis, but not with mp3) I started pulseaudio with "pulseaudio -vv" and looked into the debug messages, but it was quite a lot. When skipping, lots of

D: [alsa-sink-ALC887-VD Analog] sink.c: Found underrun 136228 bytes ago (39936 bytes ahead in playback buffer)
D: [alsa-sink-ALC887-VD Analog] sink.c: Found underrun 136228 bytes ago (35976 bytes ahead in playback buffer)
D: [alsa-sink-ALC887-VD Analog] sink.c: Found underrun 136228 bytes ago (35964 bytes ahead in playback buffer)
D: [alsa-sink-ALC887-VD Analog] sink.c: Found underrun 136228 bytes ago (31980 bytes ahead in playback buffer)

happens. I don't know what to do. Or how to test without pulseaudio. When I stop it with "pulseaudio -k", I have no sound at all.

ghost commented 10 years ago

Try with --ao=alsa (will pick pulse alsa emulation) or pasuspender.

Does this not happen with files that don't show the timestamp message?

haheute commented 10 years ago

Ok, with --ao=alsa the result is the same. I tried to find a mka/opus file without the timestamp message, but it seems they have it all. Even this example song, that I have downloaded: http://people.xiph.org/~giles/2012/opus/ehren-paper_lights-64.opus But this example does only have a small delay, perhaps 0.5 second. Some of my mka/opus - files have a 3 - 4 second delay when I skip to next song.

ghost commented 10 years ago

I have no such delays when playing these files.

Also, did you test with non-opus files?

haheute commented 10 years ago

I took this file ( http://www.file-upload.net/download-8602415/test2.mka.html ) and converted it to some formats, with "ffmpeg -i test2.mka test2.xyz" without any options.

test2.flac  test2.mka  test2.mp3  test2.ogg  test2.opus  test2.wma

Only the mka-file had a long delay, and the opus and ogg a very short. The rest did not have a delay.

$ mpv test2*
Playing: test2.flac
Detected file format: raw FLAC (libavformat)
Clip info:
 ENCODER: Lavf55.19.104
[stream] Audio (+) --aid=1 (flac)
Video: no video
Selected audio codec: FLAC (Free Lossless Audio Codec) [lavc:flac]
Position: 100 %
A: 00:10:03 / 00:03:14 (100%)

Playing: test2.mka
Detected file format: Matroska
Clip info:
 ENCODER: Lavf55.19.104
[stream] Audio (+) --aid=1 (*) (opus)
Video: no video
[ffmpeg/audio] libopus: Could not update timestamps for skipped samples.
Selected audio codec: libopus Opus [lavc:libopus]

A: 00:00:02 / 00:03:14 (1%)

A: 00:03:14 / 00:03:14 (99%)

Playing: test2.mp3
Detected file format: MP2/3 (MPEG audio layer 2/3) (libavformat)
Clip info:
 encoder: Lavf55.19.104
[stream] Audio (+) --aid=1 (mp3)
Video: no video
Selected audio codec: High-performance decoder using libmpg123 [mpg123:mp3]
Position: 100 %
A: 00:10:01 / 00:03:14 (100%)

Playing: test2.ogg
Detected file format: Ogg (libavformat)
Clip info:
 ENCODER: Lavf55.19.104
[stream] Audio (+) --aid=1 (flac)
Video: no video
Selected audio codec: FLAC (Free Lossless Audio Codec) [lavc:flac]
Position: 100 %
A: 00:03:14 / 00:03:14 (99%)

Playing: test2.opus
Detected file format: Ogg (libavformat)
Clip info:
 ENCODER: Lavf55.19.104
[stream] Audio (+) --aid=1 (flac)
Video: no video
Selected audio codec: FLAC (Free Lossless Audio Codec) [lavc:flac]
Position: 100 %
A: 00:03:14 / 00:03:14 (99%)

Playing: test2.wma
Detected file format: ASF (Advanced / Active Streaming Format) (libavformat)
Clip info:
 encoder: Lavf55.19.104
[stream] Audio (+) --aid=1 (wmav2)
Video: no video
Selected audio codec: Windows Media Audio 2 [lavc:wmav2]
Position: 100 %
A: 00:03:14 / 00:03:14 (99%)

If you have an idea and need some information I will try to provide it.

ghost commented 10 years ago

I even installed pulseaudio just now, but I can't reproduce.

Can you give more detailed instructions how to reproduce this?

haheute commented 10 years ago

I do this with gnome-terminal:

youtube-dl http://www.youtube.com/watch?v=sonYFxHHvaM
ffmpeg -i Bob\ Marley\ -\ One\ Love-sonYFxHHvaM.mp4 -acodec libopus bob.mka
mpv bob.mka

and then I have the timestamp message and the delay when skipping the song. I do not have some 'special' sound configuration. Just installed arch with the help of the wiki. No other sound server installed, and never changed something in the pulseaudio configuration. I don't know if I installed pulseaudio or if it was installed with gnome or something

ghost commented 10 years ago

How long do you play the audio? When does it "hang" (or whatever delay issue you're experiencing?) What did you do when this happened, or does it just happen when the audio ends? In this case, does it happen only when there's a next song, or also when it's the last song and mpv is going to quit after that?

haheute commented 10 years ago

It happens, when I use the 'page up' key. And not when I use it in the middle of a long dj-set . Only at the end of a file. I can use the arrow keys and the page up key to move inside the track, when I let the end of the song finish for itself, there is no problem. When I just play some songs and do nothing, it is ok, too. No delay.

But with "page up" at the end of a track, the player does not jump to the start of the next song, but to 97% or 98% of the current song. And plays from there.

And that is like a delay of 1, 2 or 3 seconds. Also, it does not matter if I play one oder more songs.

ghost commented 10 years ago

Uh ok. I can confirm that using page up (which by default is mapped to seek 600 seconds forward) near the end of the file doesn't skip to the next file, but seeks to the last bit of audio before the end of the file. It doesn't "delay" anything, but plays that audio normally. This is normal behavior. libavformat behaves this way, and can't be fixed (although maybe it would be possible to add an awful workaround to handle this). The mpv mkv demuxer also behaves this way in audio-only mode, but not with video (because audio seeking works differently than video). Probably could be "fixed", but then there's the danger of breaking something else.

The message you're seeing is a caveat with timestamp handling (and the libavcodec API being stupid), but it shouldn't affect anything seriously. (Though it might give slightly incorrect sync with video, if the file is muxed with video - if anyone has such a file that exposes issues, then I'll fix it.)

Either way, not a bug.

Use the playlist_next command (e.g > is bound to this by default) to skip to the next file.

I'll probably look into making the seeking behavior a bit more convenient, but I can't promise anything.

haheute commented 10 years ago

Ok, I was just wondering that it works better with mp3 than with opus or vorbis in mka. So i thought it must be some kind of bug. ... .. With mp3 --> immediatly , with mka --> wait a second or two. At least here on my computer. I will test if it is the same on my laptop. The > key doesn't do anything, here :(

ghost commented 10 years ago

Just pushed a commit to master that improves audio-only Matroska seeking. I can't do much about libavformat seeking behavior, though.

The > key doesn't do anything, here :(

Well, that's strange, because it's mapped by default. Note that it indeed does nothing if the current file is the last on the internal playlist; try the enter key instead.

qyot27 commented 10 years ago

"but it seems that transcoding Opus content in ffmpeg doesn't show that message." what do you mean with this? I have tried creating opus files with ffmpeg and opusenc, they all show the error. No matter if I do mp3 --> opus or mp3 --> flac --> opus.

I meant exactly what I said. Decoding Opus to another format in ffmpeg doesn't show the warning.

>ffmpeg -v 9 -loglevel 99 -i "C:\dap\vid\distro\Qyöt27 - Daybreak [10bit-444][H.264+Opus] distro.mkv" -vn -acodec pcm_s16le test.wav
ffmpeg version r60458 git-2606c29 Copyright (c) 2000-2014 the FFmpeg developers
  built on Feb  8 2014 17:16:53 with gcc 4.8.2 (GCC)
  libavutil      52. 63.101 / 52. 63.101
  libavcodec     55. 50.100 / 55. 50.100
  libavformat    55. 30.100 / 55. 30.100
  libavdevice    55.  7.100 / 55.  7.100
  libavfilter     4.  1.102 /  4.  1.102
  libavresample   1.  1.  0 /  1.  1.  0
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
  libpostproc    52.  3.100 / 52.  3.100
Splitting the commandline.
Reading option '-v' ... matched as option 'v' (set logging level) with argument '9'.
Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argum
ent '99'.
Reading option '-i' ... matched as input file with argument 'C:\dap\vid\distro\Qyöt27 - D
aybreak [10bit-444][H.264+Opus] distro.mkv'.
Reading option '-vn' ... matched as option 'vn' (disable video) with argument '1'.
Reading option '-acodec' ... matched as option 'acodec' (force audio codec ('copy' to copy
 stream)) with argument 'pcm_s16le'.
Reading option 'test.wav' ... matched as output file.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option v (set logging level) with argument 9.
Successfully parsed a group of options.
Parsing a group of options: input file C:\dap\vid\distro\Qyöt27 - Daybreak [10bit-444][H.
264+Opus] distro.mkv.
Successfully parsed a group of options.
Opening an input file: C:\dap\vid\distro\Qyöt27 - Daybreak [10bit-444][H.264+Opus] distro
.mkv.
[matroska,webm @ 03922980] Format matroska,webm probed with size=2048 and score=100
st:0 removing common factor 1000000 from timebase
st:1 removing common factor 1000000 from timebase
st:2 removing common factor 1000000 from timebase
st:3 removing common factor 1000000 from timebase
[matroska,webm @ 03922980] Before avformat_find_stream_info() pos: 703977 bytes read:73673
0 seeks:0
[matroska,webm @ 03922980] parser not found for codec opus, packets or times may be invali
d.
    Last message repeated 1 times
[h264 @ 03a37f00] no picture
[matroska,webm @ 03922980] All info found
[matroska,webm @ 03922980] After avformat_find_stream_info() pos: 1080035 bytes read:10971
78 seeks:0 frames:12
Input #0, matroska,webm, from 'C:\dap\vid\distro\Qyöt27 - Daybreak [10bit-444][H.264+Opus
] distro.mkv':
  Metadata:
    encoder         : libebml v1.3.0 + libmatroska v1.4.1
    creation_time   : 2013-07-26 22:11:52
  Duration: 00:05:00.47, start: 0.000000, bitrate: 1470 kb/s
    Stream #0:0(eng), 4, 1/1000: Video: h264 (High 4:4:4 Predictive), yuv444p10le, 848x480
, 1001/48000, SAR 1:1 DAR 53:30, 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default) (forced
)
    Stream #0:1(eng), 8, 1/1000: Audio: opus, 48000 Hz, stereo, s16 (default) (forced)
    Stream #0:2, 0, 1/1000: Subtitle: subrip (default) (forced)
    Metadata:
      title           : Dummy Subtitles
    Stream #0:3(eng), 0, 1/1000: Subtitle: ssa
    Metadata:
      title           : Karaoke Subtitles [ASS]
Codec 0x18000 is not in the full list.
    Stream #0:4, 0, 1/90000: Attachment: unknown_codec
    Metadata:
      filename        : Ubuntu-R.ttf
      mimetype        : application/x-truetype-font
    Stream #0:5, 0, 1/90000: Attachment: text
    Metadata:
      filename        : knife.txt
      mimetype        : text/plain
    Stream #0:6, 0, 1/90000: Attachment: png
    Metadata:
      filename        : release_poster.png
      mimetype        : image/png
Successfully opened the file.
Parsing a group of options: output file test.wav.
Applying option vn (disable video) with argument 1.
Applying option acodec (force audio codec ('copy' to copy stream)) with argument pcm_s16le
.
Successfully parsed a group of options.
Opening an output file: test.wav.
Successfully opened the file.
detected 1 logical cores
[graph 0 input from stream 0:1 @ 03a3a120] Setting 'time_base' to value '1/48000'
[graph 0 input from stream 0:1 @ 03a3a120] Setting 'sample_rate' to value '48000'
[graph 0 input from stream 0:1 @ 03a3a120] Setting 'sample_fmt' to value 's16'
[graph 0 input from stream 0:1 @ 03a3a120] Setting 'channel_layout' to value '0x3'
[graph 0 input from stream 0:1 @ 03a3a120] tb:1/48000 samplefmt:s16 samplerate:48000 chlay
out:0x3
[audio format for output stream 0:0 @ 03a4d400] Setting 'sample_fmts' to value 's16'
[AVFilterGraph @ 03a40e00] query_formats: 4 queried, 9 merged, 0 already done, 0 delayed
Output #0, wav, to 'test.wav':
  Metadata:
    ISFT            : Lavf55.30.100
    Stream #0:0(eng), 0, 1/48000: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 48000 Hz, ster
eo, s16, 1536 kb/s (default) (forced)
Stream mapping:
  Stream #0:1 -> #0:0 (libopus -> pcm_s16le)
Press [q] to stop, [?] for help
[libopus @ 03a1bc20] skip 356/2880 samples
[libopus @ 03a1bc20] skip 0 samples due to side data/s
[libopus @ 03a1bc20] discard 2096/2880 samples
[output stream 0:0 @ 03a44980] EOF on sink link output stream 0:0:default.
No more output streams to write to, finishing.
size=   56330kB time=00:05:00.43 bitrate=1536.0kbits/s
video:0kB audio:56330kB subtitle:0 data:0 global headers:0kB muxing overhead 0.000139%
5008 frames successfully decoded, 0 decoding errors
[AVIOContext @ 03a38c00] Statistics: 4 seeks, 5011 writeouts
[AVIOContext @ 03a2bd40] Statistics: 55226607 bytes read, 0 seeks

While playing it through mpv does show the warning:

>mpv "C:\dap\vid\distro\Qyöt27 - Daybreak [10bit-444][H.264+Opus] distro.mkv"
Playing: C:\dap\vid\distro\Qyöt27 - Daybreak [10bit-444][H.264+Opus] distro.mkv
Detected file format: Matroska
[stream] Video (+) --vid=1 (h264)
[stream] Audio (+) --aid=1 --alang=eng (*) (opus)
[stream] Subs  (+) --sid=1 (*) 'Dummy Subtitles' (subrip)
[stream] Subs      --sid=2 --slang=eng 'Karaoke Subtitles [ASS]' (ass)
Selected video codec: H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 [lavc:h264]
[ffmpeg/audio] libopus: Could not update timestamps for skipped samples.
Selected audio codec: libopus Opus [lavc:libopus]
AO: [dsound] 48000Hz stereo 2ch s16
AV: 00:00:00 / 00:05:00 (0%) A-V:  0.000
VO: [opengl-old] 848x480 => 848x480 444p10
AV: 00:00:02 / 00:05:00 (0%) A-V:  5.333 Late: 47

And yes, that build of mpv was linked against that build of FFmpeg. And the only difference RE:Opus in FFmpeg's git master vs. 2.1.3 is this commit.

ghost commented 10 years ago

This warning happens because we basically refuse to give libavcodec "real" timestamps, thus it can't adjust the timestamp to skip it. In my opinion, this doesn't really belong into libavcodec anyway - it should just tell us how many samples were skipped.

haheute commented 10 years ago

Note that it indeed does nothing if the current file is the last on the internal playlist

that was the problem. sorry. < and > work. enter is also nice.