I have a video, I cut it in parts (on keyframes only), then re-encode these parts and merge them together. A slight video jitter appears on each part transition and the audio stutters sometimes after it for a fraction of a second.
If I re-encode the whole merged video again the video jutter is gone, but now there is an additional audio stutter every time exactly on each part transition, which makes it even worse for watching.
Is there any way I could go around this or the moment I re-encode the first time is the moment I lose the possibility to create a fluent video (with audio)?
+ Reply to Thread
Results 1 to 24 of 24
There's no info on what kind of source file you have or tools you use, can you provide a sample and more info? Is the end goal to reencode the parts in to 1 file or do clean edits without video conversion in to 1 file?
you can use Virtualdub2 or Avidemux to edit mp4 videos and with carefull keyframe cuts you can join all of the parts in to 1 file without any video or audio conversion.
if that doesnt help you can open the file with virtualdub2 and export the video to Cineform, open the cineform export on Virtualdub2 and do the edits and export to your favourite video format.
Hope it helps
Last edited by ricardouk; 12th Jan 2020 at 07:40.I love it when a plan comes together!
I love it when a plan comes together!
The problem is not in the cuts or the merging, it appears after re-encoding the cuts and merging them.
1) If I cut with avidemux and merge with mkvtoolnix - no problem
2) If I re-encode after cutting and then merge - the problem appears
If I extract the mka from the created mkv, there is no problem with its sound - there is no stutter. The stutter appears when combined with the video, because the video receives jitter on transition after the re-encoding.
Hi, english is not my native language so i might have some problems understanding/replying, if you have no problems with step 1 why not stop right there, why are you trying step number 2? what is your end goal? are you "clean keyframe" cutting in setp 1 and in step 2 you're "fine tuning" your edits for the final video? Sorry for any trouble understanding your problem.I love it when a plan comes together!
I wrote above I am cropping thus re-encoding and going to step 2). If it's not clean keyframe cut step 1) will fail.
Actually the keyframe (I-FRM) is only the start [A]. The end one [B] is a P-FRM.
1. Video and audio frames usually have different lengths. It's unlikely they align 100% on your cut points.
2. Certain audio formats have things like encoder delay/pre-roll and padding. This makes it difficult to cut and re-append audio without glitches depending on the format.
3. mkvmerge has 2 different append modes (see mkvmerge doc about --append-mode option). With the non-default append-mode and manually setting fps in mkvmerge you may receive more "clean" timecodes (at the expense of av sync in some cases)
4. I'm not sure avidemux can cut all Blu-Rays correctly. I expect problems with open GOPs.
I don't know why you split, re-encode and then later re-append. I would not re-recommend this.
I split, because I want different crops, not a single crop. I tested different audio formats with no success.
Same resolution, different crops - for example scene A crop 100 pixels from top, scene B 100 from bottom.
I can't use the source audio since the final video length is different (10s larger) due to the re-encoding and jitter on transition.
Okay, I found the problem - it was a container issue.
I managed to cheat it with demuxing with tsMuxer and then merging again with mkvtoolnix. The file ended up with the intended length (no extra 10s) and there aren't any video/audio stutters, but the synchronization is not 100% accurate this time (there is some +/- ms noticeable only at certain times when characters are speaking). This is better than previous version however.
If I manage to fix this too somehow, I'll update the thread. Anyone with a theoretical knowledge why this happens?
Yes. It's not a container issue per se. Like I said mkvmerge has 2 different append modes. The non-default one will probably get you a similar result as your TS experiment (manually setting fps in mkvmerge can also "clean" the timecodes). But like I also predicted with the same AV issues.
You could do the trimming and the cropping in a single step with a relatively simple Avisynth script, as suggested above. Then do the encode with MeGUI or ffmpeg (Handbrake doesn't accept an Avisynth script as source). If you never used it, provide more information about the format of the source video and how you want to crop it, so someone can help you design a template script.
The A/V synchronization issue came from first part which had some strange start, so I just cut some frames from it, re-merged and now all is fine.
The whole process was:
1) Cut all parts with avidemux
2) Custom crop each and encode with handbrake
3) Merge with mkvtoolnix, demux with tsmuxer and merge again with mkvtoolnix
Quick 'n' dirty example :
video = FFVideoSource("X:\path\to\the\source video\Name of the file.mp4") # requires the ffms2.dll source plugin (other source plugins can be used depending on the format of the source) audio = FFAudioSource("X:\path\to\the\source video\Name of the file.mp4") source = AudioDub(video,audio) chunk1 = source.Trim(0,10500).Crop(0,20,0,-10).AddBorders(0,14,0,16) chunk2 = source.Trim(15800,20300).Crop(0,8,0,-12).AddBorders(0,10,0,10) chunk1 ++ chunk2 # for this to work the resolutions have to match, so the net result of the cropping + adding of borders should be the same for each chunk
"X:\path\to\ffmpeg\ffmpeg.exe" -i "X:\path\to\the\script\Name of the file.avs" -c:v libx264 -crf 20 -preset slower -c:a aac "Name of the file [trimmed, cropped].mkv"
Last edited by abolibibelot; 14th Jan 2020 at 17:41.
Avisynth based GUI rather than Handbrake. In case you do, I'll shamelessly plug my CropResize script so you don't have to worry about calculating the correct cropping to prevent distorting the picture if you resize.
I'd recommend MeGUI, as it's Script Creator adds the standard stuff to a script for you (so you don't need to know anything about AVisynth), but it also makes it easy to modify the script manually.
After you open a source with MeGUI's Script Creator, if you don't use it to crop or resize etc, the script MeGUI creates will look something like the first screenshot. For the second, I added 3 lots of Trim and CropResize, to crop frames 5474 to 11632 differently from the rest. The Script Creator has a video preview and it displays the current frame number at the top. When you've added the cropping you can encode the video in one go, no splitting beforehand necessary.
The video should be exactly the same duration after encoding, even if you split the source video first, so I don't know what's happening there.
10 seconds is quite a bit to be out.
Have a look at the source file with MediaInfo to see if it reports an audio delay.
MeGUI has a HD Streams Extractor under the Tools menu. It extracts with eac3to, and it adds silence to account for any delay when extracting.
avisynth, or any video editor that decompresses the file)
Because the "cutting" is done in the uncompressed domain . The file is already "decoded" before cutting. There are no "keyframes" in that state; or another way to look at it is every frame is a "keyframe" now, so you can cut anywhere
Since you are re-encoding the whole file anyway, that's the "better" way to do it since you can cut anywhere. And you are less likely to have join issues or glitches. Also, it's faster than manually cutting physical files and encoding each, then appending each. You can do it all in 1 go with 1 script
avisynth requires scripts, it's a script language of sorts . There are semi- GUI's for it like avspmod, but you still have to write scripts; it's more of a previewing mechanism. But you can see how your "edit" is working and so forth. You can see how much to crop or resize etc... and adjust
Or you can try some free,open source NLE's like shotcut .
But I would recommend learning avisynth basics when you have time - it's very useful for many types of A/V manipulations