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
ffmpeg demuxer: faster channel change for PVR addons ... #3590
Conversation
// Set streaminfo false and skip avformat_find_stream_info (slow) | ||
// But we need a proper codec extradata so fill it in for ffmpeg. | ||
// This routine is taken from avformat_find_stream_info and friends. | ||
if(st->parser && st->parser->parser->split && !st->codec->extradata) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
I'd like to encourage this patch. It's been widely used in test builds on Pi with positive reports. |
It breaks http streaming for me too. |
@FernetMenta : I will add popcornmix@cda4e3c @popcornmix: Right, now I don't want to enable it for other purposes than Live TV, because this will also break quite some video addons (e.g. ITVPlayer, Vevo). I would like to stay on the safe side for Gotham right now... @whaupt : You mean popcornmix' addition or my original patch? |
@margro |
@popcornmix can you provide this mp4 file not working? |
I tested popcornmix changes with the DVBViewer PVR (it uses http streams) and it's working fine. Channel changes seem to be slightly faster. |
@margro I applied FernetMentas version on 12.2 and if I set streaminfo boolean to false for every protocol, it breaks http streaming. maybe my version reacts slightly different to gotham, just wanted to share my findings. |
@FernetMenta I've PM-ed you the mp4 file. |
the various formats behave slightly different. for mpeg-ts ffmpeg creates streams according to pat/pmt. when it creates a stream, it sets the need_parsing flag. I did a quick test with the provided mp4 file. there's no parser created for the video stream. changing the code to this made it work.
note, this was only a quick test. i think this can be done better. |
I can confirm @FernetMenta latest patch fixes the mp4 file. |
I sent some refactoring to @margro FernetMenta@c425470 I summarize:
@elupus what's your opinion on this? |
For the file playback case: I believe it avformat_find_stream_info is not just slow for non-indexed files, it is inaccurate (an arbitrary amount of time is parsed, and is a stream is not present during that time it is missed). Would skipping avformat_find_stream_info for non-indexed formats, but using it for index formats be reasonable? |
Or maybe we should limit the time for analysis in general. |
@FernetMenta: Added and tested your changes. Will squash them later. |
see Pivosgroup@4abd884 setting AVDISCARD_ALL might also only be valid for mpeg2/h264. It really depends on what the FFMpeg codec does when discarding. Generally you want to skip the actual decode but allow the codec to parse the stream info. |
I would not eat packets for a single stream. In case we know there is video and we are waiting for an IDR frame, we should eat all packets (audio as well). This is how I do it in vnsi. |
yep |
I really dislike this. Please fix ffmpeg :(. |
Fixing ffmpeg would require major work I think, It's designed a very static situation and to try very hard to obtain correct info no matter the cost in start up time. Even decoding several frames which is a real hurt under ARM with HD content. I've looked at what it does and I don't see a good/clean way to make a stream with known characteristics, startup faster. In general, we take 5 to 10 seconds (on ARM) after selection before there is any hint of a switch. Maybe FFMpeg debs would have a clue on how to handle this. |
The problem with ffmpeg is that the parser has no access to the decode extradata functions. fixing this and add a flag to ffmpeg to force continuous parsing of SPS would eliminate the need of instantiating a decoder here and also calling find_stream_info. |
You would still have to resolve FFMpeg doing full frame decodes when probing. This really hurts to do N-frames of 1080p on ARM. Each frame can take several hundred milliseconds to decode. |
Does anyone know why FFMpeg even needs to decode instead of parse? |
I did some more investigation. When reading packets through the format context, ffmpeg actually parses the packets. The problem is that it does not expose the desired info. The codec context is only updated when a frame is decoded. |
@elupus this argument is really weak. this may not be the perfect solution but it is much better than we have now. thousands of users do suffer from this problem. I suggest that you either work with us on this or you don't block our work. we are short final for Gotham and we need a solution. |
i'm not going to block it. but hate taking these types of approaches. |
@FernetMenta: just tested (and added) your latest changes. Works fine for me. Although, I'm not sure about the global reduction of the max_analyze_duration to 0.5 s. |
Can you point me to some of your test files or streams? I'm investigating a similar problem and would like to compare my XBMC and ff(av)play outputs with yours. |
please don't limit this to 'DVD+Live TV only.' :) When one is switching between one of several udp transport streams in a playlist, it's not a DVD nor it is LiveTV. |
Here is a fix that fixes mpegts startup for rtsp and any input source that didn't mark themself as non seekable. |
Above patch affects udp as well and makes the fixes to mark those unseekable redundant. |
#3837 for a more complete fix. Note, it will still be slow if we can't find all stream parameters. |
@elupus I've tested your #3837 change (taking a Gotham nightly + updated ffmpeg DLLs) together with the MediaPortal PVR addon in RTSP mode (XBMC playback of an rtsp:// URL) #3837 results:10s switch time before => 4s after #3590 results: 10s switch time before => 4s after, so identical results Now with the PVR addon in TSReader mode (PVR addon sends an MPEGTS transport stream to XBMC): #3837 results: 8s switch time before => 4s after #3590 results: 8s switch time before => 2s after So #3837 is indeed also a solution to reduce the switching time. Combining #3837 with this PR did not reduce the RTSP switching time, but MPEGTS switching time is further reduced from 4s to 2s. |
Good to hear. I've also sent #3837 upstream to ffmpeg. Not guaranteed to get in in it's current form since they might want to make it optional, since you can't force probing of whole files for further headers. But I think it has a very good chance. The next thing we likely should add to our ffmpeg is atleast to turn on discard for the decoding. We don't have that on in our code I think. But that only reduces cpu usage somewhat. 4s still seem long. have you tested ffprobe on that file? You can apply: http://pastebin.com/nKdiWjbZ to a stock ffmpeg and do: time ffprobe -v debug [rtspurl]. Would be intersting to see the output of that when tuning. |
if ffmpeg is still sw decoding the frames rather than decode w/skips set, an HD frame takes a long time on sw ffmpeg to decode. |
right, on Rpi it takes ages opening a mpegts file. #3837 won't help in this case. also find_stream_info rewinds the stream to pos zero and delivers crap to decoder. |
I've dropped the change to set AVDISCARD_ALL on startup upstream as an RFC (it breaks many many ffmpeg regression tests, so it's not a good change for us either). Rewind is normal. We should just make sure we can rewind the full probesize in our input stream. what do you mean delivers crap to decoder? |
mpegts is no container and the frames prior to first IDR may not be decoded correctly. It makes no sense delivering those packets to decoders. Other players like WMC don't either. |
that sounds more like a bug in the h264 codec. it should not send data to hw decoder that is invalid. |
ffmpeg ASSums that it's sw/hw decoder will handle it sync to IDR. But unless you are going through an ffmpeg decoder, that does not happen. For example, rPI and AML use ffmpeg for demux only and the actual hw decode is handles elsewhere. |
as for dropping AVDISCARD_ALL, some formats must decode the frame, all of it. Some like h264/mpeg2 can handle AVDISCARD_ALL |
@elupus: Here the results from ffprobe (ffmpeg master) before and after #3837 |
Well. It's for h264 that the ffmpeg regression tests fail for with that
|
Those logs look good to me. Takes some time before it finds the key frame Then again, shouldn't matter since we won't display anything before that |
Is there still a chance to get this one for Gotham? |
I'm against it in its current form. The large udp/rtsp delay has been solved in ffmpeg. If you want to push this, please build another demuxer. I don't want this one second guessing ffmpeg. A new mpegts demuxer would be a very good thing anyway since ffmpegs is rather bad. |
OK, thx for clarification. I just wanted to know the status of this PR because there was no discussion for about a month. |
Is this still relevant with the newer ffmpeg builds we're using these days? |
yes it is |
see #5487 |
without internal demuxing
(such as MediaPortal, ArgusTV, MythTV, NextPVR)
This pull request contains a Gotham port of the original work from @FernetMenta with a few changes from @davilla
(FernetMenta@bf753eb
It is a follow-up for #1757
FernetMenta asked me to port and test his work because he couldn't test it as a VDR user.