Opened 2 years ago

#5310 new defect

mpegts demuxer ignores the amount of samples it should drop from the last Opus frame

Reported by: jamrial Owned by:
Priority: normal Component: avcodec
Version: git-master Keywords: opus mpegts
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

$ ./ffmpeg -v 0 -f lavfi -i "aevalsrc=cos(2*PI*t)*sin(2*PI*(440+4*t)*t)::d=20" -ac 2 -c:a libopus -y test.mka && ./ffmpeg -i test.mka -f md5 -
ffmpeg version N-78958-g8c24523 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 5.3.0 (Rev2, Built by MSYS2 project)
  configuration: --enable-gpl --enable-nonfree --enable-libfdk-aac --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-opengl --target-os=mingw32 --arch=x86_64 --cpu=haswell --extra-cflags='-D_WIN32_WINNT=0x0600' --samples=../samples --prefix=/mingw64
  libavutil      55. 19.100 / 55. 19.100
  libavcodec     57. 28.100 / 57. 28.100
  libavformat    57. 28.100 / 57. 28.100
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 39.102 /  6. 39.102
  libswscale      4.  0.100 /  4.  0.100
  libswresample   2.  0.101 /  2.  0.101
  libpostproc    54.  0.100 / 54.  0.100
Input #0, matroska,webm, from 'test.mka':
  Metadata:
    ENCODER         : Lavf57.28.100
  Duration: 00:00:20.02, start: 0.007000, bitrate: 160 kb/s
    Stream #0:0: Audio: opus, 48000 Hz, stereo, fltp (default)
    Metadata:
      ENCODER         : Lavc57.28.100 libopus
      DURATION        : 00:00:20.023000000
Output #0, md5, to 'pipe:':
  Metadata:
    encoder         : Lavf57.28.100
    Stream #0:0: Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s (default)
    Metadata:
      DURATION        : 00:00:20.023000000
      encoder         : Lavc57.28.100 pcm_s16le
Stream mapping:
  Stream #0:0 -> #0:0 (opus (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
MD5=8a31a3522806e330cb9200b29848b480
size=       0kB time=00:00:20.02 bitrate=   0.0kbits/s speed= 223x
video:0kB audio:3754kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

$ ./ffmpeg -v 0 -f lavfi -i "aevalsrc=cos(2*PI*t)*sin(2*PI*(440+4*t)*t)::d=20" -ac 2 -c:a libopus -y test.opus && ./ffmpeg -i test.opus -f md5 -
ffmpeg version N-78958-g8c24523 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 5.3.0 (Rev2, Built by MSYS2 project)
  configuration: --enable-gpl --enable-nonfree --enable-libfdk-aac --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-opengl --target-os=mingw32 --arch=x86_64 --cpu=haswell --extra-cflags='-D_WIN32_WINNT=0x0600' --samples=../samples --prefix=/mingw64
  libavutil      55. 19.100 / 55. 19.100
  libavcodec     57. 28.100 / 57. 28.100
  libavformat    57. 28.100 / 57. 28.100
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 39.102 /  6. 39.102
  libswscale      4.  0.100 /  4.  0.100
  libswresample   2.  0.101 /  2.  0.101
  libpostproc    54.  0.100 / 54.  0.100
Input #0, ogg, from 'test.opus':
  Duration: 00:00:20.02, start: 0.000000, bitrate: 158 kb/s
    Stream #0:0: Audio: opus, 48000 Hz, stereo, fltp
    Metadata:
      ENCODER         : Lavc57.28.100 libopus
Output #0, md5, to 'pipe:':
  Metadata:
    encoder         : Lavf57.28.100
    Stream #0:0: Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s
    Metadata:
      encoder         : Lavc57.28.100 pcm_s16le
Stream mapping:
  Stream #0:0 -> #0:0 (opus (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
MD5=8a31a3522806e330cb9200b29848b480
size=       0kB time=00:00:20.01 bitrate=   0.0kbits/s speed= 232x
video:0kB audio:3754kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

