Good morning. I am trying to join 2 mp4s. Video 1 is a 10 second video created with ffmpeg from a single image and has a silent audio created with anullsrc. Video 2 is, unfortunately, vfr and since ffmpeg does not like to create vfr files, at least to match the format of another. I tried to convert video 2 to cfr but audio sync errors occur.
Does anyone know the best way to join these 2 together. If they both must be reencoded then how can i do this and keep audio in sync. I would like to use ffmpeg and/or avisynth since they are cli.
Thank you
+ Reply to Thread
Results 1 to 15 of 15
-
-
I think you will have to convert both files to something that has the exact same specs and then they can be appended together. If there is another method I am sure someone will help you find it.
-
I would recommend using the Video To Video Converter for some of your converting tasks.
-
Have you tried MKVToolNix? It has several options for joining video/audio files in the same container. If it works you can use mkvmerge in CLI.
-
I think you will have to convert both files
I would recommend using the Video To Video Converter
Have you tried MKVToolNix
Thanks for replies. -
Would prefer to keep final output as mp4
-
Well, you could cat in mkvtoolnix. Then convert to mp4 using ffmpeg.
Or you can try the cat features provided by ffmpeg:
https://trac.ffmpeg.org/wiki/Concatenate -
For anybody who would like to try Avisynth, here's a script I had that joins two files:
In my case the files had slightly different properties (but same aspect ratio). The code modifies
the size, frame rate and audio sample rate so they match. If the two files have the same properties, this matching code
does nothing.
LoadCPlugin("I:\mypath\ffms2.dll")
Video2 = dss2("S:\mypath\music video one.avi")
Audio2 = directshowsource("S:\mypath\music video one.avi", video=no)
Audio1 = FFAudioSource("S:\mypath\music video two.mkv", track=-1)
Video1 = FFVideoSource("S:\mypath\music video two.mkv", track=-1)
Video1 = Video1.ConvertToYV12()
Video2 = Video2.ConvertToYV12()
a=audiodub(video1,audio1)
b=audiodub(video2,audio2)
b=b.blackmanresize(a.width,a.height) # fix mismatch size
b=b.assumefps(a.framerate,sync_audio=true).Resampl eAudio(a.AudioRate) # fix mismatch frame rate and audio sample rate
return a+bLast edited by davexnet; 16th Feb 2018 at 14:39.
-
One way would be do extract VFR timecodes, edit them by shifting them and adding the 1st part. It might be easy if there are only a few different sections, or it can be difficult if you have very variable file. Join the elementary streams, then use mp4fpsmod to mux the timecodes
How did you "try to convert video 2 to cfr" with the sync problems ? Which methods did you try ? -
Some notes about the above script, it wont work as-is if the amount of audio channels don't match, also in some cases,
changefps (or convertfps) will be better than assumefps.
Also, you can use what ever source filter you like. The only reason I used DSS2/directshowsource was because
FFmpegsource would not work on my partitcular AVI file. -
How did you "try to convert video 2 to cfr" with the sync problems ? Which methods did you try ?
-
It depends on what type of "VFR" (there are different variants). The most common would be things like camera phones, webcaptures, internet video, etc.. Those are actually missing frames and there are dips in the framerate , sometimes speed ups, which keep everything in sync
For those types, a proper CFR conversion inserts duplicate frames in approximately the correct locations where they were dropped in the first place. Most reliable way in my experience is DirectShowSource in avisynth with convertfps=true . You would use whatever the base frame rate was . If it was 30.0, that' s what you would enter
eg
Code:DirectShowSource("video.mp4", fps=30.0, convertfps=true, audio=false)
Some people would say ffms2 with fpsnum and fpsden . In my experience, not as reliable. You need it as accurate as possible when editing videos, and I've done thousands of these. The ffms2 conversion is slightly off and errors propogate. It might be ok for a one off, but when you edit dozens of videos in a project, those slightly more off frames are a nightmare. (And I can't believe I'm saying this, but this is the 1 case where DirectShowSource is an actually preferred source filter; but it requires that you keep your directshow filters in order too...) -
Thanks everyone for help. I tried all possibilities since this was a good test video being VFR and a little odd working with it and playing compared to others. I was able to modify an avisynth script using a combination of the posts by Poisondeathray and Davexnet.
Code:video2 = directshowsource("c:\users\bud\desktop\[dp]Manjandani-1.mp4", fps=23.976, convertfps=true, audio=true) Video1 = directshowsource("c:\users\bud\desktop\output.mp4") Video1 = Video1.ConvertToYV12() Video2 = Video2.ConvertToYV12() a=video1 b=video2 b=b.blackmanresize(a.width,a.height) # fix mismatch size b=b.assumefps(a.framerate,sync_audio=true).ResampleAudio(a.AudioRate) # fix mismatch frame rate and audio sample rate return a+b
[Attachment 44711 - Click to enlarge]
The number of frames shown above for the 10 second video was 240 (23.976 x 10) but I assume thats as close as it could get to 239.76 frames and only results in an extra 11 ms for video 1. It doesn't seem to affect video 2 after it is joined so no biggie.
Thanks again everyone who replied and helped!Last edited by Budman1; 17th Feb 2018 at 00:43. Reason: Chrome dropped unexpectedly before I finished.
-
Code:
MP4Box -cat video1.mp4 -cat video2.mp4 -new new_video.mp4
Code:MP4Box -add video1.mp4 -cat video2.mp4 -new new_video.mp4
Code:mencoder video1.mp4 video2.mp4 -ovc copy -oac copy -of lavf format=mp4 -o new_video.mp4
You can get mencoder from here.
Or you can use My-MP4Box-GUI
Similar Threads
-
Trouble Converting M4S into MP4
By einstein1 in forum Video ConversionReplies: 6Last Post: 15th Sep 2020, 05:43 -
Joining two MP4 files encoded differently?
By yetanotherlogin in forum EditingReplies: 2Last Post: 10th Aug 2017, 08:00 -
Having trouble converting MKV to MP4
By greyhaven in forum Newbie / General discussionsReplies: 3Last Post: 25th Jul 2017, 08:58 -
Trouble converting .flv to .mp4 and having it be useful
By Piefrenzy in forum Video ConversionReplies: 12Last Post: 7th Aug 2014, 18:48 -
Having trouble joining various FLV files using mkvmerge
By ragz4ragz in forum EditingReplies: 4Last Post: 9th Nov 2013, 07:45