VideoHelp Forum
+ Reply to Thread
Results 1 to 4 of 4
Thread
  1. Member
    Join Date
    Feb 2021
    Location
    Sweden
    Search Comp PM
    I have developed a Linux script program which I use to download a few news live streams for later viewing (I am on a completely different time zone).

    The downloading is done using an ffmpeg command which reformats the stream on the fly into the mp4 format I need for further editing.
    It runs unattended on an Ubuntu 20.04 server (no GUI).

    This is the main command that does the download:

    Code:
    ffmpeg -hide_banner ${MODE} -i \"${M3U8URL}\" -r 30 -vf scale=w=-4:h=${VIDEORES} -c:v libx264 -preset fast -crf 26 -x264-params keyint=30:scenecut=0:open-gop=0 -c:a aac -t ${CAPTURETIME} ${TARGETFILE}
    The variables hold these items:
    MODE="-referer \"${VIDEOURL}\"" and VIDEOURL is the source page where the video stream appears
    M3U8URL=the stream URL within the webpage
    VIDEORES="480"
    CAPTURETIME=the recording time in seconds from the source
    TARGETFILE= the outut file in mp4 format

    Now I would like to be able to optionally also speed up the video such that it can be viewed in a shorter time.

    I have researched the command to recode the video with a higher speed while keeping the pitch and sync of the audio part.
    This is placed in another script file that can do the conversion from an input file to an output file:

    Code:
    ffmpeg -hide_banner  -i ${SOURCEFILE} -filter_complex \"[0:v]setpts=1/${SPEEDUP}*PTS[v];[0:a]atempo=${SPEEDUP}[a]\" -map \"[v]\" -map \"[a]\"  ${TARGETFILE}
    Here the variables are:
    SOURCEFILE=input mp4 file created by the previous command
    SPEEDUP=a decimal number for the output video playback speed between 0.5 and 2.0
    TARGETFILE= the outut file in mp4 format

    This works fine but runs at about 6-7 times the playback speed so it takes 10 min to convert a 1 hour video.

    My question is how I can plug the speed conversion into the download command so that the conversion is done during streaming.
    I need to send the output of the first command into a new "filter" instead of directly to file.

    I have seen ffmpeg doing stuff in series but I have not understood how it works...
    Quote Quote  
  2. Member
    Join Date
    Feb 2021
    Location
    Sweden
    Search Comp PM
    I have tried this in order to insert the speed handling after the other stuff and before sending it to the output file:

    Code:
    SPEED="1.25"  #Test value, should be a script call argument.
    
    SPEEDCMD=" -filter_complex \"[0:v]setpts=1/${SPEED}*PTS[v];[0:a]atempo=${SPEED}[a]\" -map \"[v]\" -map \"[a]\" "  #This will speed up/down the video by the SPEED amount
    CMD="ffmpeg -hide_banner ${MODE} -i \"${M3U8URL}\" -r 30 -vf scale=w=-4:h=${VIDEORES} -c:v libx264 -preset fast -crf 26 -x264-params keyint=30:scenecut=0:open-gop=0 -c:a aac -t ${CAPTURETIME} ${SPEEDCMD} ${TARGETFILE}"
    ...
    eval "$CMD"
    RES=$?  #-----Check ffmpeg exit code
    When I try this I get this error:
    Code:
    Filtergraph 'scale=w=-4:h=480' was specified through the -vf/-af/-filter option for output stream 0:0, which is fed from a complex filtergraph.
    -vf/-af/-filter and -filter_complex cannot be used together for the same stream.
    So the entire speed filter is inserted just before the file output at the end, is this not how one can add extra filtering?
    And what could I do instead?
    Quote Quote  
  3. You can use pipe so sequence multiple ffmpeg instances - honestly i don't get what is your goal - such speed conversion should be possible in single ffmpeg without problem.
    Quote Quote  
  4. Member
    Join Date
    Feb 2021
    Location
    Sweden
    Search Comp PM
    Originally Posted by pandy View Post
    You can use pipe so sequence multiple ffmpeg instances - honestly i don't get what is your goal - such speed conversion should be possible in single ffmpeg without problem.
    My goal is to be able to view the news shows from USA in my own time zone, so I have created a download system where I use ffmpeg to capture the shows nightly in my Ubuntu server.
    Then I want to remove the ads before viewing so I have created a video editor where I can set cut points accurate to 1 second. The video editor creates a call with the cut points to another ffmpeg based program, which performs the extraction and pasting together of the cuts to create the final video for watching.

    Originally I had a much simpler download command but that resulted in videos that could not easily be cut at the cut points so there were artifacts of removed sections in the final video.

    After discussions here I wound up with the final download command shown above where:
    - The video size is re-encoded on the fly, because if done afterwards it takes about 10 min per video hour..
    - The frames are set on the fly in the same inline command so I don't have to process anything afterwards except the cutting.
    - The cut/paste operations are now not creating artifacts and it works much faster too (a few seconds only)

    Current problem:
    Now I have thought that I could save viewing time by speeding up the final video by some 10-15%, but this operation also takes some 10-15% of the original video playing time, so I would like to do that too during download so it will be ready immediately as the download completes.
    The command used is based on what I have found on-line and it works well enough, except it takes time so I would like it to be done while downloading too.

    So what is the proper way to insert the speedup into the download command so it will run concurrently?
    Quote Quote  



Similar Threads

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