Opened 3 years ago

Closed 3 years ago

Last modified 2 years ago

#9782 closed defect (fixed)

avformat_find_stream_info too slow with open TS stream

Reported by: GJJ Owned by:
Priority: important Component: avformat
Version: git-master Keywords:
Cc: Marton Balint Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description (last modified by GJJ)

Summary of the bug: avformat_find_stream_info take too long time return, when open single video or audio TS stream.

How to reproduce:

  1. push
    %ffmpeg.exe -re -stream_loop -1 -i ./sdi-s.ts -c:v copy -c:a copy -f mpegts udp://127.0.0.1:50000
    
  2. recv
    %ffmpeg -i udp://127.0.0.1:50000
    ffmpeg version 5.0-essentials_build-www.gyan.dev Copyright (c) 2000-2022 the FFmpeg developers
      built with gcc 11.2.0 (Rev5, Built by MSYS2 project)
      configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-sdl2 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libgme --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libtheora --enable-libvo-amrwbenc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-librubberband
      libavutil      57. 17.100 / 57. 17.100
      libavcodec     59. 18.100 / 59. 18.100
      libavformat    59. 16.100 / 59. 16.100
      libavdevice    59.  4.100 / 59.  4.100
      libavfilter     8. 24.100 /  8. 24.100
      libswscale      6.  4.100 /  6.  4.100
      libswresample   4.  3.100 /  4.  3.100
      libpostproc    56.  3.100 / 56.  3.100
    [h264 @ 000002aab67f4b00] non-existing PPS 0 referenced
        Last message repeated 1 times
    [h264 @ 000002aab67f4b00] decode_slice_header error
    [h264 @ 000002aab67f4b00] no frame!
    [h264 @ 000002aab67f4b00] non-existing PPS 0 referenced
        Last message repeated 1 times
    [h264 @ 000002aab67f4b00] decode_slice_header error
    [h264 @ 000002aab67f4b00] no frame!
    [h264 @ 000002aab67f4b00] non-existing PPS 0 referenced
        Last message repeated 1 times
    [h264 @ 000002aab67f4b00] decode_slice_header error
    [h264 @ 000002aab67f4b00] no frame!
    [h264 @ 000002aab67f4b00] non-existing PPS 0 referenced
        Last message repeated 1 times
    [h264 @ 000002aab67f4b00] decode_slice_header error
    [h264 @ 000002aab67f4b00] no frame!
    [h264 @ 000002aab67f4b00] non-existing PPS 0 referenced
        Last message repeated 1 times
    [h264 @ 000002aab67f4b00] decode_slice_header error
    [h264 @ 000002aab67f4b00] no frame!
    [h264 @ 000002aab67f4b00] non-existing PPS 0 referenced
        Last message repeated 1 times
    [h264 @ 000002aab67f4b00] decode_slice_header error
    [h264 @ 000002aab67f4b00] no frame!
    [h264 @ 000002aab67f4b00] non-existing PPS 0 referenced
        Last message repeated 1 times
    [h264 @ 000002aab67f4b00] decode_slice_header error
    [h264 @ 000002aab67f4b00] no frame!
    [h264 @ 000002aab67f4b00] non-existing PPS 0 referenced
        Last message repeated 1 times
    [h264 @ 000002aab67f4b00] decode_slice_header error
    [h264 @ 000002aab67f4b00] no frame!
    [h264 @ 000002aab67f4b00] non-existing PPS 0 referenced
        Last message repeated 1 times
    [h264 @ 000002aab67f4b00] decode_slice_header error
    [h264 @ 000002aab67f4b00] no frame!
    [h264 @ 000002aab67f4b00] non-existing PPS 0 referenced
        Last message repeated 1 times
    [h264 @ 000002aab67f4b00] decode_slice_header error
    [h264 @ 000002aab67f4b00] no frame!
    [h264 @ 000002aab67f4b00] non-existing PPS 0 referenced
        Last message repeated 1 times
    [h264 @ 000002aab67f4b00] decode_slice_header error
    [h264 @ 000002aab67f4b00] no frame!
    [h264 @ 000002aab67f4b00] non-existing PPS 0 referenced
        Last message repeated 1 times
    [h264 @ 000002aab67f4b00] decode_slice_header error
    [h264 @ 000002aab67f4b00] no frame!
    [h264 @ 000002aab67f4b00] non-existing PPS 0 referenced
        Last message repeated 1 times
    [h264 @ 000002aab67f4b00] decode_slice_header error
    [h264 @ 000002aab67f4b00] no frame!
    [h264 @ 000002aab67f4b00] non-existing PPS 0 referenced
        Last message repeated 1 times
    [h264 @ 000002aab67f4b00] decode_slice_header error
    [h264 @ 000002aab67f4b00] no frame!
    [h264 @ 000002aab67f4b00] non-existing PPS 0 referenced
        Last message repeated 1 times
    [h264 @ 000002aab67f4b00] decode_slice_header error
    [h264 @ 000002aab67f4b00] no frame!
    [h264 @ 000002aab67f4b00] non-existing PPS 0 referenced
        Last message repeated 1 times
    [h264 @ 000002aab67f4b00] decode_slice_header error
    [h264 @ 000002aab67f4b00] no frame!
    [h264 @ 000002aab67f4b00] non-existing PPS 0 referenced
        Last message repeated 1 times
    [h264 @ 000002aab67f4b00] decode_slice_header error
    [h264 @ 000002aab67f4b00] no frame!
    [h264 @ 000002aab67f4b00] non-existing PPS 0 referenced
        Last message repeated 1 times
    [h264 @ 000002aab67f4b00] decode_slice_header error
    [h264 @ 000002aab67f4b00] no frame!
    [h264 @ 000002aab67f4b00] non-existing PPS 0 referenced
        Last message repeated 1 times
    [h264 @ 000002aab67f4b00] decode_slice_header error
    [h264 @ 000002aab67f4b00] no frame!
    [h264 @ 000002aab67f4b00] non-existing PPS 0 referenced
        Last message repeated 1 times
    [h264 @ 000002aab67f4b00] decode_slice_header error
    [h264 @ 000002aab67f4b00] no frame!
    [h264 @ 000002aab67f4b00] non-existing PPS 0 referenced
        Last message repeated 1 times
    [h264 @ 000002aab67f4b00] decode_slice_header error
    [h264 @ 000002aab67f4b00] no frame!
    [h264 @ 000002aab67f4b00] non-existing PPS 0 referenced
        Last message repeated 1 times
    [h264 @ 000002aab67f4b00] decode_slice_header error
    [h264 @ 000002aab67f4b00] no frame!
    [h264 @ 000002aab67f4b00] non-existing PPS 0 referenced
        Last message repeated 1 times
    [h264 @ 000002aab67f4b00] decode_slice_header error
    [h264 @ 000002aab67f4b00] no frame!
    [h264 @ 000002aab67f4b00] non-existing PPS 0 referenced
        Last message repeated 1 times
    [h264 @ 000002aab67f4b00] decode_slice_header error
    [h264 @ 000002aab67f4b00] no frame!
    [h264 @ 000002aab67f4b00] non-existing PPS 0 referenced
        Last message repeated 1 times
    [h264 @ 000002aab67f4b00] decode_slice_header error
    [h264 @ 000002aab67f4b00] no frame!
    [h264 @ 000002aab67f4b00] non-existing PPS 0 referenced
        Last message repeated 1 times
    [h264 @ 000002aab67f4b00] decode_slice_header error
    [h264 @ 000002aab67f4b00] no frame!
    [h264 @ 000002aab67f4b00] non-existing PPS 0 referenced
        Last message repeated 1 times
    [h264 @ 000002aab67f4b00] decode_slice_header error
    [h264 @ 000002aab67f4b00] no frame!
    
    Input #0, mpegts, from 'udp://172.16.171.10:50000':
      Duration: N/A, start: 2642.758444, bitrate: N/A
      Program 1
        Metadata:
          service_name    : Service01
          service_provider: FFmpeg
      Stream #0:0[0x100]: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuvj420p(pc, bt709, progressive), 1920x1080, 30 tbr, 90k tbn
    

