Log in

View Full Version : How can I cut a video accurately from a frame to antoher frame


wthreex
12th October 2018, 12:02
I use Avidemux to cut video stuff, but I have recently realized that it doesn 't work properly, because it doesn't cut closely from the frame to frame that I choose, and most of the time it gives me 1-2 seconds behind what I wanted (it depends of picture type? B Frame or P Frame?)

So, What would you recommend for this stuff? Avisynth can handle it ? remember i want something that cut frames exaclty what i want

thanks.

manolito
12th October 2018, 14:15
I guess you know the concept of "intra" frames and "non-intra" frames in video encoding. Only I-frames can be decoded all for themselves, all other frames have references to neighboring frames. To decode them you will need to decode the whole GOP.

This means that encoded video can only be cut at I-Frame borders if you do not want to reencode at least partly.

If you need to reencode the whole video anyways then AviSynth is the way to go. AviSynth decodes the whole movie frame by frame, then applies filtering and finally serves it frame by frame to the encoder. This makes it easy to cut the video with frame accuracy. (StaxRip or any video encoding application which uses AviSynth can do this).

Then there is a technique called "Smart Rendering" which you can find in many NLE software. For frame accurate cutting only the relevant GOPs will be completely reencoded. If your video is MPEG2 then Cuttermaran is a capable and free tool for this task.

A special case is video which only consists of I-Frames. The old Mini-DV video cameras use the DV video format which only has I-Frames. This video format has its drawbacks, but it is very editing fiendly. It can be cut at any frame without problems.


Cheers
manolito

wthreex
12th October 2018, 15:26
Oh I see, i didnt really know about I-Frames, So there's no other way than encoding?

WorBry
12th October 2018, 15:37
I use Pegasys (TMPGenc) SmartRenderer 5 for cutting down native HD-AVC.mp4 footage from camcorders/cameras:

http://tmpgenc.pegasys-inc.com/en/product/tmsr5.html

If the cuts are made at 'GOP level' (i.e. on the key frames) there is no re-encoding. If cuts are made at 'frame level' there is, necessarily, re-encoding of some GOP's around the cuts/re-splice points, because of the 'Open GOP' structure. Specifically, if you cut frames from the beginning of a clip it will always re-encode the GOP that the cut falls in and the following two GOP's. If frames are trimmed from the end of a clip it will only re-encode the affected GOP. So, if you were to trim and join two clips in that way, it will re-encode four GOP's around the splice point. Same if you excise segments from the middle of a clip.

AVCHD.mts clips behave a little differently (don't they always)- when cuts are made at the key frame level, sometimes there is re-encoding around the cut/splice points, other times not. The GOP reconstruction pattern (four re-encoded GOP's) is the same though.

It is 'frame accurate', the re-encoded frames are highly quality (uses x264) and I've had no issues with skips, stutters or black frames at the splice points or out of sync audio. Other so called 'smart cutters' I tested at the time (this was a few years back) were susceptible to aberrations like that and/or the re-encoded frames were sub-par quality.

I also used it at one point for cut-editing MPEG-2 (HDV) material, but can't quite recall the pattern of GOP reconstruction at the 'frame' and 'key-frame' cut level. Again, it was high quality though.

Well worth the money if you do a lot of video editing.

videoh
12th October 2018, 17:46
I use Pegasys (TMPGenc) SmartRenderer 5 for cutting down native HD-AVC.mp4 footage from camcorders/cameras:

http://tmpgenc.pegasys-inc.com/en/product/tmsr5.html Wow, that looks like awesome capability for a very reasonable price. Thanks for pointing it out.

manolito
12th October 2018, 20:18
I agree, for this price it has remarkable features (like HEVC support).

You will have a hard time finding any free video editors with Smart Rendering. For MPEG2 video the exception is Cuttermaran, for AVC video in an MKV container there is the free software MKV Cutter by Selur.

You can find it at VideoHelp, the author's site is here:
https://forum.selur.net/showthread.php?tid=6

It is still alpha, the author does not work on it very often. The GUI needs some time to get used to, there are other rough edges, but so far I got very nice results from it. Can't hurt to give it a try...


Cheers
manolito

WorBry
14th October 2018, 21:16
I agree, for this price it has remarkable features (like HEVC support).


Haven't really examined the HEVC support, except to know that it will 'smart render' (rather sluggishly) Main10@L5@High files, but not Main10@L5.1@High mp4, such as recorded on a Panasonic GH5. Mind you, SmartRender (version) 5 is some years old now.

Whats important to me (for cut editing HD-AVC that is) is that it's easy to use, reliable and the smart rendered outputs are standards compliant - Pegasys (TMPGenc) have always been strict on compliance - so you won't have any problem importing the files into proprietary NLE's. I use DaVinci Resolve, which can be rather picky, and it imports the 'frame level' smart-rendered HD-AVC.mp4 files just fine.

manolito
14th October 2018, 22:48
Have you checked out the output of MKV Cutter? Of course it only works for AVC sources, but it uses X264 for reencoding the necessary GOPs, the result should be compliant.

And since I use this feature only on rare occasions (I mostly reencode the whole source), the difference in price does matter... (70$ vs. free)

//EDIT//
The last version of MKV Cutter has a bug. The file FFMS2.avsi in its main folder tries to load a C-Plugin version of ffms2.dll. But the ffms2 version in the archive is a standard C++ plugin. You need to edit FFMS2.avsi and in the third line remove the "C" from the LoadCPlugin call.

WorBry
15th October 2018, 01:48
I was actually in the process of testing it with an HD-AVC.mp4 (converted to mkv) clip and had already produced a whole series of 'cut-edited' exports that tested precise 'key frame' and 'frame' level cuts/excisions. I was just about to test and analyze the export files when I saw your EDIT. So you're telling me that I'll need to edit the FFMS2.avsi and repeat the tests ? :(

manolito
15th October 2018, 01:51
No, if the conversion went without errors then you are fine. The problem with the ffms2.avsi only occurs if you have a different ffms2 version in your "AviSynth\Plugins" folder.

WorBry
15th October 2018, 02:05
I don't have any ffms2.dll in my AviSynth\Plugins folder. Actually I'm using AVISynth+ and always load ffms2 from a separate directory folder anyway. Anyhow, the conversions seemed to complete OK. I'll come back on my findings when I've examined the export files in full - I created quite a few.

Edit: Not a good start - frame rate of the HD-AVC.mp4 source clip and converted mkv clip is 59.94 FPS (60000/1001). All of the MKVCutter exports are reported as 58.824 FPS (7353/125). And the frame counts of the export files do not tally with the number of frames marked for excision on the MKVCutter timeline, irrespective of whether the marked Start/End frames are intended to be cut or retained. Can't be bothered trying to figure out where the additional frame deletions are occurring, especially with the frame rate difference. I was happy to give it a shot, but no point in further testing as far as I'm concerned.

There's a reason why SmartRenderer 5 re-encodes three GOP's after a frame-level cut, to re-establish proper rate control. I'm skeptical about any software that claims seamless frame-accurate cut-editing of native HD-AVC with reconstruction of only the affected GOP.

Just one point I should mention about Smartrenderer 5:


If the cuts are made at 'GOP level' (i.e. on the key frames) there is no re-encoding.

Although there is no re-encoding of the video stream per se, if the source audio is AAC there is some re-encoding of the audio around the cut-splice points. For that reason I usually export the audio stream converted to PCM (WAV), especially if I plan to process the output (as a single joined file or individual split segments) in another application, like Resolve, or maybe process just the audio (normalization etc) externally.

The particular HD-AVC.mp4 clip I used in the MKVCutter tests had PCM audio.

manolito
17th October 2018, 04:31
I never saw MKV Cutter change the video frame rate, but it does have a problem keeping audio in sync. It does not matter if the audio is AAC or PCM, after more than about 5 cuts the audio desync becomes more and more noticeable.

But I did find another video cutting software which has no problems with audio sync. It is called "VidCutter", it does have Smart Rendering, and it is free.

http://i65.tinypic.com/rtqamu.png

The latest version is 6.0, it comes in 32-bit and 64-bit flavors. I tried both, I did not see any difference in speed.

The software uses FFmpeg, and this is probably the reason for the one problem I found. It does not play nicely with MKV sources here. The resulting file has horizontal motion judder when the source had smooth movement. Analyzing the result showed that the file is now 25 fps VFR instead of CFR, and it has non-monotonous timestamps.

What solved the issue for me was to only use MP4 files as the source. Remuxing MKV to MP4 and vice versa is just a matter of seconds with FFmpeg...


Cheers
manolito