kingslay / KSPlayer

A video player for iOS、macOS、tvOS、visionOS , based on AVPlayer and FFmpeg, support the horizontal, vertical screen. support adjust volume, brightness and seek by slide, SwiftUI, support subtitles.
https://apps.apple.com/app/tracyplayer/id6450770064
GNU General Public License v3.0
952 stars 193 forks source link

Adding SRT protocol on ffmpeg build #226

Closed HeidariMilad closed 2 years ago

HeidariMilad commented 2 years ago

Hi Firstly thank you for such a great player you have provided. I have a question. I want to add the SRT protocol at BuildXCFramework, but I can not run the builder, would you please kindly provide the information about the running your builder step by step? I will appreciate for your help

kingslay commented 2 years ago

swift run BuildFFmpeg

HeidariMilad commented 2 years ago

Thank you for response, I tried to build But unfortunately I have some errors.could you please help to resolve these issues as well? MacOS 12.3 M1 Also tried arch -x86_64 swift run BuildFFmpeg but result was same.

Errors:

error: unable to read the file at '/Users/milad/Downloads/KSPlayer-develop/Sources/BuildFFmpeg/Script/FFmpeg/ios/Libavfilter.framework/Libavfilter'

clang: error: invalid version number in '-target x86_64-apple-ios13.0-macabi' make[1]: *** [apps/lib/libapps-lib-app_libctx.o] Error 1 make: *** [build_sw] Error 2 clang: error: invalid version number in '-target x86_64-apple-ios13.0-macabi' make[1]: *** [apps/lib/libapps-lib-app_libctx.o] Error 1 make: *** [build_sw] Error 2

curl: (6) Could not resolve host: raw.githubusercontent.com yasm not found zsh:1: command not found: brew pkg-config not found zsh:1: command not found: brew

error: unable to read the file at '/Users/milad/Downloads/KSPlayer-develop/Sources/BuildFFmpeg/Script/SSL/maccatalyst/Libcrypto.framework/Libcrypto'

fatal error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: can't open input file: /Users/milad/Downloads/KSPlayer-develop/Sources/BuildFFmpeg/Script/SSL/maccatalyst/thin/arm64/lib/Libcrypto.a (No such file or directory)

error: unable to read the file at '/Users/milad/Downloads/KSPlayer-develop/Sources/BuildFFmpeg/Script/SSL/maccatalyst/Libcrypto.framework/Libcrypto'

fatal error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: can't open input file: /Users/milad/Downloads/KSPlayer-develop/Sources/BuildFFmpeg/Script/SSL/maccatalyst/thin/arm64/lib/Libssl.a (No such file or directory)

and some more like these.

Screen Shot
kingslay commented 2 years ago

you can update the code. i had fixed it

HeidariMilad commented 2 years ago

unfortunately getting new error this time. I will attach full log for you . log.docx

kingslay commented 2 years ago

you need run /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

HeidariMilad commented 2 years ago

brew was installed on my machine but still got "brew not found" error, and then by uninstalling it and installing using x86 architecture brew problem solved. but still doesn't build successfully, i will attach full log.

error: unable to read the file at '/Users/milad/Downloads/KSPlayer/Sources/BuildFFmpeg/Script/FFmpeg/ios/Libavfilter.framework/Libavfilter'

full log: log.docx

kingslay commented 2 years ago

you need run

brew install yasm
brew install pkg-config
brew install sdl2
HeidariMilad commented 2 years ago

Thank you, I appreciate your time and effort. finally your default config built successfully. now I added --enable-libsrt to BuildXCFramework.swift but finishes with error: ERROR: srt >= 1.3.0 not found using pkg-config

log.docx

kingslay commented 2 years ago

you need to build srt. you can see the openssl

https://github.com/Haivision/srt

HeidariMilad commented 2 years ago

Ok, now I built it manually. And everything is ready in BuildFFmpeg folder. How do i use it? I tried replace xcframeworks. But when i want to play a srt stream i receive error in console, protocol not found, although frameworks successfully built with enabled srt.

