VideoHelp Forum




+ Reply to Thread
Results 1 to 11 of 11
  1. Member
    Join Date
    Feb 2021
    Location
    Sweden
    Search Comp PM
    I have a scripted system on Linux for downloading real time streaming video for later viewing, which uses ffmpeg to retrieve the videos through their m3u8 urls into mp4 files.
    Some of these videos are 2 or even 3 hours long and I would like to be able to start viewing them while they are still being downloaded.
    But when I point my video player to the mp4 file being written it fails to display anything.

    So I am wondering if there is a way to do the downloading such that the file being written at the end can be simultaneously viewed from the beginning including performing timed playback jumps?

    My ffmpeg command for the download looks like this:
    Code:
    CMD="ffmpeg -hide_banner -referer \"${VIDEOURL}\" -i \"${M3U8URL}\" -r 30 -vf scale=w=-4:h=480 -c:v libx264 -preset fast -crf 26 -x264-params keyint=30:scenecut=0:open-gop=0 -c:a aac -t ${CAPTURETIME} ${TARGETFILE}"
    The reason for the complex filter is that I want the keyframes start on even seconds to enable simpler and faster editing.
    Quote Quote  
  2. I've noticed that you're re-encoding the video file. Why is that? You could also just copy the codecs over with
    Code:
    -c copy
    If you want to pre-play the video, then use
    Code:
    -f mpegts
    to set the mpegts protocol.
    Bypass HMACs, One-time-tokens and Lic.Wrapping: https://github.com/DevLARLEY/WidevineProxy2
    Quote Quote  
  3. Member
    Join Date
    Feb 2021
    Location
    Sweden
    Search Comp PM
    Originally Posted by larley View Post
    I've noticed that you're re-encoding the video file. Why is that? You could also just copy the codecs over with
    Code:
    -c copy
    If you want to pre-play the video, then use
    Code:
    -f mpegts
    to set the mpegts protocol.
    Well, I used copy earlier but then it was near impossible to edit the files because there were always artifacts of surrounding scenes at the cut points in the final video. And re-encoding after the video was downloaded took about 10 minutes per hour of video so was not useful either.
    With the on-the-go re-encoding I got control of the frame borders and now applying an edit command with 10 cut points in a 1-hour video takes something like 10 s to process.

    Before I did this though, I could still not play the video unless it had been completely downloaded.
    It looks like something necessary for playback is added to the video at the end of recording and if that is missing the video is unplayable. Some closing data needed for playback is located at the end of the file, maybe?

    This always (also in the present solution) happens if there is an interruption of the download just before it would have ended anyway...

    I have noted on my PVR box that it is possible on that to start viewing a recording that is still not finished.
    But that is on a system recording off-air via an antenna so it is not streaming video...
    Quote Quote  
  4. Haven't tried myself, but maybe adding "-movflags +faststart" to the ffmpeg arguments may help as well. Or encoding as mkv.
    Quote Quote  
  5. Member
    Join Date
    Feb 2021
    Location
    Sweden
    Search Comp PM
    Originally Posted by Obo View Post
    Haven't tried myself, but maybe adding "-movflags +faststart" to the ffmpeg arguments may help as well. Or encoding as mkv.
    I will try the suggested flags.
    Regarding encoding I need mp4 for the compression and my tools (self developed)....
    Quote Quote  
  6. Originally Posted by BosseB View Post
    I have noted on my PVR box that it is possible on that to start viewing a recording that is still not finished.
    But that is on a system recording off-air via an antenna so it is not streaming video...
    They're recording the videos as .ts files, which support this kind of operation. So setting '-f mpegts' should work, as I've tested it

    EDIT: Obo's solution works too
    Last edited by larley; 13th Aug 2024 at 03:16.
    Bypass HMACs, One-time-tokens and Lic.Wrapping: https://github.com/DevLARLEY/WidevineProxy2
    Quote Quote  
  7. Member
    Join Date
    Feb 2022
    Location
    Search the forum first!
    Search PM
    Code:
    N_m3u8DL-RE --save-name test "http://xxxx,xxxx,xxxxx.mpd" --append-url-params --mp4-real-time-decryption --use-shaka-packager  --key xxxxxxxxxxxxxxxxxxxxxxx:xxxxxxxxxxxxxxxxxxxxxxx   --live-pipe-mux
    produces a ts file that just grows. and vlc test.ts plays it. I was using this format to watch 4k Olympics output. If it isn't encrypted then only --live-pipe-mux is likely needed in the command. I found, by using vlc on my PC, I could cast to my TV; look under 'playback' and choose renderer.
    Noob Starter Pack. Just download every Widevine mpd! Not kidding!.
    https://files.videohelp.com/u/301890/hellyes6.zip
    Quote Quote  
  8. Member
    Join Date
    Feb 2021
    Location
    Sweden
    Search Comp PM
    Originally Posted by larley View Post

    EDIT: Obo's solution works too
    Not for me...
    I tried to modify the ffmpeg command as follows (added -movflags +faststart after -r 30):

    Code:
    CMD="ffmpeg -hide_banner -referer \"${VIDEOURL}\" -i \"${M3U8URL}\" -r 30 -movflags +faststart  -vf scale=w=-4:h=480 -c:v libx264 -preset fast -crf 26 -x264-params keyint=30:scenecut=0:open-gop=0 -c:a aac -t ${CAPTURETIME} ${TARGETFILE}"
    Then started a 3 min recording and after a minute or so tried to open the mp4 file in a video player, but it did not show up...

    When it was all done it played fine so there is something blocking it from being viewed until fully recorded.
    Quote Quote  
  9. '-movflags empty_moov'
    Quote Quote  
  10. Member
    Join Date
    Feb 2021
    Location
    Sweden
    Search Comp PM
    Originally Posted by LZAA View Post
    '-movflags empty_moov'
    OK thanks!
    So this did allow starting viewing of the mp4 file while it was downloading.

    But the length of the video inside the video player (VLC) seems to be read at the moment of opening the file and is not updated while the video is downloaded further.
    So the player stops at the location the recording was when it started to play the file even though the file is now longer.

    I don't know what this setting might mean for the video itself, I will have to check it further to see if I find any problems.

    What exactly is this moov thing?
    Quote Quote  
  11. 'moov' is an MPEG-4 atom (kinda like a container), that contains metadata about the video
    Bypass HMACs, One-time-tokens and Lic.Wrapping: https://github.com/DevLARLEY/WidevineProxy2
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!