or:

%ffmpeg -analyzeduration 1G -probesize 1G -i udp://127.0.0.1:50000

ref: https://trac.ffmpeg.org/ticket/4090

Attachments (2)

sdi-s.ts (2.4 MB ) - added by GJJ 3 years ago.
dolby_hevc_aac.ts (2.1 MB ) - added by luckysk 2 years ago.
There are two streams, but only audio can be recognized,

Change History (13)

comment:1 by Balling, 3 years ago

Where is the sample? 172.16.171.10 is available only to you.

by GJJ, 3 years ago

Attachment: sdi-s.ts added

comment:2 by GJJ, 3 years ago

Description: modified (diff)

in reply to:  1 comment:3 by GJJ, 3 years ago

Replying to Balling:

Where is the sample? 172.16.171.10 is available only to you.

I uploaded a test file, And pushed patch https://patchwork.ffmpeg.org/project/ffmpeg/patch/TYCP286MB2608ADF800E6A464B1BB9F4BC7CF9@TYCP286MB2608.JPNP286.PROD.OUTLOOK.COM/
Thanks for your advice.

comment:4 by GJJ, 3 years ago

Description: modified (diff)

comment:5 by Balling, 3 years ago

So the bug is that ffplay -analyzeduration 1G -probesize 1G -i udp://127.0.0.1:50000 does not open?

