PySceneDetect icon indicating copy to clipboard operation
PySceneDetect copied to clipboard

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

Open MqLeet opened this issue 1 year ago • 5 comments

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

MqLeet avatar Apr 22 '24 09:04 MqLeet

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

MqLeet avatar Apr 22 '24 10:04 MqLeet

@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!

Breakthrough avatar Apr 27 '24 22:04 Breakthrough

@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:

  • [x] 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.
  • [x] Update the default arguments + test

Breakthrough avatar Apr 27 '24 22:04 Breakthrough

@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!

MqLeet avatar Apr 28 '24 06:04 MqLeet

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.

Breakthrough avatar May 08 '24 01:05 Breakthrough

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

Breakthrough avatar May 19 '24 03:05 Breakthrough

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.

yongyongdown avatar Jun 24 '24 01:06 yongyongdown

@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?

Breakthrough avatar Jun 25 '24 02:06 Breakthrough

@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.

yongyongdown avatar Jun 25 '24 03:06 yongyongdown

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?

Breakthrough avatar Jun 26 '24 01:06 Breakthrough

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

yongyongdown avatar Jun 27 '24 04:06 yongyongdown