VideoHelp Forum
+ Reply to Thread
Results 1 to 3 of 3
Thread
  1. Member
    Join Date
    Feb 2021
    Location
    Sweden
    Search Comp PM
    I have been using ffmpeg in order to download content from a streaming source into an mp4 file while converting the format to a smaller size (480P).
    Then when the download finishes I can view the content by playing the downloaded file.

    I have scripted it on a Linux server (no GUI there) so the downloads can be done unattended on off hours and viewed later (time zone differences).

    Now I wonder if there is a way to convert the download to something that can be viewed in real time as it is being recorded?

    If I set the target to a ts file instead of mp4, can it then be viewed while the download goes on?

    My current command in the script file looks like this:
    Code:
    CMD="ffmpeg -hide_banner -loglevel warning -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}"
    where:
    VIDEOURL is the source webpage which contains an embedded video player
    M3U8URL is the stream URL for the video on that player
    CAPTURETIME is the final video length in seconds
    TARGETFILE is the name of the output mp4 fiile

    How should I modify this command in order to make it produce a file that can be viewed at the same time the download runs?
    I think that the mp4 format is not suited since such files need to have a "moov" part that can only be written at the end of a download when the file is closed for writing by ffmpeg.
    So possibly converting into a ts file or similar would be a way?

    Or is there a better way to do it where the output can be viewed as it is being created?

    I use a web browser to connect to my Linux server to view the downloaded files, so something tah can be opened in a web browser would be the output I am after.

    Any suggestion welcome.
    Quote Quote  
  2. change to .ts
    Code:
    CMD="ffmpeg -hide_banner -loglevel warning -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 -f mpegts ${TARGETFILE}.ts"
    play in web browser: http://<your-server-ip>:8000/${TARGETFILE}.ts
    Code:
    python3 -m http.server 8000
    Quote Quote  
  3. Member
    Join Date
    Feb 2021
    Location
    Sweden
    Search Comp PM
    Thanks, this worked to create the ts file,
    But now I have to work on my infrastructure since my utilities assume a video file everywhere with extension mp4....
    I could play the created file in VLC so the command seems to work fine, I "just" have to allow my website to serve out ts files from a webpage.

    The current breed only serves out mp4 files so I must somehow change it so it will also accept the ts file ending.

    The webpage lists all files with extension mp4 in a given directory and when one clicks a file in the list a call is made to a php script which takes the file name (without extension) as argument and finally ends in this php section:

    Code:
    <?PHP
            echo "<div>\n";
            $videofile = $videofile . '.mp4';  //Assumes name-only call and only mp4 files
            echo "<video id=\"myVid\" controls autoplay>\n";
            echo "<source src=\"$videofile\" type=\"video/mp4\" />\n</video>\n";
            echo "<script>\n";
            echo "var vid = document.getElementById(\"myVid\");\n";
            echo "vid.volume = 0.3;\n";
            echo "</script>\n";
            echo "</div>\n";
    ?>
    As you can see it takes the name without extension as argument and adds on .mp4.
    Then it proceeds assuming an mp4 file until the playing fails...

    I have to somehow fix this otherwise no playback of ts files is possible on my server..

    So two things need to be done:
    - List files with mp4 and ts extensions separately
    - Add a host player for the ts type files to be used with these

    The code above was retrieved many years ago via a discussion in a forum (don't remember now which one), so now I need to get help somehow to fix it to be able to handle both.

    The best would be for the server to be able to check what kind of file is used and adjust the player accordingly.
    Which of course I am not able to do at the moment.
    Maybe ChatGPT can help????
    Quote Quote  



Similar Threads

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