Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It suddenly stops while playing an online video #317

Closed
yikuo123 opened this issue Oct 20, 2022 · 14 comments
Closed

It suddenly stops while playing an online video #317

yikuo123 opened this issue Oct 20, 2022 · 14 comments

Comments

@yikuo123
Copy link

yikuo123 commented Oct 20, 2022

Just like #238.

I tried FFmepgInteropX version 0.9.4, 1.0.1 and 1.1.0-pre24, but all of them are the same. A few minutes later (about 3 minutes), MediaPlayer will stop and the timeline just jump to the end.

I also tried playing video with the original Windows.Media.Core.MediaSource and it's ok.

public sealed partial class MainPage : Page
{
    private MediaPlayer _mediaPlayer;
    private FFmpegMediaSource _currentMediaSource;

    public MainPage()
    {
        this.InitializeComponent();
        this.Loaded += MainPage_Loaded;
    }

    private async void MainPage_Loaded(object sender, RoutedEventArgs e)
    {
        _mediaPlayer = new MediaPlayer();
        _mediaPlayer.AutoPlay = true;
        _mediaPlayer.AudioCategory = MediaPlayerAudioCategory.Movie;
        MyMediaPlayerElement.SetMediaPlayer(_mediaPlayer);
        
        var url = @"https://f.video.weibocdn.com/o0/VbwYocF4lx0808KL6sCQ01041200LhGB0E010.mp4?label=mp4_hd&template=852x480.25.0&ori=0&ps=1BThihd3VLAY5R&Expires=1666285374&ssig=IpiL%2BhhyCq&KID=unistore,video";
        _currentMediaSource = await FFmpegMediaSource.CreateFromUriAsync(url, new MediaSourceConfig {
            VideoDecoderMode = FFmpegInteropX.VideoDecoderMode.ForceSystemDecoder,
        });
        _mediaPlayer.Source = _currentMediaSource.CreateMediaPlaybackItem();
    }
}

The URL in demo may become invalid. But URL is not important, I tried about 10 online videos and they are all the same.
I'm not sure how long it will reproduce but it will.
If the URL becomes invalid, you can get a new one by playing video at this link and right click to copy a new URL.

@yikuo123 yikuo123 changed the title It suddenly stop while playing a online video It suddenly stops while playing an online video Oct 20, 2022
@lukasf
Copy link
Member

lukasf commented Oct 20, 2022

The URL is invalid and I also cannot play any videos on that site without creating an account and logging in. Please check the debug output and post end of output. I guess we either get EOF, or there is some error. Debug output might help identifying the issue.

You could also check the FormatInfo property to see which streaming format is used. We might be able to find a similar sample stream from a site that does not require registration.

