Created
July 13, 2021 07:43
-
-
Save Collonville/fd2834633ba55aaa0bec402d893e6f89 to your computer and use it in GitHub Desktop.
video bytes to numpy array using ffmpeg command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import shlex | |
import subprocess | |
import tempfile | |
import numpy as np | |
with tempfile.NamedTemporaryFile() as t: | |
t.write(encoded) | |
t.flush() | |
ffmpeg_command = f"ffmpeg -y -i {t.name} -pix_fmt rgb24 -f rawvideo pipe:1" | |
ffmpeg_process = subprocess.Popen( | |
shlex.split(ffmpeg_command), | |
stdin=subprocess.PIPE, | |
stdout=subprocess.PIPE, | |
# stderr=subprocess.PIPE, | |
) | |
output_bytes = ffmpeg_process.communicate(input=encoded)[0] | |
video = np.frombuffer(output_bytes, dtype=np.uint8) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment