how to avoid add m_pFormatContext->start_time to seek_pts in FFmpegStream::SeekTime?
Closed this issue · 24 comments
my rtsp stream broken when i seek in kodi.
but it play well in potplayer.
so i use tcpdump to find out whats the different.
after that i use tcpdump to catch packages between my iptv provider and my iptv box
i found the different:
Range: npt=245-\r\n
the 245 is “the number of seconds that elapsed from the start of the stream"
and i use potplayer to play the rtsp stream:
i got
Range: npt=152.909-\r\n
and everything works well.
but kodi send a value that is much larger than the length of the entire stream.
for example:
Range: npt=10889.373-\r\n
and it should be 38.
i find these in kodi‘s logs
2023-03-19 19:39:36.248 T:18072 DEBUG <general>: AddOnLog: inputstream.ffmpegdirect: ffmpegdirect::FFmpegStream::Open - av_find_stream_info finished
2023-03-19 19:39:36.248 T:18072 INFO <general>: AddOnLog: inputstream.ffmpegdirect: ffmpeg[EA45BCCB]: Input #0, rtsp, from 'rtsp://mystream.url&playseek=20230319190000-20230319193200':
2023-03-19 19:39:36.248 T:18072 INFO <general>: AddOnLog: inputstream.ffmpegdirect: ffmpeg[EA45BCCB]: Metadata:
2023-03-19 19:39:36.248 T:18072 INFO <general>: AddOnLog: inputstream.ffmpegdirect: ffmpeg[EA45BCCB]: title : vod
2023-03-19 19:39:36.248 T:18072 INFO <general>: AddOnLog: inputstream.ffmpegdirect: ffmpeg[EA45BCCB]: Duration: 00:32:00.00, start: 26328.772378, bitrate: N/A
2023-03-19 19:39:36.248 T:18072 INFO <general>: AddOnLog: inputstream.ffmpegdirect: ffmpeg[EA45BCCB]: Program 1
2023-03-19 19:39:36.248 T:18072 INFO <general>: AddOnLog: inputstream.ffmpegdirect: ffmpeg[EA45BCCB]: Metadata:
2023-03-19 19:39:36.248 T:18072 INFO <general>: AddOnLog: inputstream.ffmpegdirect: ffmpeg[EA45BCCB]: service_name : CCTV1-HD-I
2023-03-19 19:39:36.248 T:18072 INFO <general>: AddOnLog: inputstream.ffmpegdirect: ffmpeg[EA45BCCB]: service_provider:
2023-03-19 19:39:36.249 T:18072 INFO <general>: AddOnLog: inputstream.ffmpegdirect: ffmpeg[EA45BCCB]: Stream #0:0: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 100 tbr, 90k tbn, 50 tbc
2023-03-19 19:39:36.249 T:18072 INFO <general>: AddOnLog: inputstream.ffmpegdirect: ffmpeg[EA45BCCB]: Stream #0:1: Audio: aac (LC), 48000 Hz, stereo, fltp, 131 kb/s
2023-03-19 19:39:36.249 T:18072 DEBUG <general>: AddOnLog: inputstream.ffmpegdirect: CDVDDemuxFFmpeg::AddStream ID: 0
2023-03-19 19:39:36.249 T:18072 DEBUG <general>: AddOnLog: inputstream.ffmpegdirect: CDVDDemuxFFmpeg::AddStream ID: 1
2023-03-19 19:39:36.249 T:18072 INFO <general>: AddOnLog: inputstream.ffmpegdirect: ffmpeg[EA45BCCB]: Input #0, rtsp, from 'rtsp://mystream.url&playseek=20230319190000-20230319193200':
2023-03-19 19:39:36.249 T:18072 INFO <general>: AddOnLog: inputstream.ffmpegdirect: ffmpeg[EA45BCCB]: Metadata:
2023-03-19 19:39:36.249 T:18072 INFO <general>: AddOnLog: inputstream.ffmpegdirect: ffmpeg[EA45BCCB]: title : vod
2023-03-19 19:39:36.249 T:18072 INFO <general>: AddOnLog: inputstream.ffmpegdirect: ffmpeg[EA45BCCB]: Duration: 00:32:00.00, start: 26328.772378, bitrate: N/A
2023-03-19 19:39:36.249 T:18072 INFO <general>: AddOnLog: inputstream.ffmpegdirect: ffmpeg[EA45BCCB]: Program 1
2023-03-19 19:39:36.249 T:18072 INFO <general>: AddOnLog: inputstream.ffmpegdirect: ffmpeg[EA45BCCB]: Metadata:
2023-03-19 19:39:36.249 T:18072 INFO <general>: AddOnLog: inputstream.ffmpegdirect: ffmpeg[EA45BCCB]: service_name : CCTV1-HD-I
2023-03-19 19:39:36.249 T:18072 INFO <general>: AddOnLog: inputstream.ffmpegdirect: ffmpeg[EA45BCCB]: service_provider:
2023-03-19 19:39:36.249 T:18072 INFO <general>: AddOnLog: inputstream.ffmpegdirect: ffmpeg[EA45BCCB]: Stream #0:0: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 100 tbr, 90k tbn, 50 tbc
2023-03-19 19:39:36.249 T:18072 INFO <general>: AddOnLog: inputstream.ffmpegdirect: ffmpeg[EA45BCCB]: Stream #0:1: Audio: aac (LC), 48000 Hz, stereo, fltp, 131 kb/s
2023-03-19 19:39:36.249 T:18072 DEBUG <general>: AddOnLog: inputstream.ffmpegdirect: GetCapabilities()
this line:
2023-03-19 19:39:36.248 T:18072 INFO <general>: AddOnLog: inputstream.ffmpegdirect: ffmpeg[EA45BCCB]: Duration: 00:32:00.00, start: 26328.772378, bitrate: N/A
the start is 26328
then i drag the progress to 00:17
then kodi send a request with:
Range: npt=26345.772-\r\n
26345 - 26328 = 17
then, i try again, drag the progress to 00:50
Range: npt=26378.772-\r\n
26378 - 26328 = 50
and the extra 0.772 is in the start 26328.772378
so i guess, when i drag a progress bar, someone add the progress value and a number called start then send the sum.
then i restart kodi
i found the start is still 26328.772378.
then i try another stream, the start is 17161.329422 now.
ok, i check the source code the found the parameter is output here
the start is part of the protocol,this is a wrong way, i need to find out who add the start and the progress value, and i know the start is FFmpegStream::m_pFormatContext->start_time
got it:
https://github.com/xbmc/inputstream.ffmpegdirect/blob/278312774bb9d7f8936c7463a1d363e9b88a3221/src/stream/FFmpegStream.cpp#LL1483
but why?
i need kodi send the real progress value without add the ic->start_time
what should i do?
it seems that we need a new #KODIPROP
like #KODIPROP:inputstream.ffmpegdirect.is_ignore_start_time_on_seek=true
If you change the code and build the addon does it work for your use case?
im working on it.
im not a c++ developer, it was difficult for me to build the addon.
i just create a VM, is there documentation for cross-compiling windows plugins on Ubuntu?
If you create a PR, Jenkins will build it for you. It will build for Windows, Android and Mac.
Just click the Jenkins link and then Artefacts to find them.
If you create a PR, Jenkins will build it for you. It will build for Windows, Android and Mac.
Just click the Jenkins link and then Artefacts to find them.
thx
it works.
but the process bar time is wrong.
if i start play , and when the play time is 1:00, then i seek to 2:00, it will play the stream at 2:00 but the process bar shows 1:00.
i found this in log file
AddOnLog: inputstream.ffmpegdirect: ffmpegdirect::FFmpegStream::SeekTime - unknown position after seek
i think it was because of here
ok, i found the dts is -9223372036854775808 in log , it is AV_NOPTS_VALUE(-9223372036854775808(0x8000000000000000)
i think this value should be provid by librtmp
I don't know what to do with this situation yet
the wireshark shows if i send Range: npt=1174.218-\r\n
, the server reply Range: npt=1174.000000-\r\n
So I think there must be a scheme that can set the dts or pts
oh i see.
2023-03-27 13:13:12.312 T:18952 debug <general>: CInputManager::ProcessMouse: trying mouse action leftclick
2023-03-27 13:13:12.315 T:27216 debug <general>: CVideoPlayer::SetCaching - caching state 2
2023-03-27 13:13:12.315 T:27216 debug <general>: CDVDClock::SetSpeedAdjust - adjusted:0.000000
2023-03-27 13:13:12.315 T:26600 debug <general>: CDVDAudio::Pause - pausing audio stream
2023-03-27 13:13:12.315 T:27216 debug <general>: demuxer seek to: 889453.000000
2023-03-27 13:13:12.315 T:27216 debug <general>: AddOnLog: inputstream.ffmpegdirect: ffmpegdirect::FFmpegStream::SeekTime - seek_pts = 889453000 start_time = 14935634422
2023-03-27 13:13:12.315 T:27216 debug <general>: AddOnLog: inputstream.ffmpegdirect: ffmpegdirect::FFmpegStream::SeekTime - before seek pts = -9223372036854775808 dts = -9223372036854775808
2023-03-27 13:13:12.416 T:27216 debug <general>: AddOnLog: inputstream.ffmpegdirect: ffmpegdirect::FFmpegStream::SeekTime - av_seek_frame return 0
2023-03-27 13:13:12.416 T:27216 debug <general>: AddOnLog: inputstream.ffmpegdirect: ffmpegdirect::FFmpegStream::UpdateCurrentPTS - default stream is not null dts = -9223372036854775808
2023-03-27 13:13:12.416 T:27216 debug <general>: AddOnLog: inputstream.ffmpegdirect: ffmpegdirect::FFmpegStream::SeekTime - after seek pts = -9223372036854775808 dts = -9223372036854775808
2023-03-27 13:13:12.416 T:27216 debug <general>: AddOnLog: inputstream.ffmpegdirect: ffmpegdirect::FFmpegStream::SeekTime - unknown position after seek
2023-03-27 13:13:12.416 T:27216 debug <general>: demuxer seek to: 889453.000000, success
2023-03-27 13:13:12.416 T:27216 debug <general>: CVideoPlayer::FlushBuffers - flushing buffers
2023-03-27 13:13:12.431 T:26600 debug <general>: CDVDAudio::Flush - flush audio stream
2023-03-27 13:13:12.431 T:26600 debug <general>: CDVDAudio::Pause - pausing audio stream
2023-03-27 13:13:12.448 T:16232 warning <general>: CVideoPlayerVideo::OutputPicture - timeout waiting for buffer
2023-03-27 13:13:12.449 T:16232 debug <general>: CVideoPlayerVideo - CDVDMsg::GENERAL_SYNCHRONIZE
2023-03-27 13:13:12.449 T:26600 debug <general>: CVideoPlayerAudio - CDVDMsg::GENERAL_SYNCHRONIZE
2023-03-27 13:13:12.449 T:27216 debug <general>: CVideoPlayer - CDVDMsg::GENERAL_SYNCHRONIZE
2023-03-27 13:13:12.449 T:27216 debug <general>: CVideoPlayer::CheckPlayerInit - too far to decode before finishing seek
2023-03-27 13:13:12.482 T:27216 debug <general>: AddOnLog: inputstream.ffmpegdirect: ffmpeg[C0893937]: [rtsp] Packet corrupt (stream = 0, dts = 1344599700).
2023-03-27 13:13:12.483 T:16232 debug <general>: CVideoPlayerVideo - Stillframe left, switching to normal playback
2023-03-27 13:13:12.483 T:16232 debug <general>: CVideoPlayerVideo::CalcDropRequirement - hurry: 0
2023-03-27 13:13:12.483 T:16232 debug <general>: CDVDVideoCodecFFmpeg - Updated codec: ff-h264
2023-03-27 13:13:12.483 T:16232 debug <general>: DXVA: open decoder.
2023-03-27 13:13:12.483 T:16232 debug <general>: DXVA: trying 'H.264 variable-length decoder, no film grain technology'.
2023-03-27 13:13:12.483 T:16232 debug <general>: DXVA: config 0: bitstream type 1.
2023-03-27 13:13:12.483 T:16232 debug <general>: DXVA: config 1: bitstream type 2.
2023-03-27 13:13:12.483 T:16232 debug <general>: DXVA: config 2: bitstream type 2, encrypted.
2023-03-27 13:13:12.483 T:16232 debug <general>: DXVA: selected output format: 103.
2023-03-27 13:13:12.483 T:16232 debug <general>: DXVA: source requires 3 references.
2023-03-27 13:13:12.483 T:16232 info <general>: DXVA::CDecoder::Open: Total video memory available is 11835 MB (dedicated = 3977 MB, shared = 7858 MB)
2023-03-27 13:13:12.483 T:16232 debug <general>: DXVA: allocating 11 surfaces with format 103.
2023-03-27 13:13:12.483 T:16232 debug <general>: CDVDVideoCodecFFmpeg - Updated codec: ff-h264-d3d11va
2023-03-27 13:13:12.485 T:16232 error <general>: ffmpeg[0x14988705500]: [h264] hardware accelerator failed to decode picture
2023-03-27 13:13:12.491 T:27216 debug <general>: CVideoPlayer::CheckContinuity - resync forward :1, prev:3626666.888889, curr:889344000.222223, diff:884981755.555556
2023-03-27 13:13:12.518 T:27216 debug <general>: CVideoPlayer::CheckContinuity - resync forward :1, prev:3626666.888889, curr:889365333.555555, diff:885003088.888888
2023-03-27 13:13:12.558 T:27216 debug <general>: CVideoPlayer::CheckContinuity - resync forward :1, prev:3626666.888889, curr:889386666.888890, diff:885024422.222222
2023-03-27 13:13:12.560 T:27216 debug <general>: CVideoPlayer::CheckContinuity - resync forward :1, prev:3626666.888889, curr:889408000.222224, diff:885045755.555556
2023-03-27 13:13:12.579 T:27216 debug <general>: CVideoPlayer::CheckContinuity - resync forward :1, prev:3626666.888889, curr:889429333.555556, diff:885067088.888888
2023-03-27 13:13:12.599 T:27216 debug <general>: CVideoPlayer::CheckContinuity - resync forward :1, prev:3626666.888889, curr:889450666.888890, diff:885088422.222222
2023-03-27 13:13:12.616 T:16232 debug <general>: CVideoPlayerVideo::CalcDropRequirement - hurry: 0
2023-03-27 13:13:12.616 T:16232 error <general>: ffmpeg[0x14988705500]: [h264] hardware accelerator failed to decode picture
2023-03-27 13:13:12.621 T:27216 debug <general>: CVideoPlayer::CheckContinuity - resync forward :1, prev:3626666.888889, curr:889472000.222224, diff:885069755.555557
2023-03-27 13:13:12.641 T:27216 debug <general>: CVideoPlayer::CheckContinuity - resync forward :1, prev:3626666.888889, curr:889493333.555556, diff:885091088.888889
2023-03-27 13:13:12.661 T:27216 debug <general>: CVideoPlayer::CheckContinuity - resync forward :1, prev:3626666.888889, curr:889514666.888890, diff:885112422.222223
2023-03-27 13:13:12.684 T:27216 debug <general>: CVideoPlayer::CheckContinuity - resync forward :1, prev:3626666.888889, curr:889536000.222222, diff:885133755.555555
2023-03-27 13:13:12.705 T:27216 debug <general>: CVideoPlayer::CheckContinuity - resync forward :1, prev:3626666.888889, curr:889557333.555556, diff:885155088.888890
2023-03-27 13:13:12.706 T:27216 debug <general>: CVideoPlayer::CheckContinuity - resync forward :2, prev:4362244.666667, curr:890122244.666667, diff:885720000.000000
2023-03-27 13:13:12.706 T:27216 debug <general>: CVideoPlayer::CheckContinuity - update correction: 885720000.000000
2023-03-27 13:13:12.706 T:16232 debug <general>: CVideoPlayerVideo::CalcDropRequirement - hurry: 0
2023-03-27 13:13:12.730 T:18952 info <general>: Skipped 1 duplicate messages..
2023-03-27 13:13:12.730 T:18952 debug <general>: DXVA::CDecoder::~CDecoder: destructing decoder, 0x149837a1d50.
2023-03-27 13:13:12.730 T:18952 info <general>: DXVA::CDecoder::Close: closing decoder.
2023-03-27 13:13:12.730 T:18952 debug <general>: DXVA::CVideoBufferPool::~CVideoBufferPool: destructing buffer pool.
2023-03-27 13:13:12.741 T:27216 debug <general>: CVideoPlayer::HandleMessages - player started 2
2023-03-27 13:13:12.809 T:27216 debug <general>: CVideoPlayer::HandleMessages - player started 1
2023-03-27 13:13:12.809 T:27216 debug <general>: CVideoPlayer::SetCaching - caching state 3
2023-03-27 13:13:12.809 T:26500 debug <general>: CApplicationPlayerCallback::OnAVChange: CApplication::OnAVChange
2023-03-27 13:13:12.809 T:27216 debug <general>: CDVDClock::SetSpeedAdjust - adjusted:0.000000
2023-03-27 13:13:12.809 T:27216 debug <general>: CVideoPlayer::SetCaching - caching state 0
2023-03-27 13:13:12.809 T:27216 debug <general>: CDVDClock::SetSpeedAdjust - adjusted:0.000000
2023-03-27 13:13:12.809 T:27216 debug <general>: VideoPlayer::Sync - Audio - pts: 3901333.000000, cache: 473493.829712, totalcache: 780000.030994
2023-03-27 13:13:12.809 T:27216 debug <general>: VideoPlayer::Sync - Video - pts: 4562244.000000, cache: 50000.000000, totalcache: 100000.000000
2023-03-27 13:13:12.809 T:26600 debug <general>: CVideoPlayerAudio - CDVDMsg::GENERAL_RESYNC(3427839.170288), level: 0, cache: 471041.429712
2023-03-27 13:13:12.809 T:16232 debug <general>: CVideoPlayerVideo - CDVDMsg::GENERAL_RESYNC(3427839.170288)
2023-03-27 13:13:12.809 T:16232 debug <general>: CVideoPlayerVideo::CalcDropRequirement - hurry: 0
2023-03-27 13:13:12.809 T:29492 debug <general>: ActiveAE - start sync of audio stream
2023-03-27 13:13:12.809 T:26600 debug <general>: CDVDAudio::Resume - resume audio stream
2023-03-27 13:13:12.811 T:16232 debug <general>: CVideoPlayerVideo::CalcDropRequirement - hurry: 1
2023-03-27 13:13:12.910 T:29492 debug <general>: ActiveAE::SyncStream - average error of 38.265749, start adjusting
2023-03-27 13:13:12.911 T:29492 debug <general>: ActiveAE::SyncStream - average error 23.265749 below threshold of 30.000000
2023-03-27 13:13:13.413 T:16232 warning <general>: CVideoPlayerVideo::OutputPicture - timeout waiting for buffer
i seek 889453
kodi send Range: npt=889.453-\r\n
server reply Range: npt=889.000000-\r\n
the pts and dts are both AV_NOPTS_VALUE
Is the error in librtmp or in ffmpegdirect? What exactly is the change you had to make to get it to work?
have you checked to see if an updated version of librtmp is available?
Is the error in librtmp or in ffmpegdirect?
have you checked to see if an updated version of librtmp is available?
i think the error is because of librtmp.
i find this https://github.com/xbmc/inputstream.rtmp/blob/Omega/depends/common/librtmp/librtmp.txt in inputstream.rtmp
and the source code is here http://git.ffmpeg.org/gitweb/rtmpdump.git/commit/fa8646daeb19dfd12c181f7d19de708d623704c0
there is three new commits.
ok, i konw it, i will build inputstream.rtmp with the new source code of librtmp
it works.
so here's what to do next?
You need to add the hash for librtmp tarball (all 3 directories in depends) and also update inputstream.rtmp/changelog.txt
and inputstream.rtmp/addon.xml.in
The new version number should be 21.0.1.
Then I can merge, tag and release the PR.
im working on it.
Please also squash the url and the hash of the new librtmp commits.
Please also squash the url and the hash of the new librtmp commits.
sorry, in my case, there is two points to fix.
the first one is here:
in my case, the
seek_pts
shouldnt add the m_pFormatContext->start_time
, i think the better way is set a new flag like #KODIPROP:inputstream.ffmpegdirect.is_ignore_start_time_on_seek=true
the second one is update the latest code of librtmp.
i will be back tomorrow, im going to bed now.
Which addon are you using to play the stream?
You should play with either inputstream.ffmpegdirect or inputstream.rtmp, not both.
it's inputstream.ffmpegdirect
Ok, if ffmpegdirect then changing inputstream.rtmpw will make no difference.
have you tried using inputstream.rtmp on its own?
no, im using IPTV Simple Client
, it depends on both inputstream.ffmpegdirect
and inputstream.rtmp
Yes, but only one of them will be used to play your rtsp streams.
Do you have an example the M3U entry you use to play a stream.
You can force the one use by putting a KODIPROP before each M3U entry.
for ffmpegdirect:
#KODIPROP:inputstream=inputstream.ffmpegdirect
for rtmp:
#KODIPROP:inputstream=inputstream.rtmp
for kodi’s internal ffmpeg:
#KODIPROP:inputstream=inputstream.ffmpeg
#EXTINF:0 tvg-id="241@iptv" tvg-name="CCTV1 HD" tvg-chno="1" tvg-logo="" group-title="央视" catchup="default" catchup-source="rtsp://myrtspstream&playseek={utc:YmdHMS}-${end:YmdHMS}", CCTV1 HD
http://192.168.16.1:4022/rtp/239.37.0.8:5540
the live stream is a broadcast stream
and the playback stream is a rtsp stream
i will try #KODIPROP:inputstream=inputstream.ffmpegdirect
later.
Please try all 3x ffmpegdirect, rtmp and ffmpegz internal inputstreams with each type of URL and see what happens.
Because RTMP itself has the ability to playback within a video it could be the catchup functionality in iptvsimple is interfering. The easiest to test that is to not use ffmpegdirect at all.
in my case
#KODIPROP:inputstream=inputstream.rtmp
doesn't work. it can't play any stream.
#KODIPROP:inputstream=inputstream.ffmpeg
behaved the same as the problem I had before
#KODIPROP:inputstream=inputstream.ffmpegdirect
works well.Didn't have any problems
So this problem arises because I did not write my m3u file correctly, thanks for your enthusiastic help, I will continue to observe the status after modifying the m3u file, once I find that the problem is completely solved, I will close the issue and PRs