ffmpeg changes audio bitrate when transcoding from MKV to FLV

1

I have one file - sample.mkv

=========================================================
               File: sample.mkv
              Width: 854 pixels
             Height: 480 pixels
       Aspect ratio: 1.77:1
             Frames: 0
           Duration: 00:00:33 hours/mins/secs
          Framerate: 25.000 frames per second
       Video format: H264
      Video bitrate: 0 bits per second
---------------------------
Audio track 1 (Stream 0.1, AID 0):
---------------------------
              Codec: pcm_s16le
            Bitrate: 4233000 bits per second
      Sampling rate: 44100 Hz
=========================================================

I want to recode it in FLV container via ffmpeg:

$ ffmpeg -i sample.mkv -b:a 4233k -c:v h264 -c:a pcm_s16le sample.flv

but I received:

=========================================================
               File: sample.flv
              Width: 854 pixels
             Height: 480 pixels
       Aspect ratio: 1.77:1
             Frames: 0
           Duration: 00:00:33 hours/mins/secs
          Framerate: 25.000 frames per second
       Video format: H264
      Video bitrate: 0 bits per second
---------------------------
Audio track 1 (Stream 0.1, AID 0):
---------------------------
              Codec: pcm_s16le
            Bitrate: 1411000 bits per second
      Sampling rate: 44100 Hz
=========================================================

