shaka-project / shaka-packager

A media packaging and development framework for VOD and Live DASH and HLS applications, supporting Common Encryption for Widevine and other DRM Systems.
https://shaka-project.github.io/shaka-packager/
Other
1.95k stars 504 forks source link

Sound pops & clicks when playing HLS stream by using Safari native playback #1206

Open emmitrin opened 1 year ago

emmitrin commented 1 year ago

System info

Operating System: macOS Ventura 13.2 Shaka Packager Version: packager-osx-x64 version v2.6.1-634af65-release

Issue and steps to reproduce the problem

I have the following input files:

I'm trying to make a HLS stream containing the video and two audio tracks:

Packager Command:

packager \
'in=video.mp4,stream=video,segment_template=720p/$Number$.ts,playlist_name=720p.m3u8,iframe_playlist_name=720p_iframe.m3u8' \
'in=audio0.m4a,stream=audio,segment_template=audio0/$Number$.ts,playlist_name=audio0/main.m3u8,hls_group_id=audio,hls_name=First_actor' \ 
'in=audio1.m4a,stream=audio,segment_template=audio1/$Number$.ts,playlist_name=audio1/main.m3u8,hls_group_id=audio,hls_name=Second_actor' \ 
--hls_master_playlist_output 720p_master.m3u8

The resulting stream is playing fine in hls.js-powered players, but I can constantly hear choppy clicking sound when trying to play the stream via Safari's native HLS playback.

When I switch the segment_template file extension for audio streams to .aac, everything is fine for both Safari and hls.js.

But I'm locked to MPEG-2 container for audio streams because I also need raw SAMPLE-AES encryption which is supported only for MPEG-2 TS in Hls.js.

Is this happening due to ID3 com.apple.streaming.transportStreamTimestamp tag getting lost when the audio is stored in .ts segments separated from the video?

Is there anything related to Shaka packager that may fix this issue?

emmitrin commented 1 year ago
ffprobe for input audio file ```json { "streams": [ { "index": 0, "codec_name": "aac", "codec_long_name": "AAC (Advanced Audio Coding)", "profile": "LC", "codec_type": "audio", "codec_tag_string": "mp4a", "codec_tag": "0x6134706d", "sample_fmt": "fltp", "sample_rate": "48000", "channels": 2, "channel_layout": "stereo", "bits_per_sample": 0, "id": "0x1", "r_frame_rate": "0/0", "avg_frame_rate": "0/0", "time_base": "1/48000", "start_pts": 0, "start_time": "0.000000", "duration_ts": 70435824, "duration": "1467.413000", "bit_rate": "130085", "nb_frames": "68786", "extradata_size": 5, "disposition": { "default": 1, "dub": 0, "original": 0, "comment": 0, "lyrics": 0, "karaoke": 0, "forced": 0, "hearing_impaired": 0, "visual_impaired": 0, "clean_effects": 0, "attached_pic": 0, "timed_thumbnails": 0, "captions": 0, "descriptions": 0, "metadata": 0, "dependent": 0, "still_image": 0 }, "tags": { "language": "eng", "handler_name": "SoundHandler", "vendor_id": "[0][0][0][0]" } } ], "format": { "filename": "audio0.m4a", "nb_streams": 1, "nb_programs": 0, "format_name": "mov,mp4,m4a,3gp,3g2,mj2", "format_long_name": "QuickTime / MOV", "start_time": "0.000000", "duration": "1467.413000", "size": "24677419", "bit_rate": "134535", "probe_score": 100, "tags": { "major_brand": "M4A ", "minor_version": "512", "compatible_brands": "M4A isomiso2", "title": "testvideo", "encoder": "Lavf59.27.100" } } } ```