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)
+ Reply to Thread
Results 1 to 29 of 29
-
-
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.
-
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. -
Or, make the video VFR and have the first frame extend to the length of the extra audio.
-
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)
-
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 -
...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 12:04.
-
-
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 15:59.
-
-
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 11:34.
-
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. -
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...
-
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 19:07.
-
-
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?
-
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)
Last edited by KarMa; 21st Jan 2016 at 22:00.
-
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 ? -
Perhaps concatenate will work for adding black frame. Create 1frame black video and later concatenate it in a sequence: black video + video + black video.
-
@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 17:20.
-
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 -
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 08:25.
-
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.
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 14:03.
-
accidental double post. Please delete me.
Last edited by Danfun64; 23rd Jan 2016 at 12:37.
-
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.
Similar Threads
-
Adding Black Bars to MP4 Video
By DonSeenu in forum Newbie / General discussionsReplies: 9Last Post: 2nd Nov 2015, 22:02 -
Changing the resolution of MP4 video by adding black band to top and bottom
By Crea in forum Video ConversionReplies: 10Last Post: 15th Aug 2015, 17:18 -
Encoding videos adds 10-20 black frames at the beginning of the video
By jacob28348 in forum EditingReplies: 1Last Post: 9th Feb 2015, 10:42 -
Encoding videos adds 10-20 black frames at the beginning of the video
By jacob28348 in forum Video ConversionReplies: 1Last Post: 9th Feb 2015, 03:39 -
PS3/MP4 Playback and Black Screen - easiest way to fix file/reencode?
By jumpdeveraux in forum Newbie / General discussionsReplies: 2Last Post: 17th Jun 2012, 04:30