I have been seeing EOF in rtsp streams (#280). There was not much I could do about that. It was FFmpeg reporting EOF and there was no way of recovering.

@yikuo123
Copy link
Author

yikuo123 commented Oct 20, 2022

Sorry, I can't find any debug outputs and there is the video information.

{FFmpegInteropX.VideoStreamInfo}
    Bitrate: 280270
    BitsPerSample: 24
    CodecName: "h264"
    DecoderEngine: SystemDecoder
    DisplayAspectRatio: 1.7722265624999998
    Disposition: Default
    FramesPerSecond: 30
    FramesPerSecondOverride: 0
    HardwareDecoderStatus: Available
    IsDefault: true
    Language: "und"
    Name: "und"
    PixelHeight: 480
    PixelWidth: 852
{FFmpegInteropX.FormatInfo}
    Bitrate: 334280
    Duration: {00:04:29.6990000}
    FormatName: "mov,mp4,m4a,3gp,3g2,mj2"
    Title: ""

I download this video and compress it with 7zip, please remove “.zip” from the filename.(There is file size and file name limits.)

It also works well with VLC.

test.7z.001.zip
test.7z.002.zip

@lukasf
Copy link
Member

lukasf commented Oct 20, 2022

Does the problem also occur when playing the downloaded file? I'd guess it only happens when playing through streaming. I have played the downloaded file twice and it plays fine till the end.

Our lib, as well as ffmpeg will write debug output that can be seen in VS output window while debugging the app.

This is what I see in VS on end of local file playback:

GetNextSample
GetNextPacket reaching EOF
End of stream reached. Enter draining mode.
GetNextSample
GetNextSample
End of stream reached. No more samples in decoder.
End of stream reached.
DisableStream
Flush
The thread 0x3690 has exited with code 0 (0x0).
The thread 0x3c58 has exited with code 0 (0x0).
The thread 0x584c has exited with code 0 (0x0).

VLC has its own custom stream parsing and download implementation. It only uses FFmpeg for the actual decoding. That is why you cannot really compare VLC to our lib when it comes to streaming scenarios. You should rather use ffplay for comparison, since it will also use FFmpeg for stream parsing (and best use the exact same version that we are using as a lib).

@brabebhin
Copy link
Collaborator

I think (might be mistaken) that you need either mixed or native debugger to see that output.

@yikuo123
Copy link
Author

yikuo123 commented Oct 21, 2022

Thanks for your quick reply!

I tried many times and it looks like that there are always some exceptions when the media stops.

I'll try to make a permanent link for this video to test online streaming.

This is the permanent link:

https://raw.githubusercontent.com/yikuo123/ffmepg-test/master/test.mp4

or

https://cdn.jsdelivr.net/gh/yikuo123/ffmepg-test/test.mp4

onecore\base\windows.storage\src\win32proxy.cpp(374)\windows.storage.onecore.dll!00007FFE86CDF1F7: (caller: 00007FFEBFF420AA) LogHr(21) tid(11740) 80070005 Access is denied.
    CallContext:[\GetFileAttributesProxyActivity] 
onecore\base\windows.storage\src\win32proxy.cpp(553)\windows.storage.onecore.dll!00007FFE86CDE7A1: (caller: 00007FFEBFF37402) Exception(11) tid(11740) 8007109C This functionality is not supported in the context of an app container.
    CallContext:[\CreateDirectoryProxyActivity] 
Exception thrown at 0x00007FFEBFF9FB0C in App.exe: Microsoft C++ exception: wil::ResultException at memory location 0x000000CB4F579EE0.
Exception thrown at 0x00007FFEBFF9FB0C in App.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000.
onecore\base\windows.storage\src\win32proxy.cpp(571)\windows.storage.onecore.dll!00007FFE86CE11CC: (caller: 00007FFEBFF37402) LogHr(22) tid(11740) 8007109C This functionality is not supported in the context of an app container.
    CallContext:[\CreateDirectoryProxyActivity] 
onecore\base\windows.storage\src\win32proxy.cpp(374)\windows.storage.onecore.dll!00007FFE86CDF1F7: (caller: 00007FFEBFF420AA) LogHr(23) tid(11740) 80070005 Access is denied.
    CallContext:[\GetFileAttributesProxyActivity] 
onecore\base\windows.storage\src\win32proxy.cpp(553)\windows.storage.onecore.dll!00007FFE86CDE7A1: (caller: 00007FFEBFF37402) Exception(12) tid(11740) 8007109C This functionality is not supported in the context of an app container.
    CallContext:[\CreateDirectoryProxyActivity] 
Exception thrown at 0x00007FFEBFF9FB0C in App.exe: Microsoft C++ exception: wil::ResultException at memory location 0x000000CB4F579590.
Exception thrown at 0x00007FFEBFF9FB0C in App.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000.
onecore\base\windows.storage\src\win32proxy.cpp(571)\windows.storage.onecore.dll!00007FFE86CE11CC: (caller: 00007FFEBFF37402) LogHr(24) tid(11740) 8007109C This functionality is not supported in the context of an app container.
    CallContext:[\CreateDirectoryProxyActivity] 
The thread 0xba90 has exited with code 0 (0x0).
The thread 0xcd84 has exited with code 0 (0x0).
The thread 0xde44 has exited with code 0 (0x0).
The thread 0x8cc8 has exited with code 0 (0x0).
The thread 0x942c has exited with code 0 (0x0).
The thread 0xef28 has exited with code 0 (0x0).
The thread 0x121a8 has exited with code 0 (0x0).
onecore\base\windows.storage\src\win32proxy.cpp(374)\windows.storage.onecore.dll!00007FFE86CDF1F7: (caller: 00007FFEBFF420AA) LogHr(21) tid(89f0) 80070005 Access is denied.
    CallContext:[\GetFileAttributesProxyActivity] 
onecore\base\windows.storage\src\win32proxy.cpp(553)\windows.storage.onecore.dll!00007FFE86CDE7A1: (caller: 00007FFEBFF37402) Exception(11) tid(89f0) 8007109C This functionality is not supported in the context of an app container.
    CallContext:[\CreateDirectoryProxyActivity] 
Exception thrown at 0x00007FFEBFF9FB0C in App.exe: Microsoft C++ exception: wil::ResultException at memory location 0x000000C918BF9FC0.
Exception thrown at 0x00007FFEBFF9FB0C in App.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000.
onecore\base\windows.storage\src\win32proxy.cpp(571)\windows.storage.onecore.dll!00007FFE86CE11CC: (caller: 00007FFEBFF37402) LogHr(22) tid(89f0) 8007109C This functionality is not supported in the context of an app container.
    CallContext:[\CreateDirectoryProxyActivity] 
onecore\base\windows.storage\src\win32proxy.cpp(374)\windows.storage.onecore.dll!00007FFE86CDF1F7: (caller: 00007FFEBFF420AA) LogHr(23) tid(89f0) 80070005 Access is denied.
    CallContext:[\GetFileAttributesProxyActivity] 
onecore\base\windows.storage\src\win32proxy.cpp(553)\windows.storage.onecore.dll!00007FFE86CDE7A1: (caller: 00007FFEBFF37402) Exception(12) tid(89f0) 8007109C This functionality is not supported in the context of an app container.
    CallContext:[\CreateDirectoryProxyActivity] 
Exception thrown at 0x00007FFEBFF9FB0C in App.exe: Microsoft C++ exception: wil::ResultException at memory location 0x000000C918BF9670.
Exception thrown at 0x00007FFEBFF9FB0C in App.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000.
onecore\base\windows.storage\src\win32proxy.cpp(571)\windows.storage.onecore.dll!00007FFE86CE11CC: (caller: 00007FFEBFF37402) LogHr(24) tid(89f0) 8007109C This functionality is not supported in the context of an app container.
    CallContext:[\CreateDirectoryProxyActivity] 
The thread 0x12ef0 has exited with code 0 (0x0).
The thread 0x6664 has exited with code 0 (0x0).
The thread 0x8ab4 has exited with code 0 (0x0).
The thread 0x11ec4 has exited with code 0 (0x0).
The thread 0x10f60 has exited with code 0 (0x0).

@yikuo123
Copy link
Author

yikuo123 commented Oct 21, 2022

I played this online video with ffplay and it also suddenly stops. It looks like this issue is about ffmpeg. What else we can do?

.\ffplay.exe "https://f.video.weibocdn.com/o0/VbwYocF4lx0808KL6sCQ01041200LhGB0E010.mp4?label=mp4_hd&template=852x480.25.0&ori=0&ps=1BThihd3VLAY5R&Expires=1666321355&ssig=NPsR64Rmk9&KID=unistore,video"
ffplay version 5.1.2-essentials_build-www.gyan.dev Copyright (c) 2003-2022 the FFmpeg developers
  built with gcc 12.1.0 (Rev2, 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. 28.100 / 57. 28.100
  libavcodec     59. 37.100 / 59. 37.100
  libavformat    59. 27.100 / 59. 27.100
  libavdevice    59.  7.100 / 59.  7.100
  libavfilter     8. 44.100 /  8. 44.100
  libswscale      6.  7.100 /  6.  7.100
  libswresample   4.  7.100 /  4.  7.100
  libpostproc    56.  6.100 / 56.  6.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'https://f.video.weibocdn.com/o0/VbwYocF4lx0808KL6sCQ01041200LhGB0E010.mp4?label=mp4_hd&template=852x480.25.0&ori=0&ps=1BThihd3VLAY5R&Expires=1666321355&ssig=NPsR64Rmk9&KID=unistore,video':
  Metadata:
    minor_version   : 512
    major_brand     : isom
    compatible_brands: isomiso2mp41
    comment         : mid:NDgyNjc3MTc2NjU3NTEwNg==
    moov_ahead      : 1
    is_open_gop     : 0
    encoder         : Lavf58.20.100
  Duration: 00:04:29.70, start: 0.000000, bitrate: 334 kb/s
  Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 852x480 [SAR 640:639 DAR 16:9], 280 kb/s, 30 fps, 30 tbr, 30k tbn (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
  Stream #0:1[0x2](und): Audio: aac (HE-AAC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 48 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
[tls @ 000001e1d7b2b680] Error in the pull function.=    0B f=0/0
[tls @ 000001e1d7b2b680] IO error: End of file
[https @ 000001e1d7b2c680] Stream ends prematurely at 4995928, should be 11269405
[mov,mp4,m4a,3gp,3g2,mj2 @ 000001e1d7b2b080] Packet corrupt (stream = 1, dts = 5319742).
[mov,mp4,m4a,3gp,3g2,mj2 @ 000001e1d7b2b080] stream 0, offset 0x4c3b9a: partial file
[tls @ 000001e1d7b2b680] The specified session has been invalidated for some reason.
[aac @ 000001e1ddbd98c0] Input buffer exhausted before END element found

Playing local file is OK.

If I replace "https" in URL to "http", the error information will be

[http @ 000001d9d90ac480] Stream ends prematurely at 5285336, should be 11269405
[mov,mp4,m4a,3gp,3g2,mj2 @ 000001d9d90aae80] Packet corrupt (stream = 0, dts = 3842000).
[NULL @ 000001d9d90c0440] Invalid NAL unit size (5199 > 3997).
[NULL @ 000001d9d90c0440] missing picture in access unit with size 4001
[mov,mp4,m4a,3gp,3g2,mj2 @ 000001d9d90aae80] stream 0, offset 0x50aa8a: partial file
[http @ 000001d9d90ac480] Stream ends prematurely at 5285336, should be 11269405
[h264 @ 000001d9dedb77c0] Invalid NAL unit size (5199 > 3997).0/0
[h264 @ 000001d9dedb77c0] Error splitting the input into NAL units.

@brabebhin
Copy link
Collaborator

I also noticed some video files suddenly becoming very choppy or outright video playback freezes, and this happens on local files. I too suspect the latest ffmpeg is a bit flimsy.

@yikuo123
Copy link
Author

yikuo123 commented Oct 21, 2022

I also noticed some video files suddenly becoming very choppy or outright video playback freezes, and this happens on local files. I too suspect the latest ffmpeg is a bit flimsy.

I just tried ffplay version 4.4.1, 5.0.1, 5.1.2, but all of them don't work.

@lukasf
Copy link
Member

lukasf commented Oct 21, 2022

It sounds like the server just drops the connection occasionally (or sends response data too late / timeout). The ffplay.exe you have use gnutls for https, ours use openssl for https, when using http, it is ffmpeg internal http handler. If all these three handlers show the same behavior, then it is probably just an unreliable server.

I found these ffmpeg options, which sound like they could help:

reconnect_at_eof

If set then eof is treated like an error and causes reconnection, this is useful for live / endless streams.

reconnect_streamed

If set then even streamed/non seekable streams will be reconnected on errors.

reconnect_on_network_error

Reconnect automatically in case of TCP/TLS errors during connect.

reconnect_on_http_error

A comma separated list of HTTP status codes to reconnect on. The list can include specific status codes (e.g. ’503’) or the strings ’4xx’ / ’5xx’.

reconnect_delay_max

Sets the maximum delay in seconds after which to give up reconnecting

Put these to FFmpegOptions in our config class with value "1" to enable an option. Not sure if this will help, but it sounds like you can use them so ffmpeg will retry transmission on error or incorrect eof.

@lukasf
Copy link
Member

lukasf commented Oct 21, 2022

Oh and for streaming I'd recommend trying the new ReadAheadBuffer in our lib (enable it in the config class). This will download and buffer a configurable amount of data, to allow uninterrupted playback of streams. This is available in the latest prerelease nuget package.

@yikuo123
Copy link
Author

@lukasf Thanks! It almost works! The most important thing is -reconnect 1

ffplay with these options works very well:

ffplay.exe -reconnect 1 -reconnect_at_eof 1 -reconnect_streamed 1 -reconnect_on_network_error 1 "https://raw.githubusercontent.com/yikuo123/ffmepg-test/master/test.mp4"

It outputs as below:

[tls @ 0000022b4f4ae480] Error in the pull function.=    0B f=0/0
[tls @ 0000022b4f4ae480] IO error: End of file
[https @ 0000022b4f4ae680] Stream ends prematurely at 5569367, should be 11269405
[https @ 0000022b4f4ae680] Will reconnect at 5569367 in 0 second(s), error=I/O error.
[tls @ 0000022b5776a940] Error in the pull function.=    0B f=0/0
[tls @ 0000022b5776a940] IO error: End of file
[https @ 0000022b4f4ae680] Stream ends prematurely at 9008812, should be 11269405
[https @ 0000022b4f4ae680] Will reconnect at 9008812 in 0 second(s), error=I/O error.
[tls @ 0000022b5776ac80] Error in the pull function.=    0B f=0/0
[tls @ 0000022b5776ac80] IO error: Error number -10054 occurred
[https @ 0000022b4f4ae680] Will reconnect at 11121153 in 0 second(s), error=Error number -10054 occurred.

I'll try these options with FFmpegInteropX.

Thanks again!

@yikuo123
Copy link
Author

yikuo123 commented Oct 22, 2022

I found that -reconnect_at_eof 1 causes live video problem, just remove it.

FFmpegInteropX with these options works very well too!

FFmpegOptions = new Windows.Foundation.Collections.PropertySet {
    { "reconnect", 1 },
    { "reconnect_streamed", 1 },
    { "reconnect_on_network_error", 1 },
},

Thank both of you! These problems have bothered me for a long time and now they have gone!

By the way, is it ok to add these tips to README? I think there may be other people like me.

@lukasf
Copy link
Member

lukasf commented Oct 23, 2022

Cool, this is really good to hear! Yes I think we should add a readme section for streaming, and describe the recommended parameters.

@lukasf
Copy link
Member

lukasf commented Nov 21, 2022

Closing this, since the issue is solved and documentation has been added.

@lukasf lukasf closed this as completed Nov 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants