Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MqLeet opened this issue Apr 22, 2024 · 6 comments
Labels
Milestone

Comments

@MqLeet
Copy link

MqLeet commented Apr 22, 2024

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
Copy link
Author

MqLeet commented Apr 22, 2024

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

@Breakthrough
Copy link
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!

@Breakthrough Breakthrough added this to the v0.6.4 milestone Apr 27, 2024
@Breakthrough
Copy link
Owner

Breakthrough commented Apr 27, 2024

@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

@MqLeet
Copy link
Author

MqLeet commented Apr 28, 2024

@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 MqLeet closed this as completed May 6, 2024
@Breakthrough Breakthrough reopened this May 8, 2024
@Breakthrough
Copy link
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.

@Breakthrough
Copy link
Owner

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

Breakthrough added a commit that referenced this issue May 26, 2024
Change default stream mapping so that only a single video stream is selected.
This should reduce ffmpeg command failures when an unrecognized or unsupported
stream is present in the video. Fixes #392.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants