ffmpeg-python
ffmpeg-python copied to clipboard
Bytes to video
Hello,
I am using the following snippet to convert a video to bytes:
process = (
ffmpeg
.input(INPUT)
.output('-', format='h264')
.run_async(pipe_stdout=True)
)
while True:
packet = process.stdout.read(4096)
if not packet:
break
print(packet)
my plan is to send it through a socket to a server, rebuild the video and save it to a file.
I am lacking the second part, is it possible to get the bytes and generate the video with this library?
Thanks.
Are you sure you need FFmpeg for that? You could read bytes directly from the file:
PACKET_SIZE = 100 # number of bytes, could be any number
with open("video.mp4", "rb") as fp:
packet = fp.read(PACKET_SIZE)
while True:
if len(packet) == 0:
break
print(packet)
packet = fp.read(PACKET_SIZE)
Are you sure you need FFmpeg for that? You could read bytes directly from the file:
PACKET_SIZE = 100 # number of bytes, could be any number with open("video.mp4", "rb") as fp: packet = fp.read(PACKET_SIZE) while True: if len(packet) == 0: break print(packet) packet = fp.read(PACKET_SIZE)
Hi,
thanks for the reply but this code solves an issue that I already solved, I am more looking into making these bytes into a video using ffmpeg.
@ginwakeup Have you solved the issue?