ffmpeginteropx / FFmpegInteropX

FFmpeg decoding library for Windows 10 UWP and WinUI 3 Apps
Apache License 2.0
211 stars 53 forks source link

Populate StreamIndex property for SubtitleStreamInfo #398

Closed softworkz closed 10 months ago

brabebhin commented 10 months ago

I think the question here was how to deal with this property when the source is an external subtitle.

softworkz commented 10 months ago

I think the question here was how to deal with this property when the source is an external subtitle.

No reason not to set it for internal subs. ;-)

brabebhin commented 10 months ago

Yes i know. I actually exposed those properties in some previous pull request, but then we realized we didn't really need them, and that we can identify a stream directly by its corresponding StreamInfo.

But i suppose your use case is something else.

softworkz commented 10 months ago

identify a stream directly by its corresponding StreamInfo

How do you do that without StreamIndex?

image

All other data is not guaranteed to be unique.

brabebhin commented 10 months ago

The StreamInfo objects references themselves are unique and consistent. For example, we use them to set per stream ffmpeg audio effects.

But please explain the scenario, I might be missing something.

softworkz commented 10 months ago

Ah sorry - the missing bit is this:

We do not populate our track selection lists (audio and subtitles) from the tracks that the player (in this case FFmpegMediaSource or PlaybackItem) gives us. The track selection lists are always provided by the server. This is done because there are many cases where the player doesn't get the media in a form where all available streams are included. For example, when the server is transcoding or remuxing, there's just the selected audio track included, so the player sees only a single audio track but the track selection list shows all of them. When the user switches to another audio stream, playback is restarted (while keeping playback position) and the player receives a new stream with the newly selected audio track included (and only that one then). Or for example, since FFmpegIjnteropX doesn't support dvb_teletext subtitles, it doesn't create a subtitles track for those, but we still show that in our selection list. When the user selects it and the player can't hasndle it, we do conversion or transcoding with burn-in at the server. Our tracklists "know" in advance which stream will have which index (as seen by the player), that's why the StreamIndex is perfect for making the relation.

I'm doing the switching on/off at a place where I only have the MediaPlaybackItem with its TimedMetadataTracks collection and not the FFmpegMediaSource, so I need to identify the streams by in some way, which I can do now as follows:

                    foreach (var subtitleStream in this.FfmpegMss.SubtitleStreams)
                    {
                        if (subtitleStream.SubtitleTrack != null)
                        {
                            subtitleStream.SubtitleTrack.Label = subtitleStream.StreamIndex.ToString();
                        }
                    }

Then I just need to look at the label fields of the subtitle tracks to find the right one.

brabebhin commented 10 months ago

I see. Thanks for the scenario. Then it is indeed true that other types of identifying the sub stream are not useful in your case.

softworkz commented 10 months ago

I see. Thanks for the scenario. Then it is indeed true that other types of identifying the sub stream are not useful in your case.

Yes, the preivious implementation from a colleague did it by "counting", i.e. matching the n-th subtitle stream in the playback source with the n-th TimedTextTrack, but this fails of course when FFmpegInteropX doesn't handle a certain subtitle stream or - as far as I've seen - it also doesn't produce a subttitle track when there are no subtitle events. So, counting is not reliable either - while StreamIndex is.

Thanks

brabebhin commented 10 months ago

All good. Merged.