DEAR PEOPLE FROM THE FUTURE: Here's what we've figured out so far...

Welcome! This is a Q&A website for computer programmers and users alike, focused on helping fellow programmers and users. Read more

What are you stuck on? Ask a question and hopefully somebody will be able to help you out!
0 votes

I'm trying to add the argument -r MAX_FRAME_RATE to a command if the current r_frame_rate is above the given MAX_FRAME_RATE. But I'm getting an error when converting the frame rate into a float:

def push_change_frame_rate_args_to_command(self, cmd: List[str]) -> None:
    if ('r_frame_rate' in self.video_metadata
            and convert_str_to_float('r_frame_rate') > MAX_FRAME_RATE):
        cmd.extend(["-r", str(MAX_FRAME_RATE)])

def convert_str_to_float(s: str) -> float:
    """Convert rational or decimal string to float
    """
    if '/' in s:
        num, denom = s.split('/')
        return float(num) / float(denom)
    return float(s)

File "/home/user/code/python/reduce_video_size/main.py", line 338, in convert_str_to_float
    return float(s)
ValueError: could not convert string to float: 'r_frame_rate'

I'm using 'r_frame_rate': '30000/1001'

Context

by
edited by
0

Your problem is completely unrelated to your question. A better question would have been "Why can't I convert this string to float?" The error message is pretty explicative.

1 Answer

+1 vote
 
Best answer
convert_str_to_float('r_frame_rate') > MAX_FRAME_RATE

you are passing the key "r_frame_rate" to the function instead of its value. That's exactly what the error message is saying. You have to use

convert_str_to_float(self.video_metadata['r_frame_rate'])
by
selected by
Contributions licensed under CC0
...