VideoHelp Forum



Support our site by donate $5 directly to us Thanks!!!

Try StreamFab Downloader and download streaming video from Netflix, Amazon!



+ Reply to Thread
Results 1 to 9 of 9
  1. Member
    Join Date
    Feb 2021
    Location
    Sweden
    Search Comp PM
    I am using a script on Ubuntu to download streamed shows nightly.
    The script collects input arguments and uses an ffmpeg command to perform the capture:
    Code:
    COMMAND="ffmpeg -user_agent \"Mozilla\" -i $VIDEOURL -t $CAPTURETIME -c copy $TARGETFILE"
    eval $COMMAND
    Here VIDEOURL is the source stream, CAPTURETIME is the number of seconds to download, TARGETFILE is the output file like output.ts

    This runs as at jobs during the night at certain times.

    Since the result is a ts file it needs to be converted into the final mp4 file I will be watching and I use this command for that (also in a script):
    Code:
    COMMAND="ffmpeg -hide_banner -i $INFILE -vf scale=w=-4:h=480 -c:v libx264 -preset fast -crf 16 -c:a copy $OUTFILE"
    This reduces the file size considerably by coverting from 1280x720 format of the ts file to 852x480 in the mp4 file.

    My problem is that the audio and video are not in sync, they are off by 250 ms, so I have to apply yet another script run to adjust the time sync:
    Code:
    COMMAND="ffmpeg -hide_banner  -i $SOURCEFILE -itsoffset $DELAY -i $SOURCEFILE -map 1:v -map 0:a -c copy $TARGETFILE"
    eval $COMMAND
    Here I enter DELAY as -0.25 to reach lip sync.

    My question here is if it is possible to combine the actions of the two processing scripts such that the audio fix is also done when the conversion is done from ts to mp4?

    Note:
    The stream download is as bare as it is because when I tried to do the conversion to mp4 there gaps were created in the result due to processing overload of the Ubuntu server...
    By separating processing from download that problem was cleared and I can do the processing in another Ubuntu machine since the target dir is shared with NFS.
    Quote Quote  
  2. Member Budman1's Avatar
    Join Date
    Jul 2012
    Location
    NORTHWEST ILLINOIS, USA
    Search Comp PM
    even if the TS file audio is in sync, you might try offsetting $file to see what the result is as an mp4.

    COMMAND="ffmpeg -hide_banner -itsoffset $DELAY -i $INFILE -vf scale=w=-4:h=480 -c:v libx264 -preset fast -crf 16 -c:a copy $OUTFILE"
    Quote Quote  
  3. Member
    Join Date
    Feb 2021
    Location
    Sweden
    Search Comp PM
    Thanks, I will test this.

    But after I posted I realized that the delay might be just a delay and maybe it cannot be negative?

    My standalone script command operating on the mp4 file looks like this:
    Code:
    ffmpeg -hide_banner  -i $SOURCEFILE -itsoffset $DELAY -i $SOURCEFILE -map 1:v -map 0:a -c copy $TARGETFILE
    As you can see it uses $SOURCEFILE twice and applies -itsoffset to the second of these.

    If you think about the processing then the stream being delayed (by a positive time) can be buffered by that amount before being combined by the other stream, but it is hard to imagine the other way around.

    In such case maybe the sign should control for which stream the delay (buffering) should be applied to? And the actual value be always positive.

    If this is the case then the script can check where -itsoffset $DELAY should be placed in the call to ffmpeg based on its sign (and the sign removed of course).

    Or else ffmpeg is smart enough to buffer the other stream if the delay is the wrong direction?

    As you see I am a bit confused about these matters...
    Quote Quote  
  4. Member
    Join Date
    Feb 2021
    Location
    Sweden
    Search Comp PM
    Now tested the following commands:

    Code:
    ffmpeg -hide_banner  -i input00.ts -vf scale=w=-4:h=480 -c:v libx264 -preset fast -crf 16 -c:a copy -t 120 test_000.mp4
    ffmpeg -hide_banner -itsoffset -0.8 -i input00.ts -vf scale=w=-4:h=480 -c:v libx264 -preset fast -crf 16 -c:a copy -t 120 test_-800.mp4
    ffmpeg -hide_banner -itsoffset 0.8 -i input00.ts -vf scale=w=-4:h=480 -c:v libx264 -preset fast -crf 16 -c:a copy -t 120 test_800.mp4
    Turns out that all of these mp4 files have the same 250 ms shift between audio and video even though they should have a 0, -800 and +800 ms shift.
    I used 800 ms in order to clearly see the difference but none was apparent...
    Quote Quote  
  5. Deceased
    Join Date
    Dec 2007
    Search PM
    ixnay
    Last edited by blimey; 10th Mar 2021 at 19:32.
    Quote Quote  
  6. Deceased
    Join Date
    Dec 2007
    Search PM
    ^^
    Last edited by blimey; 10th Mar 2021 at 19:34.
    Quote Quote  
  7. You need to specify the input twice, once without a delay once with. Then pick the video from one file, the audio from the other:
    Code:
    ffmpeg -hide_banner -i input00.ts -itsoffset -0.8 -i input00.ts -map 0:v -map 1:a -vf scale=w=-4:h=480 -c:v libx264 -preset fast -crf 16 -c:a copy -t 120 test_-800.mp4
    Quote Quote  
  8. Member
    Join Date
    Feb 2021
    Location
    Sweden
    Search Comp PM
    Originally Posted by jagabo View Post
    You need to specify the input twice, once without a delay once with. Then pick the video from one file, the audio from the other:
    Code:
    ffmpeg -hide_banner -i input00.ts -itsoffset -0.8 -i input00.ts -map 0:v -map 1:a -vf scale=w=-4:h=480 -c:v libx264 -preset fast -crf 16 -c:a copy -t 120 test_-800.mp4
    Yes, I know but this example was from a reply provided here and it did not have two inputs...
    I am now testing with two inputs as you suggested.
    I now see different delays with the 3 tests...
    But the conversion speed is really slow like only 4x the video speed, so a 2 hour video takes 30 min to process...

    The standalone audio sync script I have takes only about 10 seconds to deal exclusively with the audio.
    Quote Quote  
  9. Originally Posted by BosseB View Post
    I am now testing with two inputs as you suggested.
    I now see different delays with the 3 tests...
    But the conversion speed is really slow like only 4x the video speed, so a 2 hour video takes 30 min to process...
    Then use -c:v copy instead of scaling and reencoding.

    -itsoffset applies to all streams in a file. So it can't be used to offset the audio. The video will get the same delay as the audio.
    Quote Quote  



Similar Threads

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