Avidemux Forum

Avidemux => Windows => Topic started by: jraju on January 14, 2021, 10:46:49 AM

Title: can i add a small external video in to the middle of existing video by avidemux
Post by: jraju on January 14, 2021, 10:46:49 AM
Hi, i know how to copy part of video by markers a and b end point and copy and paste the same to the desired point in the video.
can i do the same, with external small video file at the reqired point in timeline
If i choose append, then it adds to the end of the file.
could you give ideas how to do it
Title: Re: can i add a small external video in to the middle of existing video by avidemux
Post by: eumagga0x2a on January 14, 2021, 11:35:45 AM
Append first, set markers accordingly to select the appended video, then use cut and paste (Ctrl+X followed by Ctrl+V at desired point in timeline) instead of copy and paste (Ctrl+C && Ctrl+V).

If you need to be able to paste independently from the frame type and internal structure of the video stream, set video encoder to a real encoder instead of "copy".
Title: Re: can i add a small external video in to the middle of existing video by avidemux
Post by: butterw on January 14, 2021, 11:49:50 AM
Quote from: jraju on January 14, 2021, 10:46:49 AMcan i do the same, with external small video file at the reqired point in timeline
If i choose append, then it adds to the end of the file.
In Avidemux appends are always at the end.
Title: Re: can i add a small external video in to the middle of existing video by avidemux
Post by: butterw on January 14, 2021, 01:38:22 PM
No file Insert feature is currently available and it's not ideal.
No marker is set by the append, you need to find the beginning keyframe of the segment.
Then after you cut, you also need to delete the first frame of the cut section, (not currently deleted by default when you cut to the end).

Title: Re: can i add a small external video in to the middle of existing video by avidemux
Post by: Who on January 14, 2021, 11:51:11 PM
The feature I'd really like is the option to replace a portion of video only with an equal length section, probably using a filter, without touching the existing audio track in any way.  So you would specify the starting point for the replacement (using the time stamp) and it would replace the existing video with the video from the alternate file starting at that point and continuing until it runs out of frames and then switch back to the original video (alternately perhaps a length to replace could also be specified).

I asked about this once before and a really kludgey way to do it was suggested, but when I tried that it threw the audio slightly out of sync with the video for the entire file.  So if they ever do add an insert feature as suggested here I hope that there will be an option to insert OR overwrite, and that you can specify to insert just the video, just the audio, or both from the alternate file.  I do realize that both files would have to be in exactly the same format for this to work but then that is also true with an append operation.

In the meantime you could concatenate files using ffmpeg; in the list of files to concatenate you'd have the main file, then your insert, then the main file again.  ffmpeg can concatenate these losslessly if you use the -c copy option, and then you can bring the full file into Avidemux and trim out the parts you don't want and do any other editing you need to do.  It is kind of a pain in the butt to do it that way, especially since ffmpeg doesn't have a super simple method to concatenate files, but it is a way to get the job done.
Title: Re: can i add a small external video in to the middle of existing video by avidemux
Post by: eumagga0x2a on January 15, 2021, 01:13:57 AM
Quote from: butterw on January 14, 2021, 01:38:22 PMNo marker is set by the append, you need to find the beginning keyframe of the segment.

Solution: seek to the end of the video prior to appending the next one, then go to the next frame. Reset markers if necessary, then set the A marker to the current position.

Quote from: butterw on January 14, 2021, 01:38:22 PMThen after you cut, you also need to delete the first frame of the cut section, (not currently deleted by default when you cut to the end).

The idea is to avoid visual disruption for the user as she or he will have probably exactly this first frame of the appended video loaded in the video preview when cutting. If no more videos need to be appended, then there is no need to delete that solitary frame, it should be enough to place the B marker at an earlier frame before saving.
Title: Re: can i add a small external video in to the middle of existing video by avidemux
Post by: eumagga0x2a on January 15, 2021, 01:32:45 AM
Quote from: Who on January 14, 2021, 11:51:11 PMIn the meantime you could concatenate files using ffmpeg; in the list of files to concatenate you'd have the main file, then your insert, then the main file again.  ffmpeg can concatenate these losslessly if you use the -c copy option, and then you can bring the full file into Avidemux and trim out the parts you don't want and do any other editing you need to do.

Why easy when it can be complicated?

Quote from: Who on January 14, 2021, 11:51:11 PMI asked about this once before and a really kludgey way to do it was suggested, but when I tried that it threw the audio slightly out of sync with the video for the entire file.

