@krambriw nice recordings! also, no key for your daughter?
I just did a quick cmd line with ffmpeg to record an mp4 from my HLS stream. It worked like a charm. In the most basic form, all you would need is ffmpeg -i https://123.45.67.89:1880/mp4frag/1/hls.m3u8 test.mp4
and ffmpeg will automatically figure out the input type and create the output. But of course, you can tweak the input and output to be whatever you like.
I was even able to pass a cookie(that i borrowed from my browser) to the headers of ffmpeg to get past my authentication middleware.
ffmpeg -headers "Cookie: nrca=s%3AeyJhbGciOiJIUzI1iIsInRcCI6IkpXVCJ9.eyJ1Ijoia2V2aW4iLCJyIjoiMTkyLjE2OCxLjcxIiwiaWF0IjoxNjEMDM4ODk0LCJleAiOjE2MTMyNDg0OTR9.GI2U2zhXOw530EyAgROAQH-afEZGXTOdzsb7zw.x1Z1bttYkQSjvMlXyT1bgDeLecWkhpz3ai7Gmx7fQ;" -i https://private.----------.com:1880/mp4frag/1/hls.m3u8 test.mp4
ffmpeg -h demuxer=hls
: -live_start_index <int> .D....... segment index to start live streams at (negative values are from the end) (from INT_MIN to INT_MAX) (default -3)
live_start_index is what you will tweak to determine how far back in the buffered video that ffmpeg will start recording from the hls.m3u8 playlist. In my non scientific test, it seems that setting that to 0
gave me the most "pre trigger" video and using a negative number such as -5
gave me the least "pre trigger" video.
If you want ffmpeg to record a pre-determined length video after you trigger it, you can use -t 30
to make ffmpeg stop after 30 seconds duration.
The following just worked for me to make a 30 second mp4 from my authenticated hls.m3u8:
ffmpeg -headers "Cookie: nrca=s%3AeyJhbGciOiJIUz6IkpXVCJ9.eyJ1IjoiCJyIjoiMTkyLjE2OC4xLjcxIiwiaWF0IjoxNjEyMDM4ODk0Dg0OTR9.GI2jU2zhXAgwROvAQH-afEZGXtTOdzsb7zw.x1Z1kbttYkQSjvMlXyTkhpz3ai7Gmx7fQ;" -f hls -live_start_index 0 -i https://private.-.com:1880/mp4frag/1/hls.m3u8 -c copy -t 30 -f mp4 test3.mp4 -y
edit. It seems like using a big negative number -100 (or whatever number is greater than your total segments) for the live_start_index ensures that ffmpeg will use the oldest media segments in the hls.m3u8 playlist, which will give you the most "pre trigger" video.
I am able to get about 7 seconds of pre-trigger video from my example playlist that seems to contain 10 seconds( 20 pieces x 0.5 second duration) of video buffered:
#EXTM3U
#EXT-X-VERSION:7
#EXT-X-TARGETDURATION:1
#EXT-X-MEDIA-SEQUENCE:377674
#EXT-X-MAP:URI="init-hls.mp4"
#EXTINF:0.520000,
hls377674.m4s
#EXTINF:0.538000,
hls377675.m4s
#EXTINF:0.541000,
hls377676.m4s
#EXTINF:0.522000,
hls377677.m4s
#EXTINF:0.547000,
hls377678.m4s
#EXTINF:0.530000,
hls377679.m4s
#EXTINF:0.536000,
hls377680.m4s
#EXTINF:0.549000,
hls377681.m4s
#EXTINF:0.516000,
hls377682.m4s
#EXTINF:0.522000,
hls377683.m4s
#EXTINF:0.549000,
hls377684.m4s
#EXTINF:0.539000,
hls377685.m4s
#EXTINF:0.502000,
hls377686.m4s
#EXTINF:0.548000,
hls377687.m4s
#EXTINF:0.543000,
hls377688.m4s
#EXTINF:0.518000,
hls377689.m4s
#EXTINF:0.549000,
hls377690.m4s
#EXTINF:0.510000,
hls377691.m4s
#EXTINF:0.532000,
hls377692.m4s
#EXTINF:0.558000,
hls377693.m4s