python - 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:
解决方案
推荐阅读
- html - 如果元素没有尾随兄弟,有没有办法只删除它?
- json - 我需要帮助来构建自己的 json 架构
- java - Android 6-7 中的内部阴影颜色不正确
- sass - TypeError:“原始”参数必须是函数类型 - SASS
- c++ - 正确使用 C++ STL set_symmetric_difference?
- r - 当函数依赖于继承的 datafame 的参数时,如何将一组函数叠加到 ggplot2 图形上?
- lua - 运行同时重复循环 Lua 脚本 Logitech GHUB
- windows - Groovy java.sql.SQLException:找不到适合 jdbc:sqlserver:// 的驱动程序
- sql - 为什么 Teradata EXCEPT 不返回预期结果?
- python - 当我使用 freq='H' 时,pd.PeriodIndex 只给我 12 小时的结果