what am I doing wrong? Have you ever tested srt protocol yourself?

kingslay commented 2 years ago

you can get me the change of BuildXCFramework.swift. and get me the play url. i will try it

HeidariMilad commented 2 years ago
  1. for changes please apply these patches: patches.zip

  2. run swift run BuildFFmpeg

  3. it will fail with ERROR: srt >= 1.3.0 not found using pkg-config

  4. comment the line enabled libsrt && require_pkg_config libsrt "srt >= 1.3.0" srt/srt.h srt_socket in Scripts/ffmpeg-5.0.1/configure

  5. run swift run BuildFFmpeg


And for SRT stream url I use FFMpeg for local streaming.you can do it like this:

  1. install ffmpeg on your machine.
  2. in terminal run this command: ffmpeg -re -f lavfi -i "smptehdbars=rate=30:size=2048x1152" \ -vf drawtext="text='SRT Test : timecode= 01\:00\:00\:00':rate=30:x=(w-tw)/2:y=(h-lh)/2:fontsize=92:fontcolor=white:box=1:boxcolor=black" \ -f flv -c:v h264 -profile:v baseline -pix_fmt yuv420p -preset ultrafast -tune zerolatency -crf 28 -g 60 -c:a aac -f mpegts "udp://127.0.0.1:1234?pkt_size=1316"
  3. in a new window terminal run this command: srt-live-transmit udp://:1234 srt://:4201 -v now you can receive SRT stream on srt://127.0.0.1:4201
HeidariMilad commented 2 years ago

Have you any good news for me?

kingslay commented 2 years ago

Have you any good news for me?

i had fixed it by 443fe834f91e837e7f84bfe233e5a0a4118277ca @MiladCyrus

HeidariMilad commented 2 years ago

fixed

Did you manage to play SRT stream? can you guid me step by step what you did? because I fail to play SRT stream.

kingslay commented 2 years ago

you need run swift run BuildFFmpeg enable-openssl enable-libsrt

HeidariMilad commented 2 years ago