And that Stream #0:0[0x100]: Video: h264 is only there after you do Ctrl-C?

It does not work on HEAD of master either.

Last edited 3 years ago by Balling (previous) (diff)

comment:7 by Marton Balint, 3 years ago

Cc: Marton Balint added

It seems that part of code is some hack for broken files from the old times.

I have sent a patch which eliminates it more completetly.

https://patchwork.ffmpeg.org/project/ffmpeg/patch/20220615053442.8300-1-cus@passwd.hu/

Also note that for ffmpeg tests I needed to specify -scan_all_pmts 0 to be able to test this, otherwise it does not really make a difference, because ffmpeg implicitly sets it to 1 which ultimately causes the code in avformat_find_stream_info() to effectively read the whole probesize during probing.

in reply to:  7 comment:8 by GJJ, 3 years ago

Replying to Marton Balint:

It seems that part of code is some hack for broken files from the old times.

I have sent a patch which eliminates it more completetly.

https://patchwork.ffmpeg.org/project/ffmpeg/patch/20220615053442.8300-1-cus@passwd.hu/

Also note that for ffmpeg tests I needed to specify -scan_all_pmts 0 to be able to test this, otherwise it does not really make a difference, because ffmpeg implicitly sets it to 1 which ultimately causes the code in avformat_find_stream_info() to effectively read the whole probesize during probing.

✅passed in my test.
@Marton Balint Thks for your patch

comment:9 by Marton Balint, 3 years ago

Resolution: fixed
Status: newclosed

by luckysk, 2 years ago

Attachment: dolby_hevc_aac.ts added

There are two streams, but only audio can be recognized,

comment:10 by luckysk, 2 years ago

However, 58df81b02779c9c87cbf5403cfdbb437d5344669 makes other ffmpeg based players(such as mpv,mplayer etc)unable to recognize video when playing some ts files. Do you want to confirm?
The dolby_ hevc_ aac.ts can reproduce this problem. Before this submission, with mpv player the video can be recognized and playback well. Now it can only play audio.

in reply to:  10 comment:11 by Balling, 2 years ago

Replying to luckysk:

However, 58df81b02779c9c87cbf5403cfdbb437d5344669 makes other ffmpeg based players(such as mpv,mplayer etc)unable to recognize video when playing some ts files. Do you want to confirm?
The dolby_ hevc_ aac.ts can reproduce this problem. Before this submission, with mpv player the video can be recognized and playback well. Now it can only play audio.

That is because a) dolby_hevc_aac.ts is buggy, -c copy -strict unofficial shows b) they do not set scan_all_pmts 1, but there is a pull request for this: https://github.com/mpv-player/mpv/pull/10550 c) mpv has its own parsers that allow to parse sound in all cases, even if ffplay cannot: #8712.

Last edited 2 years ago by Balling (previous) (diff)
Note: See TracTickets for help on using tickets.