0

To perform video operations I'm using python with the support of ffmpeg. After I've uploaded videos, I need to resize them, so I'll follow these instructions to calculate the video dimensions:

link_v = "C:/video/video.mp4"
ffmpeg = "ffprobe -v error -show_entries stream=width,height -of default=noprint_wrappers=1 %s"% link_v
info = check_output(ffmpeg, shell=True)
print(info)

The console result is something like this:

width=350
height=350

But I do not care about this, when it is printed as if it were a string, because the real data would be: b'width=350\r\nheight=350\r\n' or ['width=350\r\nheight=350\r\n'].

What I really want to see is an associative data: "{width: 350, height: 350}", once I get then I would call for example width in the info mode ['width'], how can I get this result?

Question
  • 145
  • 2
  • 12

2 Answers2

1

ffprobe offers a JSON writer as an output format. Set -of to json

Gyan
  • 85,394
  • 9
  • 169
  • 201
1

Here is the code you need:
link_v = "D:/video/youtube/video.mp4"
ffmpeg = "ffprobe -v error -show_entries stream=width,height -of default=noprint_wrappers=1 %s"% link_v
info = sp.check_output(ffmpeg, shell=True)
dim = str(info).split("b")[1].split('\'')[1].split('\\r\\n')[:2]
dim =dict(item.split("=") for item in dim)
print(dim)

and the output would be like this:

{'width': '1920', 'height': '1080'}

  • I solved in this way: 1)info = check_output(data, shell=True) 2)jsoninfo = json.loads(info), thanks anyway for the interest – Question Sep 11 '18 at 03:13