On Wed Jul01'26 05:23:24PM, Community Support for Fedora Users wrote:
> From: Robert Moskowitz via users <[email protected]>
> Date: Wed, 1 Jul 2026 17:23:24 -0400
> To: Community support for Fedora users <[email protected]>
> Cc: Robert Moskowitz <[email protected]>
> Reply-To: Community support for Fedora users <[email protected]>
> Subject: mp4 cutting
> 
> I have an mp4, well actually webm that I want to cut a big piece out.  The
> part my wife wants.
> 
> I found losslesscut, but can't find it.
> 
> Well anything that I can give a start point and end point and get the sub
> piece.
> 
> Thanks for any pointers.
> 

Here is a python script I use. It uses ffmpeg.

The input file in input.mp4 (you can change it) and then you keep on adding the 
sections you want included in the times.append function.

The output shows up in output.mp4.

I am not sure where I got it from, and I seem to have neglected to write that 
down, but I am pretty certain I modified it minimally from wherever (likely 
stackoverflow) so all credits to the original author. (I am sorry for being 
negligent in this regard.)

I have used it every semester for over five years (I record my lectures using 
simplescreenrecorder and sometimes need to clean out things).

There are likely better alternatives out there, but this is simple and 
commandline.

I hope it helps!

Best wishes,
Ranjan

#!/usr/bin/env python3

import subprocess


def get_duration(input_video):
    cmd = [
        "ffprobe",
        "-i",
        input_video,
        "-show_entries",
        "format=duration",
        "-v",
        "quiet",
        "-sexagesimal",
        "-of",
        "csv=p=0",
    ]
    return subprocess.check_output(cmd).decode("utf-8").strip()


if __name__ == "__main__":
    name = "input.mp4"
    times = []
    times.append(["00:02:04.9", "01:15:00"])
    #    times.append(["00:33:53", "00:40:25"])
    #    times.append(["01:17:25", "01:29:30"])
    #    times.append(["01:07:25", "01:11:16"])
    #    times.append(["01:08:10", "01:12:00"])

    # times = [["00:00:00", get_duration(name)]]

    if len(times) == 1:
        time = times[0]
        cmd = [
            "ffmpeg",
            "-i",
            name,
            "-ss",
            time[0],
            "-to",
            time[1],
            "-c:v",
            "copy",
            "-c:a",
            "copy",
            "output.mp4",
        ]
        subprocess.check_output(cmd)
    else:
        open("concatenate.txt", "w").close()
        for idx, time in enumerate(times):
            output_filename = f"output{idx}.mp4"
            cmd = [
                "ffmpeg",
                "-i",
                name,
                "-ss",
                time[0],
                "-to",
                time[1],
                "-c:v",
                "copy",
                "-c:a",
                "copy",
                output_filename,
            ]
            subprocess.check_output(cmd)

            with open("concatenate.txt", "a") as myfile:
                myfile.write(f"file {output_filename}\n")
        cmd = [
            "ffmpeg",
            "-f",
            "concat",
            "-i",
            "concatenate.txt",
            "-c",
            "copy",
            "output.mp4",
        ]
        output = subprocess.check_output(cmd).decode("utf-8").strip()
-- 
_______________________________________________
users mailing list -- [email protected]
To unsubscribe send an email to [email protected]
Fedora Code of Conduct: 
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedoraproject.org/archives/list/[email protected]
Do not reply to spam, report it: 
https://forge.fedoraproject.org/infra/tickets/issues/new

Reply via email to