media-kit / media-kit

A cross-platform video player & audio player for Flutter & Dart.
https://github.com/media-kit/media-kit
MIT License
916 stars 132 forks source link

[Feature Request] setAudioFile, setSubFile #91

Closed solsticedhiver closed 1 year ago

solsticedhiver commented 1 year ago

I am looking at the code and stumble upon setAudioTrack, setVideoTrack, setSubtitleTrack.

But this does not work for me. I want to play a video, with a detached audio file and another file for the subtitle.

I have found that I can do that with mpv by using --audio-file and --sub-file. I wasn't able to get it working with --vid and --aid, that SetVideo/AudioTrack are used for.

I tried to use those switches in this package with setProperty but looking at the source, it seems only a limited subset is taken into account, and not those 2.

So either, add them to the list of setProperty taken into account or add dedicated method, like setAudioFile, setSubFile.

Thank you

alexmercerind commented 1 year ago

Just to clarify, I'm not aiming to expose every single API into Player class. Some things & requirements are very very specialized for which setProperty API can directly be used. In either case, I have kept the code architecture in such a way that every single logic (except for video rendering) is in Dart itself. People who are not comfortable with native development & know just Flutter & Dart are also free to play around.

setAudioTrack, setVideoTrack, setSubtitleTrack

These will be part of next update. It will bring many API refinements, bug fixes & stability improvements.

solsticedhiver commented 1 year ago

Well, I misread the code, and it seems that audio-file and sub-file are treated like any other property.

So using .setProperty('audio-file', 'some ref') should work. But is it a property that we can use?

Looking at the documentation of mpv, it does not seem so after all. That would explain why it does not work for me with media_kit, and only on terminal with mpv using something like mpv video_stream --audio-file=audio_stream --sub-file=subtitle

By the way, I am doing this to work-around a bug of mpv/ffmpeg with "sidx not implemteted" error AND, another webvtt issue

alexmercerind commented 1 year ago

@solsticedhiver, use audio-files instead.

https://github.com/alexmercerind/media_kit/blob/eacaf7ce6bafb39fcb90aa8788b10fcd5ed65667/media_kit_test/lib/common/widgets.dart#L264-L269

solsticedhiver commented 1 year ago

Well, the subtitle is a local file, but the audio file is still streamed. and audio-files wants a local file. so it works with mpv and using audio-files-append or audio-file

But it does not work with media_kit, (using .setProperty) I don't know why.

Note: it works for the subtitle with sub-files now

alexmercerind commented 1 year ago

It works for online URIs too. We're testing it in the test application.

alexmercerind commented 1 year ago

Also... It seems you're using package:media_kit in https://github.com/solsticedhiver/flarte.

Why are you not using the link directly. Install yt-dlp or youtube-dl on your system (it seems they already support arte.tv). It will automatically set all the parameters required for the playback etc. Enjoy direct streaming within package:media_kit!

I'm able to play it in the test application.

final playable = Media('https://www.arte.tv/en/videos/112907-012-A/arte-europe-weekly/')

image

alexmercerind commented 1 year ago

Also... audio-files is not working on my GNU/Linux distribution that I'm running elementaryOS 7. No clue.

solsticedhiver commented 1 year ago

Some videos are playing fine with media_kit as is. but some throw an errors when using mpv/ffmpeg, and this gives no sound in media_kit player.

Other video, it's the subtitle.

Yes, I was using yt-dlp for download but it has problem too.

I don't follow you how I can use yt-dlp to play video with media_kit. You mean on the cli directly or uou mean use yt-dlp -F to get the format and pass it to libmpv with ytdlp options of mpv? I couldn't get it to work either. I don't know why.

and by the way, I tested, in media_kit_test, with the 2 streams in question and I got the same problem than with my tests in my app.

For example video is https://arte-cmafhls.akamaized.net/am/cmaf/103000/103500/103538-000-A/230308190304/medias/103538-000-A_v360.mp4 and audio is https://arte-cmafhls.akamaized.net/am/cmaf/103000/103500/103538-000-A/230308190304/medias/103538-000-A_aud_VOEU-ALL_8.mp4

You might be geo-blocked.

I got no sound either in media_kit_test.

Of course, in that case you can still use the original https://arte-cmafhls.akamaized.net/am/cmaf/103000/103500/103538-000-A/230308190304/103538-000-A_VOEU-STE%5BANG%5D_XQ.m3u8 which works here.

flarte is just a 'play' app to learn a bit flutter and be able to download the video more than watching them.

Don't waste your time on helping me too much ;-)

alexmercerind commented 1 year ago

I just have yt-dlp on my path & media_kit automatically uses it. I can stream videos from YouTube too! It doesn't require to extract stream URLs etc.

solsticedhiver commented 1 year ago

Yes. I know yt-dlp. and have it.

alexmercerind commented 1 year ago

What's your libmpv version? I recommend 0.33.x or higher.

solsticedhiver commented 1 year ago

ah ok, the arte.tv link directly? I have to try...

I have mpv 0.35.1 and libmpv.so.2.0.0

alexmercerind commented 1 year ago

Any progress?

solsticedhiver commented 1 year ago

no. for example: https://www.arte.tv/fr/videos/102208-000-A/kolya/ if you are able to play it

mpv choke on it and can't play it because of a sidx error (ffmpeg error, issue #10149). media_kit/media_kit_test fails too obviously

if you try to play the .m3u8 directly, mpv gives no sound (https://arte-cmafhls.akamaized.net/am/cmaf/102000/102200/102208-000-A/230313075838/102208-000-A_VF-STF_XQ.m3u8) so media_kit can't do better

so my last resort is to do like I said previously by using the low level mp4 for video, audio and subtitle this works with mpv with mpv https://arte-cmafhls.akamaized.net/am/cmaf/102000/102200/102208-000-A/230313075838/medias/102208-000-A_v432.mp4 --audio-files-append=https://arte-cmafhls.akamaized.net/am/cmaf/102000/102200/102208-000-A/230313075838/medias/102208-000-A_aud_VF-FRA_3.mp4 (subtilte not shown here you have to dl it and edit it to remove STYLE see #10169 of ffmpeg)

I can't make it work with media_kit, I have no idea why. Tried audio-files-append audio-files audio-file, audio-files-path no luck

by the way, you can close this issue if you want

alexmercerind commented 1 year ago

@solsticedhiver,

I believe libmpv is the best possible & most stable solution that ever can be for media playback & package:media_kit is using it. I'm closing this issue since it's unlikely that this will ever become part of a general API. We may re-evaluate our decision in future based on demands or priorities we get. Most likely FFmpeg or mpv/libmpv offered by your distribution's package manager is outdated. Maybe try grabbing some newer version from some external PPA if you're on Ubuntu/Debian etc.

Thanks!

I'm still able to play it just fine.

alexmercerind commented 1 year ago

Ideally speaking... I'd like to compile a standalone libmpv build for GNU/Linux & bundle it along like Windows, macOS & iOS. That'd require time investment I'm currently unable to. So, focusing on more important issues.

solsticedhiver commented 1 year ago

For the record, I am using archlinux which has most the time, the latest stable software available, currently using mpv 1:0.35.1-4 and ffmpeg 2:6.0-4

Clearly, this is not the issue, here.

And there are some videos that are fine, and others not on that site. I have given example of one broken, with mpv.

alexmercerind commented 1 year ago

And... no matter what it will still work fine for me on Windows.