kaltura / nginx-vod-module

NGINX-based MP4 Repackager
GNU Affero General Public License v3.0
1.99k stars 439 forks source link

How to handle audio playlists #1530

Closed comiconomenclaturist closed 3 months ago

comiconomenclaturist commented 3 months ago

I am looking at using this module mainly for audio playlists but also for some video files. I have generated a playlist of audio files from the API which looks like this:

{ "durations": [ 1707937, 1380330, 761049, 778814 ], "discontinuity": false, "sequences": [ { "clips": [ { "type": "source", "path": "/path/to/mp4/01.mp4" }, { "type": "source", "path": "/path/to/mp4/02.mp4" }, { "type": "source", "path": "/path/to/mp4/03.mp4" }, { "type": "source", "path": "/path/to/mp4/04.mp4" } ] } ] }

I can get the files to play in VLC media player but skipping ahead sometimes works, but sometimes doesn't. Sometimes the player just stops. Is the right way to set up playlists? Maybe it would be better to have a separate master.m3u8 file for each file, then I could just skip tracks by loading a new m3u8 file? But presumably skipping within a track would still be problematic.

I have tried using clipFrom/{timestamp}/ in the URL which seems to work for indexing the start of the tracks, but the skipping through the file seems to be a problem.

erankor commented 3 months ago

One possible cause is that you are setting discontinuity to false - if the audio tracks do not have exactly the same parameters, this can cause playback errors.

comiconomenclaturist commented 3 months ago

Yes I set discontinuity to false because the playlist would cut off the end of the track, or beginning of the next track. Having read the documentation that said the files all need to have the same parameters, I was fairly certain they were but I just checked using ffprobe and it looks like despite setting the bitrate to 160k, the bitrates reported by ffprobe are slightly different. Perhaps I need to enforce CBR somehow in the encoder..

find . -type f -exec ffprobe -hide_banner -loglevel quiet -print_format json -show_entries format=nb_streams,nb_programs,nb_stream_groups,format_name,format_long_name,start_time,duration,size,bit_rate,probe_score {} \;
{
    "format": {
        "nb_streams": 2,
        "nb_programs": 0,
        "nb_stream_groups": 0,
        "format_name": "mov,mp4,m4a,3gp,3g2,mj2",
        "format_long_name": "QuickTime / MOV",
        "start_time": "0.000000",
        "duration": "761.049002",
        "size": "17721874",
        "bit_rate": "186288",
        "probe_score": 100
    }
}
{
    "format": {
        "nb_streams": 2,
        "nb_programs": 0,
        "nb_stream_groups": 0,
        "format_name": "mov,mp4,m4a,3gp,3g2,mj2",
        "format_long_name": "QuickTime / MOV",
        "start_time": "0.000000",
        "duration": "1707.938005",
        "size": "36934791",
        "bit_rate": "173002",
        "probe_score": 100
    }
}
{
    "format": {
        "nb_streams": 2,
        "nb_programs": 0,
        "nb_stream_groups": 0,
        "format_name": "mov,mp4,m4a,3gp,3g2,mj2",
        "format_long_name": "QuickTime / MOV",
        "start_time": "0.000000",
        "duration": "1380.330000",
        "size": "30328466",
        "bit_rate": "175775",
        "probe_score": 100
    }
}
{
    "format": {
        "nb_streams": 2,
        "nb_programs": 0,
        "nb_stream_groups": 0,
        "format_name": "mov,mp4,m4a,3gp,3g2,mj2",
        "format_long_name": "QuickTime / MOV",
        "start_time": "0.000000",
        "duration": "778.813991",
        "size": "18052211",
        "bit_rate": "185432",
        "probe_score": 100
    }
}
comiconomenclaturist commented 3 months ago

I've removed all the metadata and images from the transcoded mp4's now and the bitrates match a bit more closely:

find . -type f -exec ffprobe -hide_banner -loglevel quiet -print_format json -show_entries format=format_name,format_long_name,duration,size,bit_rate {} \;
{
    "format": {
        "format_name": "mov,mp4,m4a,3gp,3g2,mj2",
        "format_long_name": "QuickTime / MOV",
        "duration": "761.049002",
        "size": "15698724",
        "bit_rate": "165021"
    }
}
{
    "format": {
        "format_name": "mov,mp4,m4a,3gp,3g2,mj2",
        "format_long_name": "QuickTime / MOV",
        "duration": "1707.938005",
        "size": "35367821",
        "bit_rate": "165663"
    }
}
{
    "format": {
        "format_name": "mov,mp4,m4a,3gp,3g2,mj2",
        "format_long_name": "QuickTime / MOV",
        "duration": "1380.330000",
        "size": "28519058",
        "bit_rate": "165288"
    }
}
{
    "format": {
        "format_name": "mov,mp4,m4a,3gp,3g2,mj2",
        "format_long_name": "QuickTime / MOV",
        "duration": "778.813991",
        "size": "15836034",
        "bit_rate": "162668"
    }
}

Not exactly the same, but closer. VLC seems to be playing ok, but videojs is still having issues.

After a bit of searching, it appears that Firefox limits the number of simultaneous requests to the same server to 6, and it appears that videojs is failing to load the 6th request.

Screenshot 2024-06-25 at 14 12 21

I tried changing the vod_segment_duration to 2000 and it seems a little bit better but still happens when skipping through the playlist quickly. Is there another setting in the module that can help with this? I tried searching for videojs issues but haven't turned up anything that might limit, or slow down the number of requests being made.

EDIT: I just tried changing the Firefox limit to 64 as described here and it's still happening so I don't think this is the issue.

comiconomenclaturist commented 3 months ago

This seems to have be caused by some bad javascript which loaded the playlist again under certain conditions. I think I will go ahead with the playlists using clipFrom to index the individual tracks as that looks like it should work for my purposes