Skip to content

provide output folder directory when splitting videos #298

Closed

Description

@fcakyon

@Breakthrough thanks for this awesome project! I am utilizing it on my PhD heavily 👍

Issue

You can set the output directory in save_images function which is super useful in my case. However, there is no such feature for split_video_ffmpeg which is a must in my case.

Example:

from scenedetect.video_splitter import split_video_ffmpeg

split_video_ffmpeg(
    filepath,
    scene_list=scene_list,
    output_file_template="$scene-$SCENE_NUMBER.",
    output_dir=export_dir,
    show_progress=True,
)

Question:

  1. Do you have any intentions to add such a feature?
  2. How can I implement a workaround for this? Should I change these lines:
    call_list += [
    '-sn',
    filename_template.safe_substitute(
    VIDEO_NAME=video_name, SCENE_NUMBER=scene_num_format % (i + 1))
    ]

Activity

  1. fcakyon commented on Nov 12, 2022

    @fcakyon
    Author

    How I solved it:

    update this:

                call_list += [
                    '-sn',
                    filename_template.safe_substitute(
                        VIDEO_NAME=video_name, SCENE_NUMBER=scene_num_format % (i + 1))
                ]

    with this:

    # create output dir at function start
    Path(output_dir).mkdir(parents=True, exist_ok=True)
    
                # prepend output_dir to filename
                export_path = str(
                    Path(output_dir)
                    / filename_template.safe_substitute(
                        VIDEO_NAME=video_name, SCENE_NUMBER=scene_num_format % (i + 1)
                    )
                )
                call_list += [
                    "-sn",
                    export_path,
                ]
  2. Breakthrough commented on Nov 13, 2022

    @Breakthrough
    Owner

    Hi @fcakyon;

    You can replace the output_file_template parameter with an absolute path as well to work around this, e.g.:

    from scenedetect.video_splitter import split_video_ffmpeg
    
    export_dir = "C:/output_folder/"
    
    split_video_ffmpeg(
        filepath,
        scene_list=scene_list,
        output_file_template=export_dir + "$scene-$SCENE_NUMBER.",
        show_progress=True,
    )

    The documentation could probably be improved here, but I probably will leave this as-is and not introduce another argument. Thanks for the report!

  3. Mensen commented on Nov 16, 2022

    @Mensen

    Apologies for raising a closed issue from the dead here, but the proposed solution (#298 (comment)), doesn't work for my example.

    >>> output_dir = r'F:\Gamepass_Clips'
    >>> output_template = os.path.join(os.path.join(output_dir,"scene-$SCENE_NUMBER.mp4"))
    >>> print(output_template)
    F:\Gamepass_Clips\scene-$SCENE_NUMBER.mp4
    >>> scenedetect.video_splitter.split_video_ffmpeg(video_file, scene_list,
    ...   output_file_template=output_template)
    Error splitting video (ffmpeg returned 1).
    1
    

    My code differs from your example by using the os.path functions instead of writing the path in a regular string... but I have also tried that with no apparent difference.

    I considered whether there were some potential write permissions that throws the error but when I do the actual scenedetect, I also specify a stats_file_path in precisely the same way using the os.path method

    Let me know if I should have simply raised another issue here, but considering the "solution" doesn't work, I figured it might be best to follow up here.

    Thanks in advance for helping out one of your sponsors :)

  4. Breakthrough commented on Nov 17, 2022

    @Breakthrough
    Owner

    @Mensen what happens if you use forward slashes instead? Does it work as expected from the CLI? If it still fails feel free to re-open a new issue, what you show above should work.

    def get_and_create_path(file_path: AnyStr, output_directory: Optional[AnyStr] = None) -> AnyStr:
    is how this works for the CLI.

  5. Mensen commented on Nov 20, 2022

    @Mensen

    Forward slashes also does not work.

    scenedetect.video_splitter.split_video_ffmpeg(video_file, scene_list[0:2], 
    ...   output_file_template='F:/Gamepass_Clips/Clip-$SCENE_NUMBER.mp4')
    Error splitting video (ffmpeg returned 1).
    1
    

    No issue when simply specifying a file name, but this then puts the files in the code directory which, when splitting 100s of scenes are less than ideal

    scenedetect.video_splitter.split_video_ffmpeg(video_file, scene_list[0:2], 
    ...   output_file_template='Clip-$SCENE_NUMBER.mp4')
    0
    

    In the code snip above it refers to output_directory and not necessarily output_file_template so there seems to be an intermediate step between the split_video_ffmeg and the get_and_create_path code. Could the problem lie there?

    For example in:

    arg_override = arg_override.replace('\\"', '"')

    That would certainly replace the double \\ that os.path.join uses when combining paths to be os compatable.

    And wouldn't the line:

    output_file_template_iter = output_file_template_iter.replace(":", ";")

    Replace the ":" with a ";" in the path I specified?

  6. Breakthrough commented on Nov 21, 2022

    @Breakthrough
    Owner

    @Mensen thanks for pointing that out, indeed that seems to be the issue here. My apologies, feel free to file a new bug report for this.

  7. Breakthrough commented on Dec 1, 2023

    @Breakthrough
    Owner

    This has come up a few times again (e.g. #363), so I will look into revisiting this for the next release.

  8. added this to the v0.6.3 milestone on Dec 1, 2023
  9. Breakthrough commented on Jan 22, 2024

    @Breakthrough
    Owner

    This will be included in the next release, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions