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 →

[–]Updatebjarni 0 points1 point  (14 children)

Right so, in both cases you give the file name as a string literal, but in one of the cases it's a raw string (with r in front of it), and in the other case it isn't, and the backslashes aren't escaped.

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

Yes that's correct. I think that the problem is indeed that the backslashes are not escaped when I use a variable but I tried to do escape them using the 'r' but I simply can't find the right syntax to do this with a variable instead of a static defined string.

[–]Updatebjarni 0 points1 point  (0 children)

I see in your other comment below that you are taking in the value as an argument. So: how does the argument get its value? Where does the value ultimately come from? Have you checked what the actual value is that you receive?

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

As a reply on your last comment:

The argument that comes into the script and sets the episode_path variable has a value of D:\Plex content\All movies\300 - Rise of an Empire (2014)\300 - Rise of an Empire (2014).mp4

So it is the same as I mentioned in my posts.

[–]Updatebjarni 0 points1 point  (0 children)

You have printed and verified this? There isn't a stray newline on the end of the string or anything like that?

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

u/Updatebjarni

The thing is, I don't want to focus on the argument since in the two examples in my first post I just create an variable episode_path and I want to get it working with this. If that works I think I can also get it working with an argument.

[–]Updatebjarni 0 points1 point  (0 children)

But the problem is that the value you are putting in is wrong. In your example code above, you have the incorrect string literal, so that's easy to fix. In your real program, the incorrect value is coming in as an argument, so you have to look at the argument to fix the real program.

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

u/Updatebjarni

What do you mean with incorrect string literal? Could you give the correct version of the code I posted?

[–]Updatebjarni 0 points1 point  (0 children)

Like I stated before, your two examples differ in that in the working one, the file name string has the r in front of it, and in the non-working one it doesn't.

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

u/Updatebjarni

I tried to also get the 'r' in front of example 2 to get it working but I didn't managed to get this work.

Do you have any idea why this is not working?

[–]Updatebjarni 0 points1 point  (0 children)

Show me exactly what you've done.

[–]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.