Reencode part of a video with same parameters as original one

Started by FlorentA, August 05, 2021, 09:37:31 AM

Previous topic - Next topic

FlorentA

Hi everyone.

I would like to remove ads from within a show I have recorded with VLC. But as my PC is old and slow (1 min of video requires about 5 min to be reencode in h264 at same resolution) I would like not to reencode the whole file.

But the copy mode is available only when cuts are made on key frames.

As you guess, ads never gently start and stop at key frames, so I have to reencode the whole file.

So I tried to cut and reencode a small part around the start and stop of ads in order to get a clip starting with a key frame.

But I get an error message saying the clips don't have the same codec setup, so video reader should fail to read it. Precisely:
QuoteCodec or codec settings across a cut point do not match. Playback of the video saved in copy mode may stop at this point.
Do you want to continue anyway?

This is true, the tiny set of codec parameters I can get shows the fps has change from 50 to 25 (why!?) as well as the pixel ratio. I managed to fix the latter. The former is still changed to 25 even if I use the Change the I/S rate filter to set to 50 or 49.998 but change with the Resample I/S rate filter. However, I get the same final error even if I set the rate to 50 or 49.99 (impossible to set the third digit).

 So, how can I get all the parameters from the original video and copy a clip between any frames with the exact same settings as the original codec, or how can I remove a part between no keyframe frames without reencoding the whole video?

Thanks.

Here are the original settings I can get
Quote=====================================================
Video
=====================================================
Codec 4CC:      H264
Image Size:      720 x 576
Aspect Ratio:      Unknown (16:11)
Frame Rate:      49,997 fps

Total Duration:      00:31:10.842

=====================================================
Extra Video Properties
=====================================================
ExtraDataSize:      07
Extra data:      01 4D 40 1E FF E0 00 frame

=====================================================
Audio (1 piste activée)
=====================================================
Codec:         AAC
Channels:      Stéréo
Bitrate:      7838 Bps / 62 kbps
Frequency:      48000 Hz
Total Duration:      00:31:17.212

and the final I get with the MPEG AVC (x264) codec and the resample I/S filter on Avidemux 2.7.8 on Linux Mint
Quote=====================================================
Video
=====================================================
Codec 4CC:      H264
Image Size:      720 x 576
Aspect Ratio:      Unknown (16:11)
Frame Rate:      49.990 fps

Total Duration:      00:00:04.641

=====================================================
Extra Video Properties
=====================================================
ExtraDataSize:      41
Extra data:      01 64 00 1F FF E1 00 18 67 64

=====================================================
Audio (1 piste activée)
=====================================================
Codec:         AAC
Channels:      Stéréo
Bitrate:      7871 Bps / 62 kbps
Frequency:      48000 Hz
Total Duration:      00:00:04.610

In addition, Avidemux cannot find any keyframe in the exported clip while it finds several at the same position of the original file

 

eumagga0x2a

When appending videos, codec and codec parameters (i.e. extradata) must match perfectly, this means that as long you have

Quote from: FlorentA on August 05, 2021, 09:37:31 AMExtraDataSize:      07
Extra data:      01 4D 40 1E FF E0 00

vs

Quote from: FlorentA on August 05, 2021, 09:37:31 AMExtraDataSize:      41
Extra data:      01 64 00 1F FF E1 00 18 67 64

(the remainder past the first 10 bytes was dropped until very recently) you absolutely cannot merge these videos in copy mode.

Now for the source video. The resolution 720x576 is the usual PAL DVD standard definition resolution with overscan (704x576 with 8 pixel margin left and right) and 16:11 the standard pixel aspect ratio for widescreen (16:9) display, meaning that the origin of the source was probably MPEG-2, not H.264. As you mentioned 50 vs 25 frame rate, I suspect that the origin of the source was field-encoded interlaced MPEG-2 (field rate: 50 fields/s) which translates to 25 full pictures per second.

Average framerate slightly below the standard value is an artifact of cuts in copy mode in open-GOP type H.264 streams with B-frames in Avidemux, because we drop so-called early B-frames not used for reference, resulting in small gaps in DTS (not in PTS!) right after each cut point.

In any case, please update to the latest Avidemux nightly (on Linux you can build your own from the latest git master especially easily, else please resort to those from appImage4Buster directory for Linux distributions with GLIBC library 2.28 or later or to builds in appImage4 for very old distributions) to see more of the extradata in the properties dialog, let alone numerous fixes and enhancements since 2.7.8, but I strongly doubt that you will be able to reproduce the extradata of the source with x264 configuration in Avidemux.

Nevertheless, the textual output of

mediainfo /path/to/video
and the console output of Avidemux from loading each of the videos would provide a fuller picture.

Quote from: FlorentA on August 05, 2021, 09:37:31 AMThe former is still changed to 25 even if I use the Change the I/S rate filter to set to 50 or 49.998

You should almost never ever use not-predefined standard values in the both "Resample Fps" and "Change Fps" filters (and you definitely don't want to change the duration by using "Change Fps", losing A/V sync). I am sure you don't need to touch frame rate at all.