$ ./ffmpeg -v 0 -f lavfi -i "aevalsrc=cos(2*PI*t)*sin(2*PI*(440+4*t)*t)::d=20" -ac 2 -c:a libopus -y test.ts && ./ffmpeg -i test.ts -f md5 -
ffmpeg version N-78958-g8c24523 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 5.3.0 (Rev2, Built by MSYS2 project)
  configuration: --enable-gpl --enable-nonfree --enable-libfdk-aac --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-opengl --target-os=mingw32 --arch=x86_64 --cpu=haswell --extra-cflags='-D_WIN32_WINNT=0x0600' --samples=../samples --prefix=/mingw64
  libavutil      55. 19.100 / 55. 19.100
  libavcodec     57. 28.100 / 57. 28.100
  libavformat    57. 28.100 / 57. 28.100
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 39.102 /  6. 39.102
  libswscale      4.  0.100 /  4.  0.100
  libswresample   2.  0.101 /  2.  0.101
  libpostproc    54.  0.100 / 54.  0.100
Input #0, mpegts, from 'test.ts':
  Duration: 00:00:20.00, start: 1.400000, bitrate: 182 kb/s
  Program 1
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Audio: opus (Opus / 0x7375704F), 48000 Hz, stereo, fltp
Output #0, md5, to 'pipe:':
  Metadata:
    encoder         : Lavf57.28.100
    Stream #0:0: Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s
    Metadata:
      encoder         : Lavc57.28.100 pcm_s16le
Stream mapping:
  Stream #0:0 -> #0:0 (opus (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
MD5=370faa46e5371aa3f65a54bee8ef402a
size=       0kB time=00:00:20.04 bitrate=   0.0kbits/s speed= 228x
video:0kB audio:3758kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

If you add -loglevel debug when decoding the Matroska and OggOpus? files you get the following:

[opus @ 0000016b4bb2a6c0] skip 0 / discard 859 samples due to side data
[opus @ 0000016b4bb2a6c0] discard 859/960 samples
[output stream 0:0 @ 0000016b4bb2ec60] EOF on sink link output stream 0:0:default.
No more output streams to write to, finishing.
MD5=8a31a3522806e330cb9200b29848b480
size=       0kB time=00:00:20.01 bitrate=   0.0kbits/s speed= 233x
video:0kB audio:3754kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Input file #0 (test.opus):
  Input stream #0:0 (audio): 1002 packets read (394264 bytes); 1002 frames decoded (961061 samples);
  Total: 1002 packets (394264 bytes) demuxed
Output file #0 (pipe:):
  Output stream #0:0 (audio): 1002 frames encoded (961061 samples); 1002 packets muxed (3844244 bytes);
  Total: 1002 packets (3844244 bytes) muxed

Whereas the mpegts file reports

[output stream 0:0 @ 0000028b48dc2800] EOF on sink link output stream 0:0:default.
No more output streams to write to, finishing.
MD5=370faa46e5371aa3f65a54bee8ef402a
size=       0kB time=00:00:20.04 bitrate=   0.0kbits/s speed= 232x
video:0kB audio:3758kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Input file #0 (test.ts):
  Input stream #0:0 (audio): 1002 packets read (397055 bytes); 1002 frames decoded (961920 samples);
  Total: 1002 packets (397055 bytes) demuxed
Output file #0 (pipe:):
  Output stream #0:0 (audio): 1002 frames encoded (961920 samples); 1002 packets muxed (3847680 bytes);
  Total: 1002 packets (3847680 bytes) muxed
1002 frames successfully decoded, 0 decoding errors

Notice the lack of discarded samples debug messages, and the amount of samples the latter decoded.
Our mpegts muxer adds this information (Opus specific code in mpegts_write_packet_internal() from mpegtsenc.o), but the demuxer is unaware of it. It's all handled and ignored by the Opus parser in libavcodec instead.

Change History (0)

Note: See TracTickets for help on using tickets.