Avidemux Forum

Avidemux => Main version 2.6 => Topic started by: phaolo on June 16, 2021, 12:48:38 AM

Title: Avidemux 2.7.8 - problem with cutting outside keyframes
Post by: phaolo on June 16, 2021, 12:48:38 AM
Sometimes I need to cut ouside keyframes. To avoid re-encoding the full video, I losslessly cut as much as possible and encode just a small segment (with as similar settings as possible).
The problem is that this trick often fails (I get a garbled image after the cut, till a keyframe) and I don't know why exactly.

For example:

S=video start
E=video end
k=keyframe
|=cut


S------------------------k---|------k-------|---k----E

part1 = lossless
part2 = removed
part3 = encoded

When I rejoin p1 & p3 I'd expect them to be fixed like:
S------------------------k---K---k----E

Doesn't it work like this?
Title: Re: Avidemux 2.7.8 - problem with cutting outside keyframes
Post by: eumagga0x2a on June 16, 2021, 09:25:54 PM
Quote from: phaolo on June 16, 2021, 12:48:38 AMwith as similar settings as possible

Being close is not enough. The codec extradata from both videos must match perfectly (bit-perfectly).
Title: Re: Avidemux 2.7.8 - problem with cutting outside keyframes
Post by: phaolo on June 17, 2021, 06:06:46 AM
Quote from: eumagga0x2a on June 16, 2021, 09:25:54 PM
Quote from: phaolo on June 16, 2021, 12:48:38 AMwith as similar settings as possible

Being close is not enough. The codec extradata from both videos must match perfectly (bit-perfectly).
Err.. what is a codec extradata?
I used the same video codec, encoding method (e.g:CRF), frame size, framerate, audio codec and kHz. What more is needed?
Title: Re: Avidemux 2.7.8 - problem with cutting outside keyframes
Post by: butterw on June 17, 2021, 10:29:46 AM
Look for the line Encoding settings in MediaInfo Video properties, most x264/x265 encoded files will have it.
Title: Re: Avidemux 2.7.8 - problem with cutting outside keyframes
Post by: phaolo on June 17, 2021, 12:13:04 PM
Quote from: butterw on June 17, 2021, 10:29:46 AMLook for the line Encoding settings in MediaInfo Video properties, most x264/x265 encoded files will have it.
Oof.. I don't know how to replicate all that.
Could I pass such parameters to Avidemux?
Title: Re: Avidemux 2.7.8 - problem with cutting outside keyframes
Post by: butterw on June 17, 2021, 12:26:15 PM
If you didn't encode the original video yourself or used custom settings: it may prove difficult.
Title: Re: Avidemux 2.7.8 - problem with cutting outside keyframes
Post by: eumagga0x2a on June 17, 2021, 04:48:53 PM
Quote from: phaolo on June 17, 2021, 06:06:46 AMErr.. what is a codec extradata?

If your source video with a H.264 or HEVC video track is a MP4/MOV or MKV, load it in Avidemux, open Avidemux log and search for the lines following "The video codec has some extradata". This binary structure, represented as hex, must be identical for all merged videos.

This is more difficult to assess in MPEG-TS streams as they by design need to handle codec parameters switching on the fly and extradata is prepended to each keyframe.