Search code examples
pythonffmpegffmpeg-python

use BytesIO into python-ffmpeg or other


Hello I have the following poc to develop

Given two S3 paths, origin and destination, I need to download from origin apply a conversion and upload to destination.

The idea is not to use a temporary local folder and use stream data ur another better option if you know.

In order to do this I have the following code:

import ffmpeg
import boto3
from io import BytesIO

origin = 'ah/a.mkv'
destination = 'av/a.mp4'

s3_client = boto3.client('s3')

f = BytesIO()
s3_client.download_fileobj('bucket', origin, f)

stream = ffmpeg.input(f)
stream = ffmpeg.output(stream, 'a.mp4', codec='copy')

(stream.run())

The problem is that

Input doesn' this library looks like that this operation is not possible.

https://kkroening.github.io/ffmpeg-python/

TypeError: expected str, bytes or os.PathLike object, not _io.BytesIO

But when another library like

https://github.com/aminyazdanpanah/python-ffmpeg-video-streaming#opening-a-resource

I don't know how do the conversion too.

So do you know any way of do this?

Thanks


Solution

  • Finnaly the library works with

    s3_client = boto3.client('s3')
    
    f = BytesIO()
    s3_client.download_fileobj('bucket', 'path', f)
    
    process = (
        ffmpeg
        .input('pipe:') \
        .output('aa.mp4') \
        .overwrite_output() \
        .run_async(pipe_stdin=True) \
    )
    
    process.communicate(input=f.getbuffer())