0

I have the following code to get the bytes representing the data stream of a .ts video:

def get_datastream_bytes(mpeg_ts_filepath):
    ffmpeg_command = [
        'ffmpeg', '-hide_banner', '-loglevel', 'quiet',
        '-i', mpeg_ts_filepath,
        '-map', '0:d',
        '-c', 'copy',
        '-copy_unknown',
        '-f', 'data',
        'pipe:1'
    ]

    try:
        output_bytes = subprocess.check_output(ffmpeg_command, stderr=subprocess.STDOUT)
        print("Output bytes length:", len(output_bytes))
        return output_bytes
    except subprocess.CalledProcessError as e:
        print("Error:", e.output)

I can then wrap the returned value in io.BytesIO and parse the resulting bytes using another library (klvdata).

This code was fashioned upon a ffmpeg CLI command I adapted from this SO Answer.

ffmpeg -i "C:\inputfile.ts" -map 0:d -c copy -copy_unknown -f:d data pipe:1

What I would really like to do is utilize the Python ffmpeg bindings in ffmpeg-python so that users do not have to install ffmpeg locally. Thus, I have attempted to get a bytes stream from an ffmpeg call like so:

bytestream = (
    ffmpeg.input(input_file)
        .output("pipe:", format="data", codec="copy", copy_unknown=True)
        .run(capture_stdout=True)
)

Though, this and many other, attempts at utilizing ffmpeg-python generally end with the same error:

Output #0, data, to 'True': [out#0/data @ 00000...] Output file does not contain any stream Error opening output file True. Error opening output files: Invalid argument Traceback (most recent call last): ... raise Error('ffmpeg', out, err) ffmpeg._run.Error: ffmpeg error (see stderr output for detail)


How do I convert the ffmpeg CLI command

ffmpeg -i "C:\inputfile.ts" -map 0:d -c copy -copy_unknown -f:d data pipe:1

To an ffmpeg-python call?

kdeckerr
  • 1
  • 1
  • You have to map the data stream explicitly (`-map 0:d`). See https://github.com/kkroening/ffmpeg-python/issues/420 for syntax guidance. – Gyan Aug 29 '23 at 04:06

0 Answers0