Skip to content

Instantly share code, notes, and snippets.

@Collonville
Created July 13, 2021 07:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Collonville/fd2834633ba55aaa0bec402d893e6f89 to your computer and use it in GitHub Desktop.
Save Collonville/fd2834633ba55aaa0bec402d893e6f89 to your computer and use it in GitHub Desktop.
video bytes to numpy array using ffmpeg command
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