ffmpeg-python icon indicating copy to clipboard operation
ffmpeg-python copied to clipboard

Bytes to video

Open ginwakeup opened this issue 2 years ago • 2 comments

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.

ginwakeup avatar Jul 14 '22 22:07 ginwakeup

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)

vvsotnikov avatar Jul 18 '22 07:07 vvsotnikov

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 avatar Jul 18 '22 09:07 ginwakeup

@ginwakeup Have you solved the issue?

pooya-mohammadi avatar Feb 09 '23 10:02 pooya-mohammadi