Thanks for the update. But I'm still unable to play srt stream. here is steps I done:

  1. replaced built xcframeworks in /ksplayer/Sources/BuildFFmpeg/Sources with /ksplayer/Sources
  2. ran a SRT stream as I mentioned in https://github.com/kingslay/KSPlayer/issues/226#issuecomment-1116991935
  3. adde an Item in AppDelegate like this: if let url = URL(string: "srt://192.168.1.102:4201") { let options = KSOptions() objects.append(KSPlayerResource(url: url, options: options, name: "srt video")) }
  4. run the app and played the srt item. but I get this error in console: KSPlayer: KSPlayerLayer.swift:340 finish(player:error:) | Error Domain=KSPlayerErrorDomain Code=2 "avformat can't open input" UserInfo={NSUnderlyingError=0x6000026bdcb0 {Error Domain=FFmpegDomain Code=-1330794744 "Protocol not found" UserInfo={NSLocalizedDescription=Protocol not found}}, NSLocalizedDescription=avformat can't open input}

this means despite building successfully and adding srt still KSPlayer doesn't recognise it and unable to play.

kingslay commented 2 years ago

Thanks for the update. But I'm still unable to play srt stream. here is steps I done:

  1. replaced built xcframeworks in /ksplayer/Sources/BuildFFmpeg/Sources with /ksplayer/Sources
  2. ran a SRT stream as I mentioned in Adding SRT protocol on ffmpeg build #226 (comment)
  3. adde an Item in AppDelegate like this: if let url = URL(string: "srt://192.168.1.102:4201") { let options = KSOptions() objects.append(KSPlayerResource(url: url, options: options, name: "srt video")) }
  4. run the app and played the srt item. but I get this error in console: KSPlayer: KSPlayerLayer.swift:340 finish(player:error:) | Error Domain=KSPlayerErrorDomain Code=2 "avformat can't open input" UserInfo={NSUnderlyingError=0x6000026bdcb0 {Error Domain=FFmpegDomain Code=-1330794744 "Protocol not found" UserInfo={NSLocalizedDescription=Protocol not found}}, NSLocalizedDescription=avformat can't open input}

this means despite building successfully and adding srt still KSPlayer doesn't recognise it and unable to play.

can you play srt://127.0.0.1:4201 on vlc?

HeidariMilad commented 2 years ago

Thanks for the update. But I'm still unable to play srt stream. here is steps I done:

  1. replaced built xcframeworks in /ksplayer/Sources/BuildFFmpeg/Sources with /ksplayer/Sources
  2. ran a SRT stream as I mentioned in Adding SRT protocol on ffmpeg build #226 (comment)
  3. adde an Item in AppDelegate like this: if let url = URL(string: "srt://192.168.1.102:4201") { let options = KSOptions() objects.append(KSPlayerResource(url: url, options: options, name: "srt video")) }
  4. run the app and played the srt item. but I get this error in console: KSPlayer: KSPlayerLayer.swift:340 finish(player:error:) | Error Domain=KSPlayerErrorDomain Code=2 "avformat can't open input" UserInfo={NSUnderlyingError=0x6000026bdcb0 {Error Domain=FFmpegDomain Code=-1330794744 "Protocol not found" UserInfo={NSLocalizedDescription=Protocol not found}}, NSLocalizedDescription=avformat can't open input}

this means despite building successfully and adding srt still KSPlayer doesn't recognise it and unable to play.

can you play srt://127.0.0.1:4201 on vlc?

Yes, It plays on vlc desktop. Vlc app on ios doesn't support SRT. if you want a srt player on ios device. You can use Haivision Play Pro.

kingslay commented 2 years ago

@MiladCyrus

  let srtPath = URL.currentDirectory + ["SRT", platform.rawValue, "thin", arch.rawValue]
        if FileManager.default.fileExists(atPath: srtPath.path) {
            cflags += " -I\(srtPath.path)/include"
            ldflags += " -L\(srtPath.path)/lib"
            ffmpegcflags.append("--enable-libsrt")
            ffmpegcflags.append("--enable-protocol=libsrt")
        }

do you had append("--enable-protocol=libsrt") ?

HeidariMilad commented 2 years ago

@MiladCyrus

  let srtPath = URL.currentDirectory + ["SRT", platform.rawValue, "thin", arch.rawValue]
        if FileManager.default.fileExists(atPath: srtPath.path) {
            cflags += " -I\(srtPath.path)/include"
            ldflags += " -L\(srtPath.path)/lib"
            ffmpegcflags.append("--enable-libsrt")
            ffmpegcflags.append("--enable-protocol=libsrt")
        }

do you had append("--enable-protocol=libsrt") ?

Do you mean in swift run command? Or BuildXCframework.swift ? After your update on repo i just ran swift run BuildFFmpeg enable-openssl enable-libsrt

kingslay commented 2 years ago

BuildXCframework.swift

Enabled protocols:
async                   hls                     rtmpts
cache                   http                    rtp
concat                  httpproxy               srtp
concatf                 https                   tcp
crypto                  libsrt                  tee
data                    pipe                    tls
ffrtmphttp              prompeg                 udp
file                    rtmp                    udplite
ftp                     rtmps
gophers                 rtmpt

you can see the ffmpeg build log. search libsrt. Enabled protocols must have libsrt

HeidariMilad commented 2 years ago

OK. there is something wrong here. I have this in BuildXCframework.swift

        if FileManager.default.fileExists(atPath: srtPath.path) {
            cflags += " -I\(srtPath.path)/include"
            ldflags += " -L\(srtPath.path)/lib"
            ffmpegcflags.append("--enable-libsrt")
            ffmpegcflags.append("--enable-protocol=libsrt")
        }

but in logs there is no libsrt in protocols. here is the log of my last run: log.docx

by the way for convenience if you want we can discuss in some other messaging platforms like telegram or ...

kingslay commented 2 years ago

you log not had --enable-libsrt and --enable-protocol=libsrt. so I guess FileManager.default.fileExists(atPath: srtPath.path) is false