kkroening/ffmpeg-python

Input as bytes not working

avpodtikhov opened this issue · 2 comments

I am trying to use bytes as input and output with the following command:

process = (
    ffmpeg.input("pipe:")
    .output(
        "pipe:",
        format='wav',
        acodec='pcm_s16le',
        ac=1,
        ar=8000,
    )
    .overwrite_output()
    .run_async(pipe_stdin=True, pipe_stdout=True, pipe_stderr=True)
)
audio, _ = process.communicate(input=audio_raw)

And getting the following logs:

ffmpeg version 4.2.7-0ubuntu0.1 Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
  configuration: --prefix=/usr --extra-version=0ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x55c7d4e90740] stream 0, offset 0x2c: partial file
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'pipe:':
  Metadata:
    major_brand     : M4A 
    minor_version   : 0
    compatible_brands: M4A isommp42
    creation_time   : 2023-04-29T00:53:21.000000Z
    title           : улица Скворцова-Степанова, 83А 25
    voice-memo-uuid : E12AF33C-0AD8-4C80-9007-C66C0803B028
    encoder         : com.apple.VoiceMemos (MacBook Pro — Artur (null))
  Duration: 00:00:03.80, bitrate: N/A
    Stream #0:0(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 86 kb/s (default)
    Metadata:
      creation_time   : 2023-04-29T00:53:21.000000Z
      handler_name    : Core Media Audio
Stream mapping:
  Stream #0:0 -> #0:0 (aac (native) -> pcm_s16le (native))
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x55c7d4e90740] stream 0, offset 0x2c: partial file
pipe:: Invalid data found when processing input
Output #0, wav, to 'pipe:':
  Metadata:
    major_brand     : M4A 
    minor_version   : 0
    compatible_brands: M4A isommp42
    voice-memo-uuid : E12AF33C-0AD8-4C80-9007-C66C0803B028
    INAM            : улица Скворцова-Степанова, 83А 25
    ISFT            : Lavf58.29.100
    Stream #0:0(und): Audio: pcm_s16le ([1][0][0][0] / 0x0001), 8000 Hz, mono, s16, 128 kb/s (default)
    Metadata:
      creation_time   : 2023-04-29T00:53:21.000000Z
      handler_name    : Core Media Audio
      encoder         : Lavc58.54.100 pcm_s16le
size=       0kB time=00:00:00.00 bitrate=N/A speed=   0x    
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used)

As long as I change ffmpeg.input("pipe:") to ffmpeg.input(path_to_m4a_file) everything is OK, so also if the input file is in wav format

Read up on m4a formats, as far as I read, pipes are not supported for m4a in ffmpeg in general

I couldn't find a solution, I had to save the file before using ffmpeg