how to embed subtitle to a video file without burn (html5) - ios

i've a cdn hosting and there are some video files on it. and i've subtitles for videos. as you know, osx or ios doesn't allow subtitles on fullscreen mode. i've found a solution with ffmpeg (burning) but it burns video with hardcode:
https://trac.ffmpeg.org/wiki/HowToBurnSubtitlesIntoVideo
is there any other way to do it without hardcode (maybe a media server)? because i've 5 different subtitles for each video file. and can't do it with hardcode.
any helps would be great..
best regards.

Well, what I'm suggesting is like this.
ffmpeg -i input_video -i input_sub -c:s mov_text -c:v copy -c:a copy output_video
Here mov_text is the codec for subtitles and this will soft embed the subtitle without burning it in to the video. All other streams will be copied as it is. See here for a demo.
Hope this helps!

Related

tool to export YouTube video with its chapters

I want to download YouTube video along with its chapters. Chapters should be embedded as a bookmark in downloaded video. Is there a tool or way to do this?
Using yt-dlp just execute:
yt-dlp --embed-chapters "VIDEO_ID"
Note that the video download is far more slow with the argument --embed-chapters.

How to add subtitles for offline video (using AvPlayer)

I'm trying to add subtitles for a video. Both video file and subtitles files are downloaded on iphone (*in both vtt and srt format)
Example paths:
subtitle: file:///private/var/mobile/Containers/Data/Application/384B1E38-7536-4F52-A9E1-B7D8E5A1490B/Documents/1_665ba05feee690141b7_english.vtt*).
video file: file:///private/var/mobile/Containers/Data/Application/384B1E38-7536-4F52-A9E1-B7D8E5A1490B/Library/com.apple.UserManagedAssets.q1zdd9/1_665ba05f2b5aa225440dc840690141b7_4CD8B29737842BA5.movpkg
I have absolutely no idea how i should create or prepare those files to have a AVMediaSelectionGroup and be able to select a proper AVMediaCharacteristic on
Unfortunately most of tutorials contains only examples for hls streaming, but im not sure if it is valid for offline player.
How should i use AVAssetResourceLoaderDelegate or AVAssetResourceLoader and how should i create a single AVURLAsset with all subtitles?
Could you help me somehow and describe what should i do? I am aware that the question is imprecise, but in fact i do not know where should i start (describing a path - what i should do in steps would be appreciated).
Kind regards.

How to: Playm3u8 files offline in VLC

I'm using an offline terminal to create an .m3u8 file but I would like to play it using VLC. Every example so far has shown examples of using m3u8 online but this isn't an option for me. If you can play it offline using VLC how do you do so?
You have to download the playlist from m3u8 to watch it offline and to do that you have to either use youtube-dl or ffmpeg
i would recommend ffmpeg , and the command for downloading the m3u8 file goes like this :-
ffmpeg -i "here your m3u8 link" -c copy Output.mp4
This will download the highest quality video available in that m3u8 file.
To change quality you can use map command or simply download the m3u8 file and open it with notepad and there you will find links for other resolution.
m3u8 files are just playlists without actual contents, but just URL pointers. Those files are mostly being used these days for HLS.
While you can play the files while offline, you won't see anything unless you are also hosting the referenced Contents.

Encode iOS compatible h264 audio stream with FFMPEG

I am using FFMPEG with Python to encode a low bit rate version of videos that I import. I would like the output to be playable on several devices, including Roku and iOS. This link states that Apple supports H264 High profile, level 4.1 and MP3 audio.
ffmpeg -preset veryslow -y -profile:v high -level 4.0 -movflags +faststart -codec:a libmp3lame -qscale:a 2 -s 1280x720 out.mp4
The resulting videos play fine in an HTML5 browser on a computer. However, on the iPhone the video appears but the audio stream does not play. Is there an issue with the mp3 settings?
From ffprobe:
[STREAM]
index=1
codec_name=mp3
codec_long_name=MP3 (MPEG audio layer 3)
profile=unknown
codec_type=audio
codec_time_base=1/44100
codec_tag_string=mp4a
codec_tag=0x6134706d
sample_fmt=s16p
sample_rate=44100
channels=1
channel_layout=mono
bits_per_sample=0
id=N/A
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/44100
start_pts=-1105
start_time=-0.025057
duration_ts=2321489
duration=52.641474
bit_rate=94949
max_bit_rate=N/A
bits_per_raw_sample=N/A
nb_frames=2016
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=1
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
TAG:language=und
TAG:handler_name=SoundHandler
[/STREAM]
I tried using AAC, but did not get good results with the native FFMPEG encoder
The document you reference is for HTTP Live Streaming, which uses a transport stream format, not an ISO mp4 format. Either way I have found many issues with mp3+video in ios. My recommendation is to use AAC (-acodec fdk-aac) instead of mp3. It is just as universally supported, and will provide you with better audio at lower bitrates. If that is not an option, try to specify all audio settings on the command line (-channles -samplerate, etc)

Streaming Technique from pocketcast in xcode

I've been asked by my client whether it is possible to download a video and stream it once a bit has downloaded, just like pocketcasts does. His reasoning is this will allow him to store his video files on a site such as godaddy and bypass the need to stream the file to the phone which normally requires a dedicated server.
Is this even possible? if so do you know anywhere I can look to find out how pocketcasts does it? At the moment my app just streams an mp4.
Thanks for looking,
Matt
Since you're targetting iOS, HLS (HTTP Live Streaming) is your friend: https://developer.apple.com/streaming/
Please see my answer here for how you can use it: Simultaneously downloading and playing a song that is pieced together from multiple URLs
It's very easy to run a long movie through the mediafilesegmenter tool from Apple (or FFMPEG) which spits out a number of small .ts files (MPEG 2 Transport Stream). Then you create a manifest (a .m3u8 file) which describes how these files fit together (which mediafilesegment will create for you too!). Then you just put the manifest file and the .ts files on a hosting provider (like GoDaddy) and you're all set.
For example, given a file called test.mp4, first turn it into a .ts file with ffmpeg:
ffmpeg -i test.mp4 -acodec copy -vcodec copy -bsf h264_mp4toannexb test.ts
Then turn it into a series of HLS segments with mediafilesegmenter (the same can be done using the ffmpeg segment muxer, but mediafilesegmenter seems to be more robust):
mediafilesegmenter -t 3 test.ts
The result is a bunch of 3 second clips (that's what -t 3 means) and an manifest file called prog_index.m3u8. The contents of that look like:
#EXTM3U
#EXT-X-TARGETDURATION:3
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-PLAYLIST-TYPE:VOD
#EXTINF:2.99520,
fileSequence0.ts
#EXTINF:2.99520,
fileSequence1.ts
#EXTINF:2.99520,
fileSequence2.ts
#EXTINF:2.99520,
fileSequence3.ts
...
#EXTINF:0.37440,
fileSequence75.ts
#EXT-X-ENDLIST
Simply putting all of the .ts files and the .m3u8 file on a web server and pointing your AVPlayer or MPMoviePlayerController in iOS at the URL for the .m3u8 will get you an excellent streaming performance.

Resources