0

I need to convert audio inside video to 8 Bit signed PCM. I try it like this:

C:\Users\E\Desktop\ffmpeg-20160731-04da20e-win32-static\bin>ffmpeg -i minions.mp4 -vcodec mjpeg -s 800x480 -acodec pcm_s8 -ac 1 out.avi

output:

ffmpeg version N-81192-g04da20e Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 5.4.0 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-lib
ebur128 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfree
type --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-lib
openjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame
 --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-
libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib
  libavutil      55. 28.100 / 55. 28.100
  libavcodec     57. 51.100 / 57. 51.100
  libavformat    57. 44.100 / 57. 44.100
  libavdevice    57.  0.102 / 57.  0.102
  libavfilter     6. 49.100 /  6. 49.100
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  1.100 /  2.  1.100
  libpostproc    54.  0.100 / 54.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'minions.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2016-03-17 10:06:57
  Duration: 00:03:18.72, start: 0.000000, bitrate: 1869 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 1675 kb/s, 23.98 fps, 23.98 tbr, 24k tbn, 47.95 tbc (default
)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 192 kb/s (default)
    Metadata:
      creation_time   : 2016-03-17 10:06:58
      handler_name    : IsoMedia File Produced by Google, 5-11-2011
[swscaler @ 04821880] deprecated pixel format used, make sure you did set range correctly
[avi @ 048c0460] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
    Last message repeated 1 times
Output #0, avi, to 'out.avi':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    encoder         : Lavf57.44.100
    Stream #0:0(und): Video: mjpeg (MJPG / 0x47504A4D), yuvj420p(pc), 800x480 [SAR 16:15 DAR 16:9], q=2-31, 200 kb/s, 23.98 fps, 23.98 tbn, 23.98 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      encoder         : Lavc57.51.100 mjpeg
    Side data:
      cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
    Stream #0:1(und): Audio: pcm_s8, 44100 Hz, mono, u8, 352 kb/s (default)
    Metadata:
      creation_time   : 2016-03-17 10:06:58
      handler_name    : IsoMedia File Produced by Google, 5-11-2011
      encoder         : Lavc57.51.100 pcm_s8
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> mjpeg (native))
  Stream #0:1 -> #0:1 (aac (native) -> pcm_s8 (native))
Could not write header for output file #0 (incorrect codec parameters ?): Operation not permitted

ffmpeg can not write a header for output file. I want to mention that if audio encoder is selected to pcm_u8 everything works fine.

C:\Users\E\Desktop\ffmpeg-20160731-04da20e-win32-static\bin>ffmpeg -i minions.mp4 -vcodec mjpeg -s 800x480 -acodec pcm_u8 -ac 1 out.avi

output:

ffmpeg version N-81192-g04da20e Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 5.4.0 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-lib
ebur128 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfree
type --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-lib
openjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame
 --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-
libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib
  libavutil      55. 28.100 / 55. 28.100
  libavcodec     57. 51.100 / 57. 51.100
  libavformat    57. 44.100 / 57. 44.100
  libavdevice    57.  0.102 / 57.  0.102
  libavfilter     6. 49.100 /  6. 49.100
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  1.100 /  2.  1.100
  libpostproc    54.  0.100 / 54.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'minions.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2016-03-17 10:06:57
  Duration: 00:03:18.72, start: 0.000000, bitrate: 1869 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 1675 kb/s, 23.98 fps, 23.98 tbr, 24k tbn, 47.95 tbc (default
)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 192 kb/s (default)
    Metadata:
      creation_time   : 2016-03-17 10:06:58
      handler_name    : IsoMedia File Produced by Google, 5-11-2011
File 'out.avi' already exists. Overwrite ? [y/N] y
[swscaler @ 030a1880] deprecated pixel format used, make sure you did set range correctly
[avi @ 04a10460] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
    Last message repeated 1 times
Output #0, avi, to 'out.avi':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    ISFT            : Lavf57.44.100
    Stream #0:0(und): Video: mjpeg (MJPG / 0x47504A4D), yuvj420p(pc), 800x480 [SAR 16:15 DAR 16:9], q=2-31, 200 kb/s, 23.98 fps, 23.98 tbn, 23.98 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      encoder         : Lavc57.51.100 mjpeg
    Side data:
      cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
    Stream #0:1(und): Audio: pcm_u8 ([1][0][0][0] / 0x0001), 44100 Hz, mono, u8, 352 kb/s (default)
    Metadata:
      creation_time   : 2016-03-17 10:06:58
      handler_name    : IsoMedia File Produced by Google, 5-11-2011
      encoder         : Lavc57.51.100 pcm_u8
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> mjpeg (native))
  Stream #0:1 -> #0:1 (aac (native) -> pcm_u8 (native))
Press [q] to stop, [?] for help
frame= 4764 fps=250 q=24.8 Lsize=   74247kB time=00:03:18.71 bitrate=3060.8kbits/s speed=10.4x
video:65364kB audio:8558kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.438745%

What is the problem ? Why conversion does not work for signed pcm ?

