Search code examples
ffmpegmp4codecflvvideo-encoding

FFMPEG error while converting flv1 (flv) -> h264 (libx264)


I am trying to covert flv format video to h264 codec with mp4 format video, but am facing the following error:

Command I executed:

ffmpeg -i input_video.flv -c:v libx264 output.mp4

Error: Error while opening encoder for output stream #0:1 - maybe incorrect parameters such as bit_rate, rate, width or height

Logs:

ffmpeg version 2.7.2 Copyright (c) 2000-2015 the FFmpeg developers
  built with Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/2.7.2 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --enable-opencl --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid --enable-vda
  libavutil      54. 27.100 / 54. 27.100
  libavcodec     56. 41.100 / 56. 41.100
  libavformat    56. 36.100 / 56. 36.100
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 16.101 /  5. 16.101
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  2.100 /  1.  2.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, flv, from 'input.flv':
  Metadata:
    encoder         : Lavf53.24.2
  Duration: 00:00:53.32, start: 0.000000, bitrate: 787 kb/s
    Stream #0:0: Video: flv1, yuv420p, 320x240, 500 kb/s, 25 fps, 25 tbr, 1k tbn, 1k tbc
    Stream #0:1: Audio: aac (LC), 48000 Hz, 5.1, fltp, 384 kb/s
[libx264 @ 0x7ff885000c00] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 @ 0x7ff885000c00] profile High, level 1.3
[libx264 @ 0x7ff885000c00] 264 - core 144 r2533 c8a773e - H.264/MPEG-4 AVC codec - Copyleft 2003-2015 - 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
[libvo_aacenc @ 0x7ff885001e00] Unable to set encoding parameters
Output #0, mp4, to 'output1.mp4':
  Metadata:
    encoder         : Lavf53.24.2
    Stream #0:0: Video: h264 (libx264), yuv420p, 320x240, q=-1--1, 25 fps, 25 tbn, 25 tbc
    Metadata:
      encoder         : Lavc56.41.100 libx264
    Stream #0:1: Audio: aac, 0 channels, 128 kb/s
    Metadata:
      encoder         : Lavc56.41.100 libvo_aacenc
Stream mapping:
  Stream #0:0 -> #0:0 (flv1 (flv) -> h264 (libx264))
  Stream #0:1 -> #0:1 (aac (native) -> aac (libvo_aacenc))
Error while opening encoder for output stream #0:1 - maybe incorrect parameters such as bit_rate, rate, width or height

What could be the reason for this ?


Solution

  • Update: Based on the console output now included in the Q, the error has nothing to do with the video, but I'll leave my earlier answer below in case anyone finding this question does get the same error from the video encoder.

    The error is being reported by the 3rd party AAC encoder, which is now obsolete, and only supports two channels.

    There are three ways to tackle this:

    #1 Copy audio stream over

    ffmpeg -i input.flv -c:a copy output.mp4
    

    #2 Upgrade to recent FFmpeg and run original command in the question

    #3 Re-encode using current binary and old encoder (least recommended)

    ffmpeg -i input.flv -ac 2 -b:a 128k -strict -2 output.mp4
    

    Older answer: Most common reason for this error is that the dimensions aren't a multiple of two, and FFmpeg is outputting using pixel encoding YUV420P which requires them to be.

    Try

    ffmpeg -i input.flv -vf "scale=2*trunc(iw/2):-2" output.mp4
    

    The scale filter makes both the dimensions even.