Skip to content

'Error splitting video (ffmpeg returned 1) ' occurs while using 'split_video_ffmpeg' #392

Closed

Description

@MqLeet

Description:

Here is my spliting code:

from scenedetect import open_video, SceneManager, split_video_ffmpeg
from scenedetect.detectors import ContentDetector
from scenedetect.video_splitter import split_video_ffmpeg



def split_video_into_scenes(video_path, threshold=27.0):
    # Open our video, create a scene manager, and add a detector.
    video = open_video(video_path)
    scene_manager = SceneManager()
    scene_manager.add_detector(
        ContentDetector(threshold=threshold))
    scene_manager.detect_scenes(video, show_progress=True)
    scene_list = scene_manager.get_scene_list()
    # import pdb; pdb.set_trace()
    split_video_ffmpeg(input_video_path=video_path, scene_list=scene_list, output_dir='test4longsplit', show_progress=True)


if __name__ == '__main__':
    video_path = 'sampled_videos/tokyo-walk.mp4'
    split_video_into_scenes(video_path=video_path)

Command:

I run the python python scene_detect.py in command line

Output:

And I got the error like this:

  Detected: 1 | Progress: 100%|██████████| 1799/1799 [00:03<00:00, 583.63frames/s]
  0%|          | 0/1799 [00:00<?, ?frame/s]Error splitting video (ffmpeg returned 1).
  0%|          | 0/1799 [00:00<?, ?frame/s]

How can I solve it?

Environment:
System Info

OS Linux-3.10.0-957.el7.x86_64-x86_64-with-glibc2.17
Python 3.9.18

Packages

av 12.0.4
click 8.1.7
cv2 4.9.0
moviepy Not Installed
numpy 1.26.4
platformdirs 4.2.0
scenedetect 0.6.3
tqdm 4.66.2

Tools

ffmpeg 9c33b2f
mkvmerge Not Installed

Media/Files:

Video link: https://cdn.openai.com/sora/videos/tokyo-walk.mp4

Activity

  1. MqLeet commented on Apr 22, 2024

    @MqLeet
    Author

    Hi @Breakthrough, thanks for your great work! Can you help me?😭

  2. Breakthrough commented on Apr 27, 2024

    @Breakthrough
    Owner

    @MqLeet in v0.6.1 I added -map 0 to the ffmpeg args as part of fixing #271. It seems to cause issues for this particular video, I am not entirely sure why though.

    You can override the default ffmpeg arguments by setting the arg_override parameter of split_video_ffmpeg().

    Can you remove the -map 0 from the defaults and try to see if that works? Thanks!

  3. added this to the v0.6.4 milestone on Apr 27, 2024
  4. Breakthrough commented on Apr 27, 2024

    @Breakthrough
    Owner

    @MqLeet thank you for sharing the sample, that was really helpful. Running through ffprobe I see the following streams:

    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'tokyo-walk.mp4':
      Metadata:
        major_brand     : isom
        minor_version   : 512
        compatible_brands: isomiso2avc1mp41
        encoder         : Lavf60.3.100
      Duration: 00:00:59.97, start: 0.000000, bitrate: 6462 kb/s
      Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 6459 kb/s, 30 fps, 30 tbr, 15360 tbn (default)
        Metadata:
          handler_name    : Core Media Video
          vendor_id       : [0][0][0][0]
          encoder         : Lavc60.3.100 libx264
          timecode        : 00:00:00:00
      Stream #0:1[0x2](eng): Data: none (tmcd / 0x64636D74)
        Metadata:
          handler_name    : Core Media Video
          timecode        : 00:00:00:00
    Unsupported codec with id 0 for input stream 1
    

    I was able to rework the set of mappings from -map 0 to -map 0:v -map 0:a? -map 0:s? to get it to work. NOTE: The order of the streams is important!

    Initially I thought the video mapping would need to be -map 0:v:0 (only select the first video stream), but selecting all video streams seems to work as well. I'm not sure why it works since it seems to interpret both streams as videos. Thanks for the report though, I'll make sure to update the default args in the next release.

    Open items before closing:

    • Decide on a default video mapping:
      • -map 0:v matches current behavior, but might fail if one of the video streams is unsupported.
      • -map 0:v:0 would only take a single video stream if multiple are present, which reduces the chances of failures, and only selects the stream PySceneDetect processed. This may be the best option for compatibility, but would require anyone dealing with multiple video streams to override the default set of arguments.
    • Update the default arguments + test
  5. MqLeet commented on Apr 28, 2024

    @MqLeet
    Author

    @MqLeet in v0.6.1 I added -map 0 to the ffmpeg args as part of fixing #271. It seems to cause issues for this particular video, I am not entirely sure why though.

    You can override the default ffmpeg arguments by setting the arg_override parameter of split_video_ffmpeg().

    Can you remove the -map 0 from the defaults and try to see if that works? Thanks!

    Hi @Breakthrough , after removing "-map 0" , bug fixed!
    image

    image

    Thanks for your great work!

  6. Breakthrough commented on May 8, 2024

    @Breakthrough
    Owner

    Keeping this issue open until the items in the previous comment are resolved. I think changing these options should be considered in order to improve compatibility out-of-the-box, but still want to verify the new mapping I've proposed.

  7. Breakthrough commented on May 19, 2024

    @Breakthrough
    Owner

    A single stream is likely the most common use case, so I will choose that for a default.

  8. added a commit that references this issue on May 26, 2024
    448e6c4
  9. modified the milestones: v0.6.5, v0.6.4 on Jun 5, 2024
  10. yongyongdown commented on Jun 24, 2024

    @yongyongdown

    hello
    I too am experiencing the same problem.

    run the code below, an error will appear.

    image

    I also modified DEFAULT_FFMPEG_ARGS like this. But still the problem persists.
    image

    What should I do?
    Thank you for your reply.

  11. Breakthrough commented on Jun 25, 2024

    @Breakthrough
    Owner

    @yongyongdown try setting show_output=True when calling split_video_ffmpeg to get more information about the error. That will let you know why ffmpeg does not like the input. Can you try that and post it here?

  12. yongyongdown commented on Jun 25, 2024

    @yongyongdown

    @Breakthrough

    image

    run it,

    image

    but, I don't know where I saw this code, but when I run it, it works fine.
    image
    image

    The first code removes map from arg_override,
    The code that works well is the one with only -map 0 added.

    Likewise, add arg_override='-map 0' to the first code, it works well.

  13. Breakthrough commented on Jun 26, 2024

    @Breakthrough
    Owner

    It looks like you are using a very old version of ffmpeg which is probably why the default arguments aren't working. What version of PySceneDetect are you using? Can you also try with a newer version of ffmpeg?

  14. yongyongdown commented on Jun 27, 2024

    @yongyongdown

    image

    I used ffmpeg == 4.3, pyscenedetect == 0.6.4

    I don't think I am using an old version. In any case, the issue has been resolved, but please let me know if you need any information

  15. tavyscrolls commented on Sep 27, 2024

    @tavyscrolls

    On Ubuntu, you need to switch channels from stable (ffmpeg 4.3 ~2020) to latest/edge

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions