Skip to content
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

Improved generated test stream investigation #179

Closed
4 tasks done
defagos opened this issue Jan 6, 2023 · 5 comments
Closed
4 tasks done

Improved generated test stream investigation #179

defagos opened this issue Jan 6, 2023 · 5 comments
Assignees
Labels
tooling Issues related to the tools we use

Comments

@defagos
Copy link
Member

defagos commented Jan 6, 2023

As a developer I want to have reliable local test streams with minimal footprint (i.e. files stored in the repo), covering future implementation needs:

  • Alternative audio tracks.
  • Alternative subtitles.
  • Forced subtitles and AD tracks.
  • Bonus: Sports streams (DVR turning into on-demand).

Acceptance criteria

  • The described use cases have matching local test streams.
  • Test stream generation without local files is investigated and implemented if possible.

Hints

From @amtins: See https://www.bogotobogo.com/FFMpeg/ffmpeg_video_test_patterns_src.php

Proposal for a time-displaying video:

ffplay -f lavfi -i testsrc=duration=10.1:size=1280x720:rate=15 -vf drawtext="fontfile=monofonto.ttf: fontsize=96: box=1: [email protected]: boxborderw=5: fontcolor=white: x=(w-text_w)/2: y=((h-text_h)/2)+((h-text_h)/4): text='timestamp: %{pts \: hms}'"

Tasks

  • Investigate test stream generation without local files (see hints above), implement if appropriate and cleanup old files.
  • Generate local test streams with alternative audio tracks.
  • Generate local test streams with alternative subtitles.
  • Bonus: If possible add example of a DVR stream which ends and turns into an on-demand stream.
@defagos defagos added the enhancement New feature or request label Jan 6, 2023
@defagos defagos added tooling Issues related to the tools we use and removed enhancement New feature or request labels May 31, 2023
@defagos
Copy link
Member Author

defagos commented Jun 28, 2023

We could also use a Docker image based on https://github.com/SRGSSR/docker-nginx-vod-module, as discussed with @bgaudaen.

One limitation in comparison to what we have is that the chunk size would be globally defined, whereas we are currently able to tweak it per sample stream.

@defagos
Copy link
Member Author

defagos commented Jun 28, 2023

Tools we could likely use as well:

Below is a quick feedback. I also opened a (currently private) repository for investigation. This repository provides generation scripts. Generated content can then be served locally with

python3 -m http.server 8765 <directory>

Overall recommendation: Shaka Packager, as it supports most features we need to test.

gpac

Most definitely too obscure to use IMHO. Probably too powerful for our needs.

Bento4

Quite easy to use but lacks some features like support for FORCED subtitles or characteristics for AD. Could probably be added through a PR on mp4_dash.py, though, but requires to do the same work for DASH packaging as well.

Shaka packager

Quite easy to use but lacks support for FORCED subtitles. Supports characteristics with hls_characteristics, though, thus marking audio tracks for AD is possible. We could probably make a PR to add support for an hls_forced flag.

The language can be set with the lang descriptor. For a complete list of available descriptors refer to the source code.

@defagos defagos self-assigned this Jun 28, 2023
@waliid
Copy link
Member

waliid commented Jun 30, 2023

How to add subtitles to a stream

Here is an example of how to add English and French subtitles to a stream.

Create subtitles files

SRT - SubRip subtitle with embedded timing

English

1
00:00:0,000 --> 00:00:1,000
Subtitle 1

2
00:00:1,000 --> 00:00:2,000 
Subtitle 2

3
00:00:2,000 --> 00:00:3,000
Subtitle 3

3
00:00:3,000 --> 00:00:4,000
Subtitle 4

French

1
00:00:0,000 --> 00:00:1,000
Sous-titre 1

2
00:00:1,000 --> 00:00:2,000 
Sous-titre 2

3
00:00:2,000 --> 00:00:3,000
Sous-titre 3

3
00:00:3,000 --> 00:00:4,000
Sous-titre 4

To convert to another format (vtt for example) we can use ffmpeg.
ffmpeg -i subtitles_en.srt Medias/subtitles_en.vtt

Merge subtitles to the stream

Generic context

ffmpeg -i <#video_path.mov#> -i <#path/subtitles_en.srt#> -i <#path/subtitles_fr.srt#> \
-map 0 -map 1 -map 2 \
-c:v copy -c:a copy -c:s mov_text \
-metadata:s:s:0 language=eng -metadata:s:s:1 language=fre \
<#output_path#>.mp4

Pillarbox context

ffmpeg -i Medias/nyan_cat.mov -i Medias/subtitles_en.srt -i Medias/subtitles_fr.srt \
-map 0:v:0 -map 0:a:0 -map 0:a:0 -map 1:s:0 -map 2:s:0 \
-c:v copy -c:a copy -c:s webvtt \
-metadata:s:s:0 language=eng -metadata:s:s:1 language=fre \
-metadata:s:a:0 language=eng -metadata:s:a:1 language=fre \
Medias/nyan_cat_subtitled.mkv

Deliver the stream via HLS

Pillarbox context

ffmpeg -stream_loop -1 \
-i "$MEDIAS_DIR/nyan_cat_subtitled.mkv" \
-c:s webvtt \
-map 0:v -map 0:a:0 -map 0:s:0 \
-f hls \
-var_stream_map "v:0,a:0,s:0,sgroup:subtitle,language:eng,name:english" \
-master_pl_name master.m3u8 \
-t 120 -hls_time 10 -hls_init_time 4 -hls_list_size 10 \
-master_pl_publish_rate 10 \
-hls_flags delete_segments+discont_start+split_by_time \
-hls_segment_filename "$ON_DEMAND_SUBTITLED_DIR/%v/seg%03d.ts" \
"$ON_DEMAND_SUBTITLED_DIR/%v/video.m3u8"

This approach works only for one subtitle track.

@defagos defagos changed the title Improve generated test streams Improved generated test stream investigation Jul 3, 2023
@defagos
Copy link
Member Author

defagos commented Jul 3, 2023

DVR to on-demand transition is probably not so useful for a unit testing setup since such a scenario requires the stream to be started, played for a while as a DVR stream before the stream changes to an on-demand one.

@defagos defagos closed this as completed Jul 3, 2023
@defagos
Copy link
Member Author

defagos commented Jul 27, 2023

Work is being done to modernize how Shaka Packager is built using CMake. Currently migration has not reached a sufficient state so that we can efficiently work on adding forced subtitles support, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tooling Issues related to the tools we use
Projects
Archived in project
Development

No branches or pull requests

2 participants