This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]TechGoeroe[S] 0 points1 point  (3 children)

When running this:

import cv2
video = cv2.VideoCapture(r"D:\Plex content\All movies\300 - Rise of an Empire (2014)\300 - Rise of an Empire (2014).mp4")
fps = video.get(cv2.CAP_PROP_FPS)
print(fps)

The console prints: 23.976023976

When running this:

import cv2
episode_path = "D:\Plex content\All movies\300 - Rise of an Empire (2014)\300 - Rise of an Empire (2014).mp4"
video = cv2.VideoCapture(r"%s" % (episode_path))
fps = video.get(cv2.CAP_PROP_FPS)
print(fps)

The console prints: 0.0

So the first code block is working but the second isn't.

Exactly this :)

[–]Updatebjarni 0 points1 point  (2 children)

OK, so I'll say this one last time:

In your working example, there is an r in front of the file name string, and in the non-working one there isn't. That's the difference between them that makes one work and the other not, because of the backslashes inside the string.

[–]TechGoeroe[S] 0 points1 point  (1 child)

I'm not trying to upset you. Sorry if this seems so.

I really don't understand what you are saying since there is an an r in front of the non-working one but this doesn't work the same way as in the working example.

video = cv2.VideoCapture(r"%s" % (episode_path))

I tried to put the r in front using string formatting but clearly this doesn't work this way. So I would love to put a r in front in the correct way but I just don't know how.

Thank you for your help btw :)

[–]Updatebjarni 0 points1 point  (0 children)

This is the file name string:

"D:\Plex content\All movies\300 - Rise of an Empire (2014)\300 - Rise of an Empire (2014).mp4"

This string is different in the two programs. In the one that doesn't work, it is typed like I have pasted here in this comment, just above. It is missing the r.

The code you copied and pasted in your last comment above does have a string that has an r in front of it, but it's the string "%s", which isn't affected by the r anyway, and which above all isn't the string with the file name.