0

I am trying to split a video with ffmpeg, implementing a python script.

I am getting this error:

Command '['ffprobe', '-i', 'path_to_my_video/MVI_0731.MP4', '-hide_banner']' returned non-zero exit status 1.

Here is the code I am using to split the video:

for video_file in video_files:
        try:
            # Call "ffprobe" to get duration of input video.
            ffprobe_process = subprocess.run(args=["ffprobe", "-i", video_file, "-hide_banner"],
                                           check=True,
                                           stdout=subprocess.PIPE,
                                           stderr=subprocess.PIPE,
                                           encoding="utf-8",
                                           shell=True)

            # "ffprobe" writes to stderr instead of stdout!
            duration_string = extract_duration_from_ffprobe_output(ffprobe_process.stderr)            
            duration_in_seconds = duration_string_to_seconds(duration_string)

            # Make start_stop_list
            start_stop_list = read_start_stop_list(start_stop_lists[nbr_video])
            nbr_video += 1
            total_pieces = int(len(start_stop_list))

This is the line causing the problem:

ffprobe_process = subprocess.run(args=["ffprobe", "-i", video_file, "-hide_banner"],
                                           check=True,
                                           stdout=subprocess.PIPE,
                                           stderr=subprocess.PIPE,
                                           encoding="utf-8",
                                           shell=True)

When I change it to this line of code:

ffprobe_process = subprocess.run(args=['ffprobe', '-i', video_file, '-show_entries', 'format=duration', '-v', 'quiet', '-of', 'csv=%s' % ("p=0")])

it works, I mean, the script goes after that line, but then throws the following error at the next line:

470.240000
expected string or bytes-like object

470.240000 is the right duration of my video. So the new line that I changed it with works better, but still not working with my code somehow.

Anyone has an idea how I can solve this?

ZelelB
  • 1,836
  • 7
  • 45
  • 71
  • 2
    What is the command you would run in the shell? The `cmd` tag is for Microsoft Windows cmd.exe. If this is not on Windows, please delete the `cmd` tag. – lit Oct 22 '18 at 19:52

1 Answers1

0

I found the solution.

Here is the code that works:

for video_file in video_files:
        try:
            # Call "ffprobe" to get duration of input video.
            ffprobe_process = subprocess.run(args=["ffprobe", "-i", video_file, '-show_entries', 'format=duration', '-v', 'quiet', '-of', 'csv=%s' % ("p=0")])

            # "ffprobe" writes to stderr instead of stdout!
            #duration_string = extract_duration_from_ffprobe_output(ffprobe_process.stderr)     
            duration_string = str(ffprobe_process)   
            #duration_in_seconds = duration_string_to_seconds(duration_string)
            duration_in_seconds = duration_string

            # Make start_stop_list
            start_stop_list = read_start_stop_list(start_stop_lists[nbr_video])
            nbr_video += 1
            total_pieces = int(len(start_stop_list))
            #pdb.set_trace()
ZelelB
  • 1,836
  • 7
  • 45
  • 71