首页 > 解决方案 > ValueError:无法将字符串转换为浮点数:(python)

问题描述

有这个代码:

import os

def get_video_duration(video_path: str) -> float:
    duration_command_stream = os.popen(
        'ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1' + video_path
    )
    duration_command_output = duration_command_stream.read()

    return float(duration_command_output)

错误:

[default @ 000001d1cf80b400] Unable to parse option value "1videosaHR0cHM6Ly9zdG9yYWdlLm1pbmlnZ2lvZGV2LmZyL3Rlc3Qvc3RvcnkubXA0.mp4" as boolean[default @ 000001d1cf80b400] Failed to set option 'nokey' with value '1videosaHR0cHM6Ly9zdG9yYWdlLm1pbmlnZ2lvZGV2LmZyL3Rlc3Qvc3RvcnkubXA0.mp4' provided to writer context
Traceback (most recent call last):
  File "main.py", line 21, in <module>
    videos_to_upload = build_videos_to_upload(video_url, video_path)
  File "C:\Users\shrim\Downloads\instagram-story-poster-main\instagram-story-poster-main\build_videos_to_upload.py", line 10, in build_videos_to_upload
    duration = get_video_duration(video_path)
  File "C:\Users\shrim\Downloads\instagram-story-poster-main\instagram-story-poster-main\get_video_duration.py", line 9, in get_video_duration
    return float(duration_command_output)
ValueError: could not convert string to float: 

标签: python

解决方案


推荐阅读