Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

ffmpeg.py 1.7 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
  1. import json
  2. import subprocess
  3. from typing import Union
  4. def run(args, pipe_stdin=False, pipe_stdout=False, pipe_stderr=False, quiet_stderr=False) -> Union[subprocess.Popen,None]:
  5. """
  6. run ffmpeg process
  7. returns Popen class if success
  8. otherwise None
  9. """
  10. args = ['ffmpeg'] + args
  11. stdin_stream = subprocess.PIPE if pipe_stdin else None
  12. stdout_stream = subprocess.PIPE if pipe_stdout else None
  13. stderr_stream = subprocess.PIPE if pipe_stderr else None
  14. if quiet_stderr and not pipe_stderr:
  15. stderr_stream = subprocess.DEVNULL
  16. try:
  17. return subprocess.Popen(args, stdin=stdin_stream, stdout=stdout_stream, stderr=stderr_stream)
  18. except Exception as e:
  19. print('ffmpeg exception: ', e)
  20. return None
  21. def probe(filename):
  22. """Run ffprobe on the specified file and return a JSON representation of the output.
  23. Raises:
  24. Exception if ffprobe returns a non-zero exit code,
  25. """
  26. args = ['ffprobe', '-show_format', '-show_streams', '-of', 'json', filename]
  27. p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  28. out, err = p.communicate()
  29. if p.returncode != 0:
  30. raise Exception('ffprobe', out, err)
  31. return json.loads(out.decode('utf-8'))
  32. def probe(filename):
  33. """Run ffprobe on the specified file and return a JSON representation of the output.
  34. Raises:
  35. Exception if ffprobe returns a non-zero exit code,
  36. """
  37. args = ['ffprobe', '-show_format', '-show_streams', '-of', 'json', filename]
  38. #'-count_frames',
  39. p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  40. out, err = p.communicate()
  41. if p.returncode != 0:
  42. raise Exception('ffprobe', out, err)
  43. return json.loads(out.decode('utf-8'))
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...