Could you please point me to that topic? I guess this operation required extracting and importing the original audio track after replacing a part of the video. A constant A/V offset is easy to correct, but a situation where the start is in good sync but the part after the insert is not would be very difficult to handle.
Title: Re: can i add a small external video in to the middle of existing video by avidemux
Post by: jraju on January 15, 2021, 08:34:04 AM
Hi, if a length of a video is more than an hour, either you have to close the video viewing or open the video again and use the forward button to the required place to view the screen once again.
So, what i want is a kind of break after one hour, by way of , adding the title song frame for a few minutes, so that i Just close the video and again go to the required portion to see the next time.
When A and B are available in the existing video, to move or copy to any location of the video,
I want repetiion of the same A and B segment , alreadly saved from the same video having the same features in the particular time on the timeline
Is this not possible  with the latest available version. To make it clear, I want the same title song to be copied in al the sequence of files at the desired point in timelilne
I think the solution is not yet given for me
Title: Re: can i add a small external video in to the middle of existing video by avidemux
Post by: butterw on January 15, 2021, 01:12:19 PM
Quote from: eumagga0x2a on January 15, 2021, 01:13:57 AM
Quote from: butterw on January 14, 2021, 01:38:22 PMNo marker is set by the append, you need to find the beginning keyframe of the segment.

Solution: seek to the end of the video prior to appending the next one, then go to the next frame. Reset markers if necessary, then set the A marker to the current position.

This sequence of operations is quite easy easy to get wrong on first attempt (or if you repeat it many times).
Avidemux should be have a command to do it automatically. 

Easy Lossless insert:
- Position yourself on a keyframe
- Select Insert command >> choose the clip to be inserted in a file open dialog
- Avidemux inserts the clip before the keyframe (warns of possible issues if applicable).
 

Quote from: eumagga0x2a
Quote from: butterw on January 14, 2021, 01:38:22 PMThen after you cut, you also need to delete the first frame of the cut section, (not currently deleted by default when you cut to the end).

The idea is to avoid visual disruption for the user as she or he will have probably exactly this first frame of the appended video loaded in the video preview when cutting. If no more videos need to be appended, then there is no need to delete that solitary frame, it should be enough to place the B marker at an earlier frame before saving.

When I cut or delete something, I don't expect it to be still there. It also inconsistent with the behavior of cut/delete when not performed at the end (in this case, the displayed frame is deleted and it goes to the next frame).
https://avidemux.org/smif/index.php?msg=90671

If there wasn't this orphaned keyframe to contend with, maybe an Insert command would not be needed.


Title: Re: can i add a small external video in to the middle of existing video by avidemux
Post by: jraju on January 15, 2021, 02:00:22 PM
your quote Hi, butterw
Select Insert command >> choose the clip to be inserted in a file open dialog
- Avidemux inserts the clip before the keyframe (warns of possible issues if applicable).
Is that command available in avidemux now in the latest edition
i tried to locate but could not find it.
hi, why i am not receiving the answers in my email gmail
Title: Re: can i add a small external video in to the middle of existing video by avidemux
Post by: butterw on January 15, 2021, 02:26:36 PM
Easy Lossless insert: isn't currently available in Avidemux

the sequence of operations suggested by eumagga0x2a works, but is probably a bit hard to accomplish for a first time user:
https://avidemux.org/smif/index.php?msg=90704
Title: Re: can i add a small external video in to the middle of existing video by avidemux
Post by: Who on January 15, 2021, 11:40:50 PM
Quote from: eumagga0x2a on January 15, 2021, 01:32:45 AM
Quote from: Who on January 14, 2021, 11:51:11 PMI asked about this once before and a really kludgey way to do it was suggested, but when I tried that it threw the audio slightly out of sync with the video for the entire file.

Could you please point me to that topic? I guess this operation required extracting and importing the original audio track after replacing a part of the video. A constant A/V offset is easy to correct, but a situation where the start is in good sync but the part after the insert is not would be very difficult to handle.

https://avidemux.org/smif/index.php?msg=89791

And you are correct, the thing that is problematic is this:

Quote from: eumagga0x2a on September 20, 2020, 08:41:29 PMIf the other video has a matching audio track which you can use, the operation degrades to a straightforward copy and paste task, else the next step is to export ("Audio" --> "Save Audio") the audio track to a file.

...

Quote from: eumagga0x2a on September 20, 2020, 08:41:29 PMAdd an external audio track ("Audio" --> "Select Track" --> ".... Add audio track" for Track 1) if you can't use audio from video 2 for the duration of the patch.

You would THINK that would work but I have found that even if the edits are all near the end of the video, when you bring the audio back it is off a little right from the start; you particularly notice it when people are speaking.  And if I knew exactly how much it was off I could correct it using the audio Shift field, but I don't, and I detest the idea of trial-by-error or just guessing to get a good shift value.  I am kind of a perfectionist, and "close enough" isn't good enough for me.
Title: Re: can i add a small external video in to the middle of existing video by avidemux
Post by: eumagga0x2a on January 16, 2021, 12:24:10 AM
Quote from: eumagga0x2a on January 15, 2021, 01:13:57 AM
Quote from: butterwThen after you cut, you also need to delete the first frame of the cut section, (not currently deleted by default when you cut to the end).

The idea is to avoid visual disruption for the user as she or he will have probably exactly this first frame of the appended video loaded in the video preview when cutting.

I've modified the behaviour of truncateVideo() to match removeChunk() with regard to the start of selection i.e. to delete the frame at the A marker. If the start of selection matches the first frame of an appended video, the whole segment is deleted.

This brings back the UX problem of loss of current visual context, slightly mitigated as Avidemux now tries to jump to the previous keyframe instead of rewinding to the start of video.
Title: Re: can i add a small external video in to the middle of existing video by avidemux
Post by: eumagga0x2a on January 16, 2021, 12:30:36 AM
Quote from: Who on January 15, 2021, 11:40:50 PMAnd if I knew exactly how much it was off I could correct it using the audio Shift field, but I don't, and I detest the idea of trial-by-error

Are you aware of audio shift working in preview? It is not that you need to save video each time you modify the value. Of course, one needs to put some effort into finding the right sync, but this takes usually just a couple of minutes.

By the way, I think some issues with external audio causing loss of sync were fixed recently, e.g. for AC3 (https://github.com/mean00/avidemux2/commit/cfb089b84ab08e1b163652386c7c62abdd8e6d70).
Title: Re: can i add a small external video in to the middle of existing video by avidemux
Post by: butterw on January 16, 2021, 12:31:48 AM
Switching between multiple video and audio tracks is a feature only available in full video editors.

It should also be possible with an Avisynth script though, which can be loaded with Avidemux or Virtualdub.
Title: Re: can i add a small external video in to the middle of existing video by avidemux
Post by: butterw on January 16, 2021, 01:03:58 AM
Quote from: eumagga0x2a on January 16, 2021, 12:24:10 AM
Quote from: eumagga0x2a on January 15, 2021, 01:13:57 AM
Quote from: butterwThen after you cut, you also need to delete the first frame of the cut section, (not currently deleted by default when you cut to the end).

The idea is to avoid visual disruption for the user as she or he will have probably exactly this first frame of the appended video loaded in the video preview when cutting.

I've modified the behaviour of truncateVideo() to match removeChunk() with regard to the start of selection i.e. to delete the frame at the A marker. If the start of selection matches the first frame of an appended video, the whole segment is deleted.

This brings back the UX problem of loss of current visual context, slightly mitigated as Avidemux now tries to jump to the previous keyframe instead of rewinding to the start of video.

Losing visual context might be a thing, but at least the user knows what has just been deleted.
Moving the view to the frame just before the segment to be deleted (now the last frame of the video) seems like the most logical step (this is also the frame you need to be on currently to delete to the End).
Title: Re: can i add a small external video in to the middle of existing video by avidemux
Post by: Who on January 16, 2021, 12:29:36 PM
Quote from: eumagga0x2a on January 16, 2021, 12:30:36 AM
Quote from: Who on January 15, 2021, 11:40:50 PMAnd if I knew exactly how much it was off I could correct it using the audio Shift field, but I don't, and I detest the idea of trial-by-error

Are you aware of audio shift working in preview? It is not that you need to save video each time you modify the value. Of course, one needs to put some effort into finding the right sync, but this takes usually just a couple of minutes.

I have read that over several times, and either I am still not understanding it or you totally ignored what I said about not wanting to use a trial-and-error method.  First, you ask "Are you aware of audio shift working in preview?"  But I am not talking about the audio being off in preview, I am talking about it being off in the saved file.  You then say "It is not that you need to save video each time you modify the value."  The only thing I can deduce from that is you are saying to try different values and watch in preview to see when it looks right, if so that is totally abhorrent to me, I would NEVER EVER IN A MILLION YEARS try to do sync using just my eyes and ears, because that is not at all precise!  Then you say "Of course, one needs to put some effort into finding the right sync, but this takes usually just a couple of minutes" which again leads me to suspect you totally ignored what I said and are suggesting I just try various values until I hit one that "looks" right.

Here is the thing, if I start with a video that has audio that is in sync with the video, and somewhere during the editing process it loses that synchronization, then the resulting file and maybe the original file is toxic waste as far as I am concerned!  NORMALLY Avidemux is really good about keeping the audio in sync, even after multiple edits. It is only if I try to save the audio to a separate file and then bring it back where it doesn't precisely sync up with the video, and that is true even near the start if you only made edits near the end.  And no I am not going to try various random shift settings to see what "looks good", if that is what you are actually suggesting, that is NOT the correct way to sync up audio with video!  To me that's like if I needed to get some paint to repair a damaged section of wall and I went to the paint store and tried to pick a color based on my memory of what color the wall is.  Even if somehow I managed to get close, it would never be a precise match, and it would always really bother me that it isn't precise.

Also, I have seen occasional situations where the audio looks VERY out of sync in the preview mode (off by even a second or two) but still is perfectly synced in the saved file (obviously these are cases where I did not try to save the audio to a separate file and then bring it back).  My suspicion in those cases are that the files are some high-bandwidth variety and it is my hardware that can't quite keep up but in any case that's just another reason I would never attempt to sync audio and video based on what I see in a preview.  If I am in doubt, I always do a test encode of a few seconds of the video and watch that in an external player such as VLC.

Quote from: eumagga0x2a on January 16, 2021, 12:30:36 AMBy the way, I think some issues with external audio causing loss of sync were fixed recently, e.g. for AC3 (https://github.com/mean00/avidemux2/commit/cfb089b84ab08e1b163652386c7c62abdd8e6d70).

That may be the issue then; several of the files I have attempted to edit have been encoded with AC3 audio.  So if it was fixed recently that means I have to wait for the next release version that will work in MacOS (Catalina).  Thanks for fixing that!

I guess what I am wondering is whether it would really be this hard to add the ability to replace a number of frames of video with frames from a different video.  You can replace single frames or a series of frames with a static image that replaces the entire frame(s) or a portion thereof, and this would simply be replacing a series of frames with a different series of frames taken from another video instead of a single static image.  I am not a programmer so I have no idea what would be involved, but when I see some of the amazing filters that already exist in Avidemux, this seems to me like something that really shouldn't be that difficult, and the main thing is that it would not involve saving and reloading the audio so that there would be no chance at all of introducing audio/video sync issues.  It would also be a lot easier method of replacing a section of video than what you suggested in that other thread, but maybe that's kind of beside the point if programming such a feature would take up far too much time.  What I REALLY care about is preserving the ORIGINAL audio/video sync in the part of the video that has no been changed, not trying to guess what it should be afterwards.  Anyway, I'm not going to beat a dead horse here if you have really decided this can't be done or if it would take far too much time and effort, I'll just say that if you ever do think of a way to add something like that it would really be appreciated, and I suspect not just by me.
Title: Re: can i add a small external video in to the middle of existing video by avidemux
Post by: eumagga0x2a on January 16, 2021, 01:12:26 PM
Quote from: butterw on January 16, 2021, 01:03:58 AMMoving the view to the frame just before the segment to be deleted (now the last frame of the video) seems like the most logical step

Sure, but not viable as the seek to a frame which is likely located at the end of a GOP may take a lot of time depending on codec, GOP length, video resolution and hardware capabilities.
Title: Re: can i add a small external video in to the middle of existing video by avidemux
Post by: eumagga0x2a on January 16, 2021, 02:19:40 PM
Quote from: Who on January 16, 2021, 12:29:36 PMBut I am not talking about the audio being off in preview

I didn't mean that.

Quote from: Who on January 16, 2021, 12:29:36 PMYou then say "It is not that you need to save video each time you modify the value."  The only thing I can deduce from that is you are saying to try different values and watch in preview to see when it looks right,

Exactly, the step I never leave out. On my system, achieving a good sync in Avidemux during preview results in a good sync after saving when played in video players or on external devices.

Quote from: Who on January 16, 2021, 12:29:36 PMI would NEVER EVER IN A MILLION YEARS try to do sync using just my eyes and ears, because that is not at all precise!

It is actually quite the opposite, eyes and ears are ultimately the only valid reference. But I understand that once audio is more that just a half a second off, it becomes almost impossible to sync from lips or from hand movements (e.g. of a musician) without clear visual references like a clap.

Quote from: Who on January 16, 2021, 12:29:36 PMIt is only if I try to save the audio to a separate file and then bring it back where it doesn't precisely sync up with the video

This is correct and a big fundmental problem. In a raw audio stream, there is no other source of timing than counting audio samples coming out of the decoder for given sampling rate. In a container with video, a player can compare audio timing with video timing and perform a sync if they don't match. Different applications have different sync strategies. Most players will try to sync video to audio, Avidemux will sync (by inserting silence or skipping samples) audio to video. But when saving audio as a raw audio stream, Avidemux cannot do that. If audio timing in the source container didn't 100% agree with the number of samples decoded, exporting and importing audio will result in A/V getting out of sync somewhere.

Quote from: Who on January 16, 2021, 12:29:36 PMAlso, I have seen occasional situations where the audio looks VERY out of sync in the preview mode (off by even a second or two) but still is perfectly synced in the saved file [...].  My suspicion in those cases are that the files are some high-bandwidth variety and it is my hardware that can't quite keep up

Indeed, high frame rates at high resolutions with computationally expensive codecs (AV1, HEVC, to a lesser extent VP9), probably decoded in software rather than in hardware will do that (and even with hardware acceleration available, at least on macOS Avidemux does a poor job using it as it always immediately downloads decoded video data from GPU to the normal memory and then re-uploads it for display). Such files are not really editable as A/V sync cannot be judged during preview.

Quote from: Who on January 16, 2021, 12:29:36 PMSo if it was fixed recently that means I have to wait for the next release version that will work in MacOS (Catalina).

Unless you need AV1 decoding and VP9 encoding support, you can use the latest (not very fresh but oh well) Mojave nightly from https://avidemux.org/nightly/osx_mojave/ as it has that code change. In general, the idea is to build all macOS builds on Mojave as there is no easy way to generate backward-compatible builds on Catalina or Big Sur.

Quote from: Who on January 16, 2021, 12:29:36 PMAnyway, I'm not going to beat a dead horse here if you have really decided this can't be done or if it would take far too much time and effort

There are simply no resources to investigate this at the moment, apart from the fact that AFAIK you can do it in iMovie.
Title: Re: can i add a small external video in to the middle of existing video by avidemux
Post by: butterw on January 17, 2021, 10:03:12 AM
From what I understand Avidemux uses Tinypy for its project files and custom user scripts (available in the menu).
Would it be possible to write an insert.py script with Tinypy (when the next dev build becomes available) ? 

Easy Lossless insert:
- Position yourself on a keyframe
- Select Insert command >> choose the clip to be inserted in a file open dialog (or paste the filepath)
- Avidemux inserts the clip before the keyframe (warns of possible issues if applicable).
Title: Re: can i add a small external video in to the middle of existing video by avidemux
Post by: butterw on January 17, 2021, 10:54:58 AM
From what I understand Avidemux uses Tinypy for its project files and custom user scripts (available through the menu).
https://www.avidemux.org/admWiki/doku.php?id=using:tinypy

Is it currently (when the next dev build becomes available) possible to write an insert.py script with Tinypy ? 

Easy Lossless insert:
- Position yourself on a keyframe
- Select Insert command >> choose the clip to be inserted in a file open dialog (or paste the filepath)
- Avidemux inserts the clip before the keyframe (warns of possible issues if applicable).
Title: Re: can i add a small external video in to the middle of existing video by avidemux
Post by: Who on January 17, 2021, 12:29:14 PM
Quote from: eumagga0x2a on January 16, 2021, 02:19:40 PMThis is correct and a big fundmental problem. In a raw audio stream, there is no other source of timing than counting audio samples coming out of the decoder for given sampling rate. In a container with video, a player can compare audio timing with video timing and perform a sync if they don't match. Different applications have different sync strategies. Most players will try to sync video to audio, Avidemux will sync (by inserting silence or skipping samples) audio to video. But when saving audio as a raw audio stream, Avidemux cannot do that. If audio timing in the source container didn't 100% agree with the number of samples decoded, exporting and importing audio will result in A/V getting out of sync somewhere.

Well maybe this is a dumb question, but if "Avidemux will sync (by inserting silence or skipping samples) audio to video" I would assume that at that point it has a count of how much silence it has to add, or how many samples it has to skip.  What if it saved that offset value in a variable, and then if you exported the audio it would also save that offset value in a small file with the same filename as the audio file but a different extension?  And then when you go to bring the audio back it would look at that offset file and use that offset value?  Or, alternately, maybe when you go to save audio it could just print something to the screen saying "the current audio offset is xxx ms" and then when you go to bring it back you could use that value in the audio offset box?  Just anything so you get an exact sync and are not trying to guess the sync amount.

Even with a clapboard in the video I would not feel comfortable trying to judge the offset using my eyes and ears.  It would maybe be different if Avidemux had an expanded audio waveform display (no I am not asking for that) so that you could see visually exactly where the sound occurred in relation to the clapboard or whatever, and then drag or reposition the audio so it lines up; then I would feel much more confident that I could get an accurate match (but only if I had a good visual and audio cue to go on, which I'm sure would not always occur).  But still I think it is far better to try to preserve the original audio offset from the source material, and I would not mind entering that value by hand, I just don't want to be trying to "guesstimate" what it should be.

Quote from: eumagga0x2a on January 16, 2021, 02:19:40 PMUnless you need AV1 decoding and VP9 encoding support, you can use the latest (not very fresh but oh well) Mojave nightly from https://avidemux.org/nightly/osx_mojave/ as it has that code change. In general, the idea is to build all macOS builds on Mojave as there is no easy way to generate backward-compatible builds on Catalina or Big Sur.

That should work fine in Catalina, so I downloaded and installed it and will see if it makes any difference.  Thanks!
Title: Re: can i add a small external video in to the middle of existing video by avidemux
Post by: butterw on January 17, 2021, 08:52:51 PM
Quote from: butterw on January 17, 2021, 10:54:58 AMFrom what I understand Avidemux uses Tinypy for its project files and custom user scripts (available through the menu).
https://www.avidemux.org/admWiki/doku.php?id=using:tinypy

Is it currently (when the next dev build becomes available) possible to write an insert.py script with Tinypy ? 

Easy Lossless insert:
- Position yourself on a keyframe
- Select Insert command >> choose the clip to be inserted in a file open dialog (or paste the filepath)
- Avidemux inserts the clip before the keyframe (warns of possible issues if applicable).

It should be possible with Tinypy, but adm.clearSegments and adm.addSegment still remain a bit unclear to me.
   
Is there a way to add a complete Segment without knowing its duration (rather than adm.addSegment(1, 0, 10000000))
OR a way of getting the appended segment duration directly
OR a way of resetting markers like in the GUI without calling adm.clearSegments() ?

adm.loadVideo("B:/Videos/out/vid.mp4")
markA = adm.markerA
end0 =  adm.markerB
adm.appendVideo("B:/Videos/out/ins.mp4")
adm.clearSegments()
adm.addSegment(0, 0, markA) #presumably I need to stop one frame before keyframe markA
adm.addSegment(1, 0, 10000000) #I need duration of Segment 1. Is it possible to get directly or does it need to be calculated ?
adm.addSegment(0, markA, end0)
EDIT: end = ed.getVideoDuration() is equivalent to adm.markerB and involves a bit of calculation to reset the final value of marker B (which seems to be required.)

I got a popup msgbox on saving:
Cut points could not be checked.  This indicates an issue with a source video, the state of editing or a bug in the program.  Please check the application log file or console output for details.  Try anyway?
Title: Re: can i add a small external video in to the middle of existing video by avidemux
Post by: eumagga0x2a on January 17, 2021, 10:20:19 PM
If the first video wasn't edited yet (a single segment from 0 to its full duration fullDuration_0) , then the first segment is

adm.addSegment(0,0,currentPts)

The second one is the appended video:

adm.addSegment(1,firstFramePts_1,fullDuration_1)

The problem here is to get firstFramePts_1, i.e. the offset of the first frame relative to the start of the time in that reference video.

The third one is

adm.addSegment(0,currentPts,fullDuration_0)
Title: Re: can i add a small external video in to the middle of existing video by avidemux
Post by: eumagga0x2a on January 17, 2021, 10:22:27 PM
Editing commands are not available via internal Python interface, which means that the entire segment handling logic has to be reimplemented in Python.
Title: Re: can i add a small external video in to the middle of existing video by avidemux
Post by: butterw on January 17, 2021, 11:49:18 PM
Quote from: eumagga0x2a on January 17, 2021, 10:22:27 PMEditing commands are not available via internal Python interface, which means that the entire segment handling logic has to be reimplemented in Python.

You mean the commands from the Edit Menu (except for Set Markers) are not directly available in Tinypy,
meaning: Cut, Copy, Paste, Delete, Undo, Redo
Reset Markers, Reset Edit have some similarity with adm.clearSegments() + adm.addSegment() for all segments.
Title: Re: can i add a small external video in to the middle of existing video by avidemux
Post by: butterw on January 18, 2021, 01:29:45 AM
Quote from: eumagga0x2a on January 17, 2021, 10:20:19 PMIf the first video wasn't edited yet (a single segment from 0 to its full duration fullDuration_0) , then the first segment is
adm.addSegment(0,0,currentPts)

The second one is the appended video:
adm.addSegment(1,firstFramePts_1,fullDuration_1)

The problem here is to get firstFramePts_1, i.e. the offset of the first frame relative to the start of the time in that reference video.

The third one is
adm.addSegment(0,currentPts,fullDuration_0)

- ed.currentPts() returns the timestamp of the current position.
- from what I understand fullDuration_1 needs to be calculated, there is no predefined function for this.
- How is firstFramePts_1 obtained in regular Avidemux ?

As long as the source video has not been edited and only has one segment, operations such as split and insert look like they could be achieved by a script.

Title: Re: can i add a small external video in to the middle of existing video by avidemux
Post by: eumagga0x2a on January 18, 2021, 08:33:05 AM
Quote from: butterw on January 18, 2021, 01:29:45 AM- How is firstFramePts_1 obtained in regular Avidemux ?

Please see ADM_EditorSegment::updateRefVideo() in avidemux/common/ADM_editor/src/ADM_segment.cpp
Title: Re: can i add a small external video in to the middle of existing video by avidemux
Post by: eumagga0x2a on January 18, 2021, 08:37:53 AM
From Python interface, you would need to get the PTS of the first keyframe of the appended video (iterate ed.getNextKFramePts() until the value != ADM_NO_PTS is > fullDuration_0), then subtract fullDuration_0.
Title: Re: can i add a small external video in to the middle of existing video by avidemux
Post by: butterw on January 18, 2021, 01:51:37 PM
Quote from: eumagga0x2a on January 18, 2021, 08:37:53 AMFrom Python interface, you would need to get the PTS of the first keyframe of the appended video (iterate ed.getNextKFramePts() until the value != ADM_NO_PTS is > fullDuration_0), then subtract fullDuration_0.

What does ADM_NO_PTS mean and is its Python value (-1) ?
If I understand correctly I would need to seek with adm.seekKeyFrame, until ed.getNextKFramePts()>fullDuration_0 ?
fullDuration_0 can be obtained simply by ed.getVideoDuration() before appending.

The Python binding does not have all the Go menu functions, only next frame, and seek N keyframes.
adm.seekKeyFrame(int) #updates the preview
ed.nextFrame() #returns 0 on the last Frame
ed.getCurrentPts()
ed.getPrevKFramePts()
ed.getNextKFramePts() #returns -1 after the last KFrame
Title: Re: can i add a small external video in to the middle of existing video by avidemux
Post by: eumagga0x2a on January 18, 2021, 02:49:37 PM
Quote from: butterw on January 18, 2021, 01:51:37 PMWhat does ADM_NO_PTS mean and is its Python value (-1) ?

ADM_NO_PTS is a reserved value to indicate a missing timestamp. Correct, it is equal -1 in Python ((uint64_t)(-1) in C++).

Quote from: butterw on January 18, 2021, 01:51:37 PMIf I understand correctly I would need to seek with adm.seekKeyFrame

Yes, you are right, I missed that. Bisect could speed up the process, but in the future it would make sense to be able to pass linear time to getNextKFramePts() to avoid this.
Title: Re: can i add a small external video in to the middle of existing video by avidemux
Post by: butterw on January 18, 2021, 05:47:18 PM
All these different times (Pts, Dts?) are really quite confusing.
With the latest dev build it's at least not too difficult to do the cut/paste insert operation manually. But there would still be a benefit to have a direct insert command if it can be done.


One unrelated thing I've noticed is that I get a seek error msg when I try to paste at the first frame.
The paste operation seems to go well though.
Before the paste, the first frame timestamp in the GUI is 66ms. After the paste, first frame is zero.
Title: Re: can i add a small external video in to the middle of existing video by avidemux
Post by: eumagga0x2a on January 18, 2021, 06:37:22 PM
Quote from: butterw on January 18, 2021, 05:47:18 PMOne unrelated thing I've noticed is that I get a seek error msg when I try to paste at the first frame.

Good catch, thanks, should be fixed now (https://github.com/mean00/avidemux2/commit/c0f730851f67a8e7a811e3e616e554278c1a89c4).

Quote from: butterw on January 18, 2021, 05:47:18 PMBefore the paste, the first frame timestamp in the GUI is 66ms. After the paste, first frame is zero.

This is expected.
Title: Re: can i add a small external video in to the middle of existing video by avidemux
Post by: butterw on January 19, 2021, 12:32:05 AM
Quote from: eumagga0x2a on January 17, 2021, 10:20:19 PMIf the first video wasn't edited yet (a single segment from 0 to its full duration fullDuration_0) , then the first segment is
adm.addSegment(0,0,currentPts)

The second one is the appended video:
adm.addSegment(1,firstFramePts_1,fullDuration_1)

The problem here is to get firstFramePts_1, i.e. the offset of the first frame relative to the start of the time in that reference video.

The third one is
adm.addSegment(0,currentPts,fullDuration_0)

I went though this with the TinyPy Shell, Avidemux crashed after I finished editing. But I noticed that ed.getVideoDuration() was not reported correctly, the value i gets added twice.

adm.clearSegments()
adm.addSegment(0, 0, i) # i is the insert point
adm.addSegment(1, f1, end1) # the inserted section
adm.addSegment(0, i, end0)
 
I also didn't succeed when trying to save the part-0b like this, which may be expected (output is truncated at end0-I):
adm.clearSegments() #duration is 0, clears the selection, but not the markers or position
adm.addSegment(0, i, end0)
adm.markerA = i
adm.markerB = end0
adm.save("B:/Videos/out/test0b.mp4")
Title: Re: can i add a small external video in to the middle of existing video by avidemux
Post by: butterw on January 19, 2021, 11:45:36 AM
Quote from: eumagga0x2a on January 17, 2021, 10:20:19 PMIf the first video wasn't edited yet, then the first segment is adm.addSegment(0,0,currentPts)
Is there a way to check whether the loaded video has been edited and why does it matter ?

I think it is possible to write TinyPy script functions that does the following:
1) if segments have been appended: save the loaded file (to out.mp4) and reload. 
2) splits and saves the video in two files (tmp1.mp4, tmp2.mp4) based on the current position.
3) reload and append the three segments (tmp1.mp4, insert.mp4, tmp2.mp4) then saves to out.mp4 (or opens a fileSave dialog).

This should achieve Insert on the current position with the current python bindings (though not very elegantly: it needs to save and reload two temporary files). To do better the issue referenced in my previous post would need to be solved or a built-in Insert command would be needed.
Title: Re: can i add a small external video in to the middle of existing video by avidemux
Post by: Who on January 19, 2021, 03:14:32 PM
Quote from: Who on January 17, 2021, 12:29:14 PM
Quote from: eumagga0x2a on January 16, 2021, 02:19:40 PMUnless you need AV1 decoding and VP9 encoding support, you can use the latest (not very fresh but oh well) Mojave nightly from https://avidemux.org/nightly/osx_mojave/ as it has that code change. In general, the idea is to build all macOS builds on Mojave as there is no easy way to generate backward-compatible builds on Catalina or Big Sur.

That should work fine in Catalina, so I downloaded and installed it and will see if it makes any difference.  Thanks!

Just wanted to pop back in to report that the newest Mojave build from that link did NOT work fine in Catalina.  There were two issues:  First, sound would not play while previewing, and second, the preview window would shrink down to a very small area of the screen.  Both of these were intermittent issues and if I closed and restarted the program sometimes one issue would disappear but then the other would show up.  I don't think either of these problems would affect actual encoding but they made editing difficult to impossible so I finally wound up going back to the previous version from my Time Machine backup.  I have no idea if these were only issues because I am running Catalina or not.
Title: Re: can i add a small external video in to the middle of existing video by avidemux
Post by: eumagga0x2a on January 19, 2021, 04:24:59 PM
The audio issue is due to the later fix [editor/audio] Enforce blockalign for (L)PCM only (https://github.com/mean00/avidemux2/commit/43cd15d4ef62dd17074941cfb4e9f2fdbdb1572c) not present in that build. I cannot reproduce the issue with preview window shrinking down. I run Catalina too.

Obviously, I can generate a private build off git master and upload it to WeTransfer anytime if you wish. Official builds will happen when they happen.

Using Time Machine to revert an installation of Avidemux app bundle is a major overkill, IMHO.
Title: Re: can i add a small external video in to the middle of existing video by avidemux
Post by: butterw on January 22, 2021, 07:51:12 PM
With a few corrections, my insert script for Avidemux seems to be working now. It doesn't require temporary files.

https://github.com/butterw/bShaders/tree/master/test_LimitedRange (bInsert.py)

Feedback in the patch section.