VideoHelp Forum
+ Reply to Thread
Results 1 to 29 of 29
Thread
  1. Member
    Join Date
    Mar 2014
    Location
    nice try...
    Search Comp PM
    I'm trying to sync a video file (.mp4) with an audio file (.flac). In order to do so, I will need to add black frames to the beginning and ending. Of course, it would be easier to do this kind of thing with a video encoder and then reencode everything, but I really don't want to do that, partially because to reencode everything losslessly is ridiculous. Do you have any suggestions on how to do this? (I don't care if the process invokes changing the .mp4 to .mkv)
    Quote Quote  
  2. Dinosaur Supervisor KarMa's Avatar
    Join Date
    Jul 2015
    Location
    US
    Search Comp PM
    Could'nt you just add or remove a few ms of audio from the flac, in audacity for example.
    Quote Quote  
  3. Member
    Join Date
    Mar 2014
    Location
    nice try...
    Search Comp PM
    No. The audio is several seconds longer than the video, and the video starts a few seconds after the audio starts, and ends before the audio ends.
    Quote Quote  
  4. Member
    Join Date
    Sep 2012
    Location
    Australia
    Search Comp PM
    If it's an mp4 you could try modifying an edit list. If there's already a black frame at the beginning of the video, then you could probably just slow it down to a fraction of a frame per second. Other than that you could just repeat the frame over and over.

    I'm no expert on mp4, I don't know how many players would obey and I don't know if editing the video track will affect the other tracks but it may be interesting to find out.
    Quote Quote  
  5. Member
    Join Date
    Sep 2012
    Location
    Australia
    Search Comp PM
    Or, make the video VFR and have the first frame extend to the length of the extra audio.
    Quote Quote  
  6. Dinosaur Supervisor KarMa's Avatar
    Join Date
    Jul 2015
    Location
    US
    Search Comp PM
    Um well if you can encode a new video with the exact same codec, the same settings, and this codec can be fed with avisynth. Then you could just take the new blank videos and append them onto the front and back of the video, with MP4Box (or MP4BoxGUI).

    To make the blank videos with avisynth, you can use this script as a template, edit as needed to match resolution, fps, needed length and so on. You only need BlankClip to for this, nothing else in the script.
    Code:
    BlankClip(length=1000, pixel_type="YV12", fps=25, width=1280, height=720)
    http://avisynth.nl/index.php/BlankClip
    Image Attached Files
    Quote Quote  
  7. Originally Posted by Danfun64 View Post
    I'm trying to sync a video file (.mp4) with an audio file (.flac). In order to do so, I will need to add black frames to the beginning and ending. Of course, it would be easier to do this kind of thing with a video encoder and then reencode everything, but I really don't want to do that, partially because to reencode everything losslessly is ridiculous. Do you have any suggestions on how to do this? (I don't care if the process invokes changing the .mp4 to .mkv)
    read this first: https://forum.videohelp.com/threads/346293-Insert-Audio-Delay-With-ffmpeg
    no need to recode - i would recommend method with adjusting audio PTS - look at https://ffmpeg.org/ffmpeg-filters.html#setpts_002c-asetpts
    Quote Quote  
  8. Member
    Join Date
    Mar 2014
    Location
    nice try...
    Search Comp PM
    ...I'd rather have a *video* delay.

    edit: #KarMa: How do I identify the exact settings of a video?
    Last edited by Danfun64; 20th Jan 2016 at 13:04.
    Quote Quote  
  9. Originally Posted by Danfun64 View Post
    ...I'd rather have a *video* delay.
    A negative audio delay is equivalent to a video delay.
    Quote Quote  
  10. Member
    Join Date
    Mar 2014
    Location
    nice try...
    Search Comp PM
    Thanks for the advice pandy and jagabo. Unfortunately, I don't understand how I can adjust the audio PTS. Can you post clear instructions?

    edit: #KarMa: did you read my last reply?

    edit 2: I got the info. https://paste.debian.net/hidden/c3cc13ff/

    Now, how could I get ffmpeg to encode a video that is completely with no audio and those settings for a specific amount of seconds and milliseconds? If I can figure that out, then my problem is solved.
    Last edited by Danfun64; 20th Jan 2016 at 16:59.
    Quote Quote  
  11. Originally Posted by Danfun64 View Post
    Thanks for the advice pandy and jagabo. Unfortunately, I don't understand how I can adjust the audio PTS. Can you post clear instructions?

    Now, how could I get ffmpeg to encode a video that is completely with no audio and those settings for a specific amount of seconds and milliseconds? If I can figure that out, then my problem is solved.

    Perhaps as:
    Apply an offset of 10 seconds to the input PTS:

    setpts=PTS+10/TB
    then for audio it could be something like this:

    Apply an offset of -10 seconds to the input audio PTS:

    asetpts=PTS-10/TB
    Quote Quote  
  12. Member
    Join Date
    Mar 2014
    Location
    nice try...
    Search Comp PM
    Thanks for answering the first question. Unfortunately you didn't answer my second question at all.

    edit: By settings I meant what is referred to in the paste.debian.net link.
    Last edited by Danfun64; 21st Jan 2016 at 12:34.
    Quote Quote  
  13. Originally Posted by Danfun64 View Post
    Thanks for answering the first question. Unfortunately you didn't answer my second question at all.

    edit: By settings I meant what is referred to in the paste.debian.net link.
    You won't be able to. There are too many variables, many hidden, that have to match exactly.

    You're better off trimming some head or tails off the original clip and trying to duplicate and re-append that, or using a smart renderer like videoredo or TMPGenc Smart Renderer, adding clips that approximate your master and let the payed software match it and combine.
    Quote Quote  
  14. Member
    Join Date
    Mar 2014
    Location
    nice try...
    Search Comp PM
    Can both videoredo and TMPgenc Smart Renderer be run completely offline? I heard bad things about TMPGenc in general concerning drm. They could be wrong, but...
    Quote Quote  
  15. Originally Posted by Danfun64 View Post
    Can both videoredo and TMPgenc Smart Renderer be run completely offline? I heard bad things about TMPGenc in general concerning drm. They could be wrong, but...
    I've heard nothing bad about TMPGenc -- do you mean that it occasionally calls home on start-up to make sure you're using a legal copy?
    Quote Quote  
  16. Member
    Join Date
    Mar 2014
    Location
    nice try...
    Search Comp PM
    Not necessarily, but I thought that it required to be online most of the time.

    edit: ...oh boy...

    http://www.videoredo.com/en/CompareProducts.htm (main issue is that FLAC isn't supported, though that could be remedied with mkvtoolnix. Either that or I can have audio as an uncompressed wave.)

    http://tmpgenc.pegasys-inc.com/en/info/lic_val.html (they can require validation whenever they want, and could care less about people who want their privacy respected. Somehow it wouldn't surprise me if piracy increased because of their validation "feature".)

    I know that videoredo costs more than tmpgenc smart renderer, but if videoredo has no validation feature, then it is well worth the additional cost. Freedom isn't free, you know.

    edit 2: I noticed that Smart Renderer isn't mentioned in the validation list. Then again, said list may be outdated...
    Last edited by Danfun64; 21st Jan 2016 at 20:07.
    Quote Quote  
  17. Dinosaur Supervisor KarMa's Avatar
    Join Date
    Jul 2015
    Location
    US
    Search Comp PM
    Originally Posted by Danfun64 View Post
    ...I'd rather have a *video* delay.

    edit: #KarMa: How do I identify the exact settings of a video?
    Mediainfo should tell you most of what you need to know.
    Quote Quote  
  18. Member
    Join Date
    Mar 2014
    Location
    nice try...
    Search Comp PM
    ...I already found out about Mediainfo. That's where the info from paste.debian.net is from.
    Quote Quote  
  19. Dinosaur Supervisor KarMa's Avatar
    Join Date
    Jul 2015
    Location
    US
    Search Comp PM
    Originally Posted by Danfun64 View Post
    ...I already found out about Mediainfo. That's where the info from paste.debian.net is from.
    Ok sorry about that, did not notice everything since my last post. How many seconds of blank frames do you need, or number of blank frames, or how every you are measuring it. I can just encode it.
    Quote Quote  
  20. Member
    Join Date
    Mar 2014
    Location
    nice try...
    Search Comp PM
    Thanks for the offer, but I don't want to bug you every time I want seconds of black. Out of curiosity, how were you going to encode it?
    Quote Quote  
  21. Dinosaur Supervisor KarMa's Avatar
    Join Date
    Jul 2015
    Location
    US
    Search Comp PM
    Megui was going to be my easiest option, which is just a gui for avisyth, x264, a bunch of other things. It seems like your video was encoded with the x264 preset "Very Fast" along with High@L3.2 and a CRF of 14. So encoding with these settings should make it close enough to allow them to be joined.

    You can take the below code and save it in a text file, and change the ending from .txt to .avs. And then just drag and drop it in the video encoding area labeled "avisynth script", of Megui. And just change the x264 settings to what I described. https://forum.videohelp.com/images/imgfiles/YmYC6OX.png Chose the container you want (MKV, MP4, RAW), then click queue which will start the encoding.


    Code:
    BlankClip(length=1000, pixel_type="YV12", fps=30, width=1364, height=768)
    Edit the length as needed, length is equal to the number of frames you want. In my example it's 1000 frames. At 30fps, 1 frame is equal to 33ms (1000/30=33.33ms). I changed the rest of the settings to match the video.
    Last edited by KarMa; 21st Jan 2016 at 23:00.
    Quote Quote  
  22. Member
    Join Date
    Jan 2007
    Location
    United States
    Search Comp PM
    what is the video ?

    can you match the video specs, by editing some black frames from something else and transcoding them to the desired specs
    cut to the desired length
    then merge /append to the video in question ?
    Quote Quote  
  23. Perhaps concatenate will work for adding black frame. Create 1frame black video and later concatenate it in a sequence: black video + video + black video.
    Quote Quote  
  24. Member
    Join Date
    Mar 2014
    Location
    nice try...
    Search Comp PM
    @KarMa: Thanks for the advice. I'm thinking of trying it out, but I am afraid that it won't align exactly with the video. Perhaps, just this once at the very least, I will provide the seconds and milliseconds and see if it is possible to provide a smooth transition between the two sources.

    If it doesn't align properly, then I'll have to come up with something else. One solution could be using either videoredo or TMPG Smart Renderer (if it doesn't have random validation) and having only small parts reencoded. Another might be doubling the frame rate, if necessary.

    @theewizard: I'm going to warn you now, the source is ridiculous. The video source is an Open Broadcaster Software recording of my desktop and a coop playthrough of Doom. The audio source is a hybrid of the video source's audio and a mumble recording. The mumble recording has a longer start and end than the OBS video.

    @pandy: Aside from sounding a little on the impractical side (wouldn't having dozens of 1 second blank videos overload and crash something?), it poses the same problem that KarMa's solution has: it might not sync up properly.

    edit: The start video should be 10058119 audacity samples and the end video should be 311260 audacity samples.
    Last edited by Danfun64; 22nd Jan 2016 at 18:20.
    Quote Quote  
  25. As mentioned above, a 30FPS video can only have 33.3ms accuracy. Humans can typically distinguish ~30-60ms where desync becomes noticable. You can do it with more accuracy with VFR as suggested earlier , but this can be tricky to do. Higher framerates, for example, 60FPS CFR would give you 16.7ms accuracy, but you cannot change the framerate higher of the main section without re-encoding

    For most people, the simplest method would still be to use a video editor to get the sync timing. Again this only provides 33.3ms accuracy or 1 frame ; you can' t have 0.2343 frames in video for example, only whole frames), but only export the "black" sections, then append . You can do this in avisynth as well, you can playback avs scripts in mpchc for example to test sync. info() will also tell you the number of audio samples
    Quote Quote  
  26. This is so simple. There are two ways to address it:

    The audio and video in a file don't need to start at the same time or be the same length. You can just mux the longer audio with the video and set a negative audio delay value. The only drawback to this is that you don't know exactly how different players will handle the delayed video at the start and any extra audio at the end. At the start, some may display black frames until the video starts. Others may display the first frame of the video until it's time to play the video. Some may skip the first part of the audio and start playing both when the video starts. At the end, if the audio is longer than the video some may display the last frame of video until the audio is done. Some may stop playing at the end of the video stream.

    The more foolproof way is to render short blank videos and append them. Make the frame the same size, use the same codec and similar enough codec settings. Then just use a muxer like MkvToolinx to append the video segments blank1+video+blank2 and mux in the audio. Single frame accuracy on the audio offset is probably sufficient but you can combine this with a small audio delay/advance to get more perfect results.

    Audio sync should also be easy to determine if there's no difference in speed, only an offset. Just load the original video and longer audio into a player that supports manual A/V sync adjustments, like MPCH. Then just adjust the audio delay until it's playing in sync.
    Last edited by jagabo; 23rd Jan 2016 at 09:25.
    Quote Quote  
  27. Member
    Join Date
    Mar 2014
    Location
    nice try...
    Search Comp PM
    I am currently using MKVToolNix GUI to merge three files, two blank videos made with megui, and the main file. I get this warning:
    --- Warnings emitted by job 'merging to file "clip1 (1).mkv" in directory "C:/Users/Danfu/Documents/megui"' started on 2016-01-23 13:24:42 ---
    The track number 0 from the file 'E:/home/danfun64/Videos/2016-01-01_22-22-18.mp4' can probably not be appended correctly to the track number 0 from the file 'C:/Users/Danfu/Documents/megui/clip1.mkv': The codec's private data does not match (lengths: 42 and 43). Please make sure that the resulting file plays correctly the whole time. The author of this program will probably not give support for playback issues with the resulting file.
    The track number 0 from the file 'C:/Users/Danfu/Documents/megui/clip2.mkv' can probably not be appended correctly to the track number 0 from the file 'E:/home/danfun64/Videos/2016-01-01_22-22-18.mp4': The codec's private data does not match (lengths: 43 and 42). Please make sure that the resulting file plays correctly the whole time. The author of this program will probably not give support for playback issues with the resulting file.
    I'm not sure if it will play correctly. What can I do to get the megui videos to match the length of the private data?

    edit: So far, it appears to be playing correctly, but I am still concerned, especially with the "author of this program will probably not give support for playback issues with the resulting file" thing. To be fair, I think I have to redo the video anyway, as there are minor sync problems.

    edit 2: Setting the audio delay to -100 ms in VLC fixed the sync. So basically I have to make clip1 longer, possibly make clip2 shorter, and encode the avs scripts for clip1 and clip 2 to have the correct private data length thingy.

    edit 3: It doesn't correct the private data length thingy, but it does fix the audio delay. Eventually I thought to myself, "Why do I need the black parts of the video at all? I can edit the audio to match the length of the video and not lose anything of importance." So I did. I'm not sure if this means the thread is over and done.
    Last edited by Danfun64; 25th Jan 2016 at 15:03.
    Quote Quote  
  28. Member
    Join Date
    Mar 2014
    Location
    nice try...
    Search Comp PM
    accidental double post. Please delete me.
    Last edited by Danfun64; 23rd Jan 2016 at 13:37.
    Quote Quote  
  29. Originally Posted by Danfun64 View Post
    @pandy: Aside from sounding a little on the impractical side (wouldn't having dozens of 1 second blank videos overload and crash something?), it poses the same problem that KarMa's solution has: it might not sync up properly.

    edit: The start video should be 10058119 audacity samples and the end video should be 311260 audacity samples.
    It's your call not mine - don't see how this can be done without recoding video, side to this concatenate and PTS modification are lossless and fastest way to deal with problem (also most elegant from engineer perspective) - but once again - not my circus and not my monkeys.

    And samples are meaningless - time is everything - you may have different sample rates and number of samples without sample rate have no value.
    Quote Quote  



Similar Threads

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