Encoders for both unsigned and signed pcm are avaible:

C:\Users\E\Desktop\ffmpeg-20160731-04da20e-win32-static\bin>ffmpeg -encoders

 .
 .
 A..... pcm_f32be            PCM 32-bit floating point big-endian
 A..... pcm_f32le            PCM 32-bit floating point little-endian
 A..... pcm_f64be            PCM 64-bit floating point big-endian
 A..... pcm_f64le            PCM 64-bit floating point little-endian
 A..... pcm_mulaw            PCM mu-law / G.711 mu-law
 A..... pcm_s16be            PCM signed 16-bit big-endian
 A..... pcm_s16be_planar     PCM signed 16-bit big-endian planar
 A..... pcm_s16le            PCM signed 16-bit little-endian
 A..... pcm_s16le_planar     PCM signed 16-bit little-endian planar
 A..... pcm_s24be            PCM signed 24-bit big-endian
 A..... pcm_s24daud          PCM D-Cinema audio signed 24-bit
 A..... pcm_s24le            PCM signed 24-bit little-endian
 A..... pcm_s24le_planar     PCM signed 24-bit little-endian planar
 A..... pcm_s32be            PCM signed 32-bit big-endian
 A..... pcm_s32le            PCM signed 32-bit little-endian
 A..... pcm_s32le_planar     PCM signed 32-bit little-endian planar
 A..... pcm_s8               PCM signed 8-bit
 A..... pcm_s8_planar        PCM signed 8-bit planar
 A..... pcm_u16be            PCM unsigned 16-bit big-endian
 A..... pcm_u16le            PCM unsigned 16-bit little-endian
 A..... pcm_u24be            PCM unsigned 24-bit big-endian
 A..... pcm_u24le            PCM unsigned 24-bit little-endian
 A..... pcm_u32be            PCM unsigned 32-bit big-endian
 A..... pcm_u32le            PCM unsigned 32-bit little-endian
 A..... pcm_u8               PCM unsigned 8-bit
 .
 .
patszn
  • 11
  • 1
  • 3

3 Answers3

0

Your error not about audio, it's about video:

[swscaler @ 04821880] deprecated pixel format used, make sure you did set range correctly
[avi @ 048c0460] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
    Last message repeated 1 times

I think you can try to set pixel format as it asking. it could solve it.

I want to mention that if audio encoder is selected to pcm_u8 everything works fine.

Please, place the command for this convertion and the output (averything before 'stream mapping' including it) in your qustion by editing it.

Ngoral
  • 4,215
  • 2
  • 20
  • 37
  • As you can see it works for unsigned pcm even though warnings (piexel format, and avstream.codec) are still there. I will try to set pixel format corretly, first I have to find out how to do it :P – patszn Aug 01 '16 at 10:58
0

The RIFF function called by the AVI muxer does not support writing a tag for PCM_S8 streams, so apparently that's why you can't write it to AVIs or WAVs.

You can use MOV or NUT formats.

If you need to use AVI, you are left with S16LE, S24LE, S32LE, F32LE, F64LE and U8 variants of LPCM.


To encode using IMA ADPCM, use

ffmpeg -i minions.mp4 -c:v mjpeg -s 800x480 -c:a adpcm_ima_wav -ac 1 out.avi

To encode using mu-law PCM, use

ffmpeg -i minions.mp4 -c:v mjpeg -s 800x480 -c:a pcm_mulaw -ac 1 out.avi
Gyan
  • 85,394
  • 9
  • 169
  • 201
  • Thank you. Do you have any ideas how can I achieve one of these formats: 4 Bit IMA ADPCM, 8 Bit signed PCM, 8 Bit u-Law in AVI mjpeg-encoded videos? I need it, because the chip I'm using for diplaying video (FT810) can not handle other ones.. "For the audio data encoded into MJPEG-encoded AVI video , three formats are supported: 4 Bit IMA ADPCM, 8 Bit signed PCM, 8 Bit u-Law" It only supports MJPEG AVI of course. – patszn Aug 01 '16 at 13:16
0

My company is building a device using the FT810 and this is the conversion script I have come up with:

AUDIO_SAMPLE_RATE=8000
VIDEO_FRAME_RATE=8

VIDEO_Y_POS=266 # Place video in 2/3rds up from bottom of screen

ffmpeg -i source/audio.mp3 -r 65535/2733 -vn -c:a libmp3lame -ar $AUDIO_SAMPLE_RATE -ac 1 -ab 128k -y /tmp/resampled.mp3

ffmpeg -i source/video.gif \
       -i /tmp/resampled.mp3  \
       -filter:v scale=420:-2,pad=420:270+ih/2:0:270-ih/2:black \
       -pix_fmt yuvj420p -vcodec mjpeg -acodec pcm_s16le -r:v $VIDEO_FRAME_RATE -b:v 0.1M -ac 1 -shortest -y output/startup.avi

Notice that I am using pcm_s16le, because the documentation says "16 Bit PCM is partially supported by dropping off less significant 8 bits in each audio sample."

marcio-ao
  • 11
  • 4