Why does the bitrate go 4233000 -> 1411000?
In this regard the sound turns out very bad :(

UPDATE full log

ffmpeg -i sample.mkv -b:a 4233k -c:v h264 -c:a pcm_s16le sample.flv
ffmpeg version 2.6.2 Copyright (c) 2000-2015 the FFmpeg developers
  built with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
  configuration: --prefix=/opt/ffmpeg --libdir=/opt/ffmpeg/lib/ --enable-shared --enable-avresample --disable-stripping --enable-gpl --enable-version3 --enable-nonfree --enable-runtime-cpudetect --build-suffix=.ffmpeg --enable-postproc --enable-x11grab --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libdc1394 --enable-libfaac --enable-libfdk_aac --enable-libflite --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopus --enable-libpulse --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libvo-aacenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-openal --enable-opengl --enable-pthreads --enable-vaapi --enable-vdpau --enable-zlib --enable-debug=3
  libavutil      54. 20.100 / 54. 20.100
  libavcodec     56. 26.100 / 56. 26.100
  libavformat    56. 25.101 / 56. 25.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 11.102 /  5. 11.102
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Guessed Channel Layout for  Input Stream #0.1 : 5.1
Input #0, matroska,webm, from 'sample.mkv':
  Metadata:
    MINOR_VERSION   : 512
    COMPATIBLE_BRANDS: qt  
    MAJOR_BRAND     : qt  
    ENCODER         : Lavf56.25.101
  Duration: 00:00:33.08, start: 0.080000, bitrate: 4691 kb/s
    Stream #0:0(eng): Video: h264 (High), yuv420p, 854x480 [SAR 1:1 DAR 427:240], 25 fps, 25 tbr, 1k tbn, 50 tbc (default)
    Metadata:
      LANGUAGE        : eng
      HANDLER_NAME    : DataHandler
      ENCODER         : Lavc56.26.100 libx264
    Stream #0:1(eng): Audio: pcm_s16le, 44100 Hz, 6 channels, s16, 4233 kb/s (default)
    Metadata:
      LANGUAGE        : eng
      HANDLER_NAME    : DataHandler
      ENCODER         : Lavc56.26.100 pcm_s16le
[libx264 @ 0x914de0] using SAR=1/1
[libx264 @ 0x914de0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x914de0] profile High, level 3.0
[libx264 @ 0x914de0] 264 - core 142 r2389 956c8d8 - H.264/MPEG-4 AVC codec - Copyleft 2003-2014 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, flv, to 'sample.flv':
  Metadata:
    MINOR_VERSION   : 512
    COMPATIBLE_BRANDS: qt  
    MAJOR_BRAND     : qt  
    encoder         : Lavf56.25.101
    Stream #0:0(eng): Video: h264 (libx264) ([7][0][0][0] / 0x0007), yuv420p, 854x480 [SAR 1:1 DAR 427:240], q=-1--1, 25 fps, 1k tbn, 25 tbc (default)
    Metadata:
      LANGUAGE        : eng
      HANDLER_NAME    : DataHandler
      encoder         : Lavc56.26.100 libx264
    Stream #0:1(eng): Audio: pcm_s16le ([3][0][0][0] / 0x0003), 44100 Hz, 5.1, s16, 4233 kb/s (default)
    Metadata:
      LANGUAGE        : eng
      HANDLER_NAME    : DataHandler
      encoder         : Lavc56.26.100 pcm_s16le
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (pcm_s16le (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
frame=  812 fps= 93 q=-1.0 Lsize=   18938kB time=00:00:33.00 bitrate=4700.7kbits/s    
video:1841kB audio:17056kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.214361%
[libx264 @ 0x914de0] frame I:23    Avg QP:16.97  size: 20207
[libx264 @ 0x914de0] frame P:294   Avg QP:20.61  size:  3904
[libx264 @ 0x914de0] frame B:495   Avg QP:23.24  size:   550
[libx264 @ 0x914de0] consecutive B-frames: 15.0%  7.9%  9.6% 67.5%
[libx264 @ 0x914de0] mb I  I16..4: 34.6% 45.1% 20.3%
[libx264 @ 0x914de0] mb P  I16..4:  3.5% 12.4%  0.8%  P16..4: 19.1%  5.7%  2.4%  0.0%  0.0%    skip:56.0%
[libx264 @ 0x914de0] mb B  I16..4:  0.4%  0.4%  0.1%  B16..8: 12.5%  1.0%  0.1%  direct: 0.5%  skip:85.1%  L0:43.1% L1:50.9% BI: 5.9%
[libx264 @ 0x914de0] 8x8 transform intra:64.0% inter:75.7%
[libx264 @ 0x914de0] coded y,uvDC,uvAC intra: 33.0% 43.7% 13.4% inter: 4.1% 6.8% 1.0%
[libx264 @ 0x914de0] i16 v,h,dc,p: 53% 22%  9% 16%
[libx264 @ 0x914de0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 27% 21% 27%  3%  5%  4%  5%  4%  4%
[libx264 @ 0x914de0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 28% 20% 12%  5%  7%  9%  6%  8%  5%
[libx264 @ 0x914de0] i8c dc,h,v,p: 62% 20% 14%  5%
[libx264 @ 0x914de0] Weighted P-Frames: Y:32.0% UV:30.6%
[libx264 @ 0x914de0] ref P L0: 72.5% 16.1%  8.0%  3.3%  0.1%
[libx264 @ 0x914de0] ref B L0: 86.4% 11.6%  2.0%
[libx264 @ 0x914de0] ref B L1: 95.1%  4.9%
[libx264 @ 0x914de0] kb/s:464.26

UPDATE 2:

ffmpeg -i sample.mkv -ac 6 -c copy sample.flv
ffmpeg version 2.6.2 Copyright (c) 2000-2015 the FFmpeg developers
  built with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
  configuration: --prefix=/opt/ffmpeg --libdir=/opt/ffmpeg/lib/ --enable-shared --enable-avresample --disable-stripping --enable-gpl --enable-version3 --enable-nonfree --enable-runtime-cpudetect --build-suffix=.ffmpeg --enable-postproc --enable-x11grab --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libdc1394 --enable-libfaac --enable-libfdk_aac --enable-libflite --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopus --enable-libpulse --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libvo-aacenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-openal --enable-opengl --enable-pthreads --enable-vaapi --enable-vdpau --enable-zlib --enable-debug=3
  libavutil      54. 20.100 / 54. 20.100
  libavcodec     56. 26.100 / 56. 26.100
  libavformat    56. 25.101 / 56. 25.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 11.102 /  5. 11.102
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Guessed Channel Layout for  Input Stream #0.1 : 5.1
Input #0, matroska,webm, from 'sample.mkv':
  Metadata:
    MINOR_VERSION   : 512
    COMPATIBLE_BRANDS: qt  
    MAJOR_BRAND     : qt  
    ENCODER         : Lavf56.25.101
  Duration: 00:00:33.08, start: 0.080000, bitrate: 4691 kb/s
    Stream #0:0(eng): Video: h264 (High), yuv420p, 854x480 [SAR 1:1 DAR 427:240], 25 fps, 25 tbr, 1k tbn, 50 tbc (default)
    Metadata:
      LANGUAGE        : eng
      HANDLER_NAME    : DataHandler
      ENCODER         : Lavc56.26.100 libx264
    Stream #0:1(eng): Audio: pcm_s16le, 44100 Hz, 6 channels, s16, 4233 kb/s (default)
    Metadata:
      LANGUAGE        : eng
      HANDLER_NAME    : DataHandler
      ENCODER         : Lavc56.26.100 pcm_s16le
Output #0, flv, to 'sample.flv':
  Metadata:
    MINOR_VERSION   : 512
    COMPATIBLE_BRANDS: qt  
    MAJOR_BRAND     : qt  
    encoder         : Lavf56.25.101
    Stream #0:0(eng): Video: h264 ([7][0][0][0] / 0x0007), yuv420p, 854x480 [SAR 1:1 DAR 427:240], q=2-31, 25 fps, 25 tbr, 1k tbn, 1k tbc (default)
    Metadata:
      LANGUAGE        : eng
      HANDLER_NAME    : DataHandler
      ENCODER         : Lavc56.26.100 libx264
    Stream #0:1(eng): Audio: pcm_s16le ([3][0][0][0] / 0x0003), 44100 Hz, 5.1, 4233 kb/s (default)
    Metadata:
      LANGUAGE        : eng
      HANDLER_NAME    : DataHandler
      ENCODER         : Lavc56.26.100 pcm_s16le
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame=  812 fps=0.0 q=-1.0 Lsize=   18968kB time=00:00:33.00 bitrate=4708.2kbits/s    
video:1872kB audio:17056kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.214011%

Dima00782

Posted 2015-05-03T10:23:24.910

Reputation: 13

have you tried using avconv instead of ffmpeg? It was forked from ffmpeg and these days it is (I think) more widely used and supported... – gogoud – 2015-05-03T11:01:48.250

@gogoud That's absolutely not true. FFmpeg is actively developed and used. In fact, Ubuntu switched back to ffmpeg again. Please read this.

– slhck – 2015-05-03T11:54:18.487

Please show the full, uncut command line output from from the conversion. Does it actually sound bad or are you just worried about the bitrate value? – slhck – 2015-05-03T11:56:33.613

gogoud, yes, I try avconv - same result – Dima00782 – 2015-05-03T11:58:46.950

slhck, I worry about sound quality and I want convert my mkv file in flv without any transcoding, only repack container mkv -> flv with same audio and video – Dima00782 – 2015-05-03T12:02:55.567

@slhck thanks for that info, it was news to me, I stand corrected... – gogoud – 2015-05-03T12:04:48.403

Answers

2

As far as I can tell, the FLV format does not officially support uncompressed audio in PCM format (see the spec). However, you can still multiplex PCM audio into FLV with ffmpeg. There seems to be a bug or incompatibility with ffplay not playing the audio correctly, but it works for me in VLC:

ffmpeg -i sample.mkv -c copy sample.flv

If you want to be more compatible with other players, you may want to restrict the audio to two channels. To do that:

ffmpeg -i sample.mkv -c:v copy -c:a pcm_s16le -ac 2 sample.flv

This will reduce the number of audio channels, but they will not lose any quality. The bitrate will look lower, but it's fewer channels.

Your other choices are AAC audio or MP3 audio:

ffmpeg -i sample.mkv -c:v copy -c:a aac -strict experimental -b:a 128k sample.flv
ffmpeg -i sample.mkv -c:v copy -c:a libmp3lame sample.flv

This will automatically convert the multi-channel audio to stereo.

Note that if using MP3 in FLV you will be restricted to the following audio sample rates: 44100, 22050, 11025. This can be set with the -ar option or aresample filter.

slhck

Posted 2015-05-03T10:23:24.910

Reputation: 182 472

Try "ffmpeg -i sample.mkv -c copy sample.flv" - same result, audio is bad and with 1411000 bitrate, "ffmpeg -i sample.mkv -ac 6 -c copy sample.flv" unfortunately works similarly – Dima00782 – 2015-05-03T12:48:44.063

Can you supply a sample file? – slhck – 2015-05-03T13:30:16.080

yes of course http://dropmefiles.com/tx3em

– Dima00782 – 2015-05-03T13:53:40.910

I checked; simply copying works fine with VLC as a player, but not with ffplay. The audio is distorted and too slow with ffplay. – slhck – 2015-05-03T15:25:09.777