News:

--

Main Menu

Extract multiple files at once?

Started by spartanhooah, April 13, 2020, 09:12:54 PM

Previous topic - Next topic

spartanhooah

I have a long video that I'd like to cut into smaller segments. Is it possible to set multiple markers and tell Avidemux to split the file at those points?

eumagga0x2a

No, Avidemux doesn't support multiple selection, i.e. you need to set the B marker to the end of the first chunk, save the video, set the A marker to the current position of the B marker, set the B marker to the end of the second chunk, save the video to a different file, rinse and repeat.

The operation is easily scriptable, e.g.

adm = Avidemux()
ed = Editor()
gui = Gui()
if 0 == ed.nbSegments():
    gui.displayError("No video loaded!")
    return
# video
adm.videoCodec("Copy")
# audio
tracks = adm.audioTracksCount()
if tracks > 0:
    adm.audioClearTracks()
    adm.setSourceTrackLanguage(0,"Unknown")
    adm.audioAddTrack(0)
    adm.audioCodec(0, "copy")
# muxer
adm.setContainer("MKV", "forceDisplayWidth=False", "displayWidth=1280", "displayAspectRatio=0")
# choose output directory
outdir = gui.dirSelect("Select the target folder")
if outdir is None:
    gui.displayError("No output folder selected, bye")
    return
# choose chunk duration (1 to 10 minutes)
spin = DFInteger("Chunk duration in minutes:",1,10)
spin.value = 2
dialog = DialogFactory("Split video in chunks")
dialog.addControl(spin)
if 1 != dialog.show():
    return
# set some variables
chunk = spin.value
chunk *= 60        # chunk duration in seconds
chunk *= 1000000   # chunk duration in microseconds (us)
duration = ed.getVideoDuration() # video duration in us
start = 0
end = chunk
sep = "\\"
ext = ".mkv"
count = 1
zero = "0"
# loop!
while True:
    adm.markerA = start
    if end > duration:
        end = duration
    adm.markerB = end
    if count > 9:
        zero = ""
    outfile = outdir + sep + zero + str(count) + ext
    if 1 != adm.save(outfile):
        gui.displayError("Error saving "+outfile)
        return
    if end >= duration:
        break
    start += chunk
    end += chunk
    count += 1
    if count > 99:
        gui.displayError("Number of chunks exceeds max = 99")
        return
# done
gui.displayInfo("Everything done","")


Of couse, you may need to adjust the codec and the output container (and to set the value of the variable "ext" to match the container).

spartanhooah

Ok, thanks. Easily scriptable, yes, but perhaps not conducive to segments that may not be the same length within some margin.

eumagga0x2a

Sure, only a manual operation can ensure that segments are chosen based on the context. Enabling alternative keyboard shortcuts in Avidemux preferences and generally using keyboard with Avidemux rather than other input devices could significantly simplify and speed up the task.