FFmpeg报错:Specified pixel format yuvj420p is invalid or not supported(用ffmpeg程序查看编码器支持像素格式命令)

Posted Dontla

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了FFmpeg报错:Specified pixel format yuvj420p is invalid or not supported(用ffmpeg程序查看编码器支持像素格式命令)相关的知识,希望对你有一定的参考价值。

文章目录

原因

这是因为我们把海康rtsp视频流packet解封装后,它frame的像素格式是yuvj420p(AV_PIX_FMT_YUVJ420P)的,然后我们又指定编码器上下文的像素格式pix_fmt = AV_PIX_FMT_YUVJ420P,指定编码器为AV_CODEC_ID_MPEG4,但是AV_CODEC_ID_MPEG4不支持AV_PIX_FMT_YUVJ420P像素格式,所以报了上述错误

解决办法

ffmpeg -h encoder=mpeg4指令查看编码器支持哪些像素格式

发现:
x264编码器支持yuv420p yuvj420p yuv422p yuvj422p yuv444p yuvj444p nv12 nv16 nv21 yuv420p10le yuv422p10le yuv444p10le nv20le gray gray10le
x265编码器支持yuv420p yuvj420p yuv422p yuvj422p yuv444p yuvj444p gbrp yuv420p10le yuv422p10le yuv444p10le gbrp10le yuv420p12le yuv422p12le yuv444p12le gbrp12le gray gray10le gray12le
mpeg4编码器支持yuv420p

那么解决方法只能是
①将yuvj420p的frame转换成yuv420p的frame,再输入给mpeg4编码器(我不知道ffmpeg有没这个功能。。。)
②换个编码器,比如x264或x265,它们都支持解析yuvj420p,同时能将输出packet的像素格式转换成其他的类型,比如yuv420p

C:\\Users\\Arnold\\source\\repos\\20221114_ffmpeg_compile_test2\\video>ffmpeg -h encoder=libx264
ffmpeg version n4.3.2-162-g4bbcaf7559 Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 9.3-win32 (GCC) 20200320
  configuration: --prefix=/ffbuild/prefix --pkg-config-flags=--static --pkg-config=pkg-config --cross-prefix=x86_64-w64-mingw32- --arch=x86_64 --target-os=mingw32 --enable-gpl --enable-version3 --disable-debug --enable-shared --disable-static --disable-w32threads --enable-pthreads --enable-iconv --enable-zlib --enable-libxml2 --enable-libfreetype --enable-libfribidi --enable-gmp --enable-lzma --enable-fontconfig --enable-opencl --enable-libvmaf --disable-vulkan --enable-libvorbis --enable-amf --enable-libaom --enable-avisynth --enable-libdav1d --enable-libdavs2 --enable-ffnvcodec --enable-cuda-llvm --disable-libglslang --enable-libgme --enable-libass --enable-libbluray --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvpx --enable-libwebp --enable-lv2 --enable-libmfx --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librav1e --enable-librubberband --enable-schannel --enable-sdl2 --enable-libsoxr --enable-libsrt --enable-libtwolame --enable-libvidstab --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libzimg --extra-cflags=-DLIBTWOLAME_STATIC --extra-cxxflags= --extra-ldflags=-pthread --extra-libs=-lgomp
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
Encoder libx264 [libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10]:
    General capabilities: delay threads
    Threading capabilities: auto
    Supported pixel formats: yuv420p yuvj420p yuv422p yuvj422p yuv444p yuvj444p nv12 nv16 nv21 yuv420p10le yuv422p10le yuv444p10le nv20le gray gray10le
libx264 AVOptions:
  -preset            <string>     E..V...... Set the encoding preset (cf. x264 --fullhelp) (default "medium")
  -tune              <string>     E..V...... Tune the encoding params (cf. x264 --fullhelp)
  -profile           <string>     E..V...... Set profile restrictions (cf. x264 --fullhelp)
  -fastfirstpass     <boolean>    E..V...... Use fast settings when encoding first pass (default true)
  -level             <string>     E..V...... Specify level (as defined by Annex A)
  -passlogfile       <string>     E..V...... Filename for 2 pass stats
  -wpredp            <string>     E..V...... Weighted prediction for P-frames
  -a53cc             <boolean>    E..V...... Use A53 Closed Captions (if available) (default true)
  -x264opts          <string>     E..V...... x264 options
  -crf               <float>      E..V...... Select the quality for constant quality mode (from -1 to FLT_MAX) (default -1)
  -crf_max           <float>      E..V...... In CRF mode, prevents VBV from lowering quality beyond this point. (from -1 to FLT_MAX) (default -1)
  -qp                <int>        E..V...... Constant quantization parameter rate control method (from -1 to INT_MAX) (default -1)
  -aq-mode           <int>        E..V...... AQ method (from -1 to INT_MAX) (default -1)
     none            0            E..V......
     variance        1            E..V...... Variance AQ (complexity mask)
     autovariance    2            E..V...... Auto-variance AQ
     autovariance-biased 3            E..V...... Auto-variance AQ with bias to dark scenes
  -aq-strength       <float>      E..V...... AQ strength. Reduces blocking and blurring in flat and textured areas. (from -1 to FLT_MAX) (default -1)
  -psy               <boolean>    E..V...... Use psychovisual optimizations. (default auto)
  -psy-rd            <string>     E..V...... Strength of psychovisual optimization, in <psy-rd>:<psy-trellis> format.
  -rc-lookahead      <int>        E..V...... Number of frames to look ahead for frametype and ratecontrol (from -1 to INT_MAX) (default -1)
  -weightb           <boolean>    E..V...... Weighted prediction for B-frames. (default auto)
  -weightp           <int>        E..V...... Weighted prediction analysis method. (from -1 to INT_MAX) (default -1)
     none            0            E..V......
     simple          1            E..V......
     smart           2            E..V......
  -ssim              <boolean>    E..V...... Calculate and print SSIM stats. (default auto)
  -intra-refresh     <boolean>    E..V...... Use Periodic Intra Refresh instead of IDR frames. (default auto)
  -bluray-compat     <boolean>    E..V...... Bluray compatibility workarounds. (default auto)
  -b-bias            <int>        E..V...... Influences how often B-frames are used (from INT_MIN to INT_MAX) (default INT_MIN)
  -b-pyramid         <int>        E..V...... Keep some B-frames as references. (from -1 to INT_MAX) (default -1)
     none            0            E..V......
     strict          1            E..V...... Strictly hierarchical pyramid
     normal          2            E..V...... Non-strict (not Blu-ray compatible)
  -mixed-refs        <boolean>    E..V...... One reference per partition, as opposed to one reference per macroblock (default auto)
  -8x8dct            <boolean>    E..V...... High profile 8x8 transform. (default auto)
  -fast-pskip        <boolean>    E..V...... (default auto)
  -aud               <boolean>    E..V...... Use access unit delimiters. (default auto)
  -mbtree            <boolean>    E..V...... Use macroblock tree ratecontrol. (default auto)
  -deblock           <string>     E..V...... Loop filter parameters, in <alpha:beta> form.
  -cplxblur          <float>      E..V...... Reduce fluctuations in QP (before curve compression) (from -1 to FLT_MAX) (default -1)
  -partitions        <string>     E..V...... A comma-separated list of partitions to consider. Possible values: p8x8, p4x4, b8x8, i8x8, i4x4, none, all
  -direct-pred       <int>        E..V...... Direct MV prediction mode (from -1 to INT_MAX) (default -1)
     none            0            E..V......
     spatial         1            E..V......
     temporal        2            E..V......
     auto            3            E..V......
  -slice-max-size    <int>        E..V...... Limit the size of each slice in bytes (from -1 to INT_MAX) (default -1)
  -stats             <string>     E..V...... Filename for 2 pass stats
  -nal-hrd           <int>        E..V...... Signal HRD information (requires vbv-bufsize; cbr not allowed in .mp4) (from -1 to INT_MAX) (default -1)
     none            0            E..V......
     vbr             1            E..V......
     cbr             2            E..V......
  -avcintra-class    <int>        E..V...... AVC-Intra class 50/100/200 (from -1 to 200) (default -1)
  -me_method         <int>        E..V...... Set motion estimation method (from -1 to 4) (default -1)
     dia             0            E..V......
     hex             1            E..V......
     umh             2            E..V......
     esa             3            E..V......
     tesa            4            E..V......
  -motion-est        <int>        E..V...... Set motion estimation method (from -1 to 4) (default -1)
     dia             0            E..V......
     hex             1            E..V......
     umh             2            E..V......
     esa             3            E..V......
     tesa            4            E..V......
  -forced-idr        <boolean>    E..V...... If forcing keyframes, force them as IDR frames. (default false)
  -coder             <int>        E..V...... Coder type (from -1 to 1) (default default)
     default         -1           E..V......
     cavlc           0            E..V......
     cabac           1            E..V......
     vlc             0            E..V......
     ac              1            E..V......
  -b_strategy        <int>        E..V...... Strategy to choose between I/P/B-frames (from -1 to 2) (default -1)
  -chromaoffset      <int>        E..V...... QP difference between chroma and luma (from INT_MIN to INT_MAX) (default -1)
  -sc_threshold      <int>        E..V...... Scene change threshold (from INT_MIN to INT_MAX) (default -1)
  -noise_reduction   <int>        E..V...... Noise reduction (from INT_MIN to INT_MAX) (default -1)
  -x264-params       <dictionary> E..V...... Override the x264 configuration using a :-separated list of key=value parameters


C:\\Users\\Arnold\\source\\repos\\20221114_ffmpeg_compile_test2\\video>ffmpeg -h encoder=libx265
ffmpeg version n4.3.2-162-g4bbcaf7559 Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 9.3-win32 (GCC) 20200320
  configuration: --prefix=/ffbuild/prefix --pkg-config-flags=--static --pkg-config=pkg-config --cross-prefix=x86_64-w64-mingw32- --arch=x86_64 --target-os=mingw32 --enable-gpl --enable-version3 --disable-debug --enable-shared --disable-static --disable-w32threads --enable-pthreads --enable-iconv --enable-zlib --enable-libxml2 --enable-libfreetype --enable-libfribidi --enable-gmp --enable-lzma --enable-fontconfig --enable-opencl --enable-libvmaf --disable-vulkan --enable-libvorbis --enable-amf --enable-libaom --enable-avisynth --enable-libdav1d --enable-libdavs2 --enable-ffnvcodec --enable-cuda-llvm --disable-libglslang --enable-libgme --enable-libass --enable-libbluray --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvpx --enable-libwebp --enable-lv2 --enable-libmfx --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librav1e --enable-librubberband --enable-schannel --enable-sdl2 --enable-libsoxr --enable-libsrt --enable-libtwolame --enable-libvidstab --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libzimg --extra-cflags=-DLIBTWOLAME_STATIC --extra-cxxflags= --extra-ldflags=-pthread --extra-libs=-lgomp
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
Encoder libx265 [libx265 H.265 / HEVC]:
    General capabilities: delay threads
    Threading capabilities: auto
    Supported pixel formats: yuv420p yuvj420p yuv422p yuvj422p yuv444p yuvj444p gbrp yuv420p10le yuv422p10le yuv444p10le gbrp10le yuv420p12le yuv422p12le yuv444p12le gbrp12le gray gray10le gray12le
libx265 AVOptions:
  -crf               <float>      E..V...... set the x265 crf (from -1 to FLT_MAX) (default -1)
  -qp                <int>        E..V...... set the x265 qp (from -1 to INT_MAX) (default -1)
  -forced-idr        <boolean>    E..V...... if forcing keyframes, force them as IDR frames (default false)
  -preset            <string>     E..V...... set the x265 preset
  -tune              <string>     E..V...... set the x265 tune parameter
  -profile           <string>     E..V...... set the x265 profile
  -x265-params       <dictionary> E..V...... set the x265 configuration using a :-separated list of key=value parameters


C:\\Users\\Arnold\\source\\repos\\20221114_ffmpeg_compile_test2\\video>
C:\\Users\\Arnold\\source\\repos\\20221114_ffmpeg_compile_test2\\video>ffmpeg -h encoder=mpeg4
ffmpeg version n4.3.2-162-g4bbcaf7559 Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 9.3-win32 (GCC) 20200320
  configuration: --prefix=/ffbuild/prefix --pkg-config-flags=--static --pkg-config=pkg-config --cross-prefix=x86_64-w64-mingw32- --arch=x86_64 --target-os=mingw32 --enable-gpl --enable-version3 --disable-debug --enable-shared --disable-static --disable-w32threads --enable-pthreads --enable-iconv --enable-zlib --enable-libxml2 --enable-libfreetype --enable-libfribidi --enable-gmp --enable-lzma --enable-fontconfig --enable-opencl --enable-libvmaf --disable-vulkan --enable-libvorbis --enable-amf --enable-libaom --enable-avisynth --enable-libdav1d --enable-libdavs2 --enable-ffnvcodec --enable-cuda-llvm --disable-libglslang --enable-libgme --enable-libass --enable-libbluray --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvpx --enable-libwebp --enable-lv2 --enable-libmfx --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librav1e --enable-librubberband --enable-schannel --enable-sdl2 --enable-libsoxr --enable-libsrt --enable-libtwolame --enable-libvidstab --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libzimg --extra-cflags=-DLIBTWOLAME_STATIC --extra-cxxflags= --extra-ldflags=-pthread --extra-libs=-lgomp
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
Encoder mpeg4 [MPEG-4 part 2]:
    General capabilities: delay threads
    Threading capabilities: slice
    Supported pixel formats: yuv420p
MPEG4 encoder AVOptions:
  -data_partitioning <boolean>    E..V...... Use data partitioning. (default false)
  -alternate_scan    <boolean>    E..V...... Enable alternate scantable. (default false)
  -mpv_flags         <flags>      E..V...... Flags common for all mpegvideo-based encoders. (default 0)
     skip_rd                      E..V...... RD optimal MB level residual skipping
     strict_gop                   E..V...... Strictly enforce gop size
     qp_rd                        E..V...... Use rate distortion optimization for qp selection
     cbp_rd                       E..V...... use rate distortion optimization for CBP
     naq                          E..V...... normalize adaptive quantization
     mv0                          E..V...... always try a mb with mv=<0,0>
  -luma_elim_threshold <int>        E..V...... single coefficient elimination threshold for luminance (negative values also consider dc coefficient) (from INT_MIN to INT_MAX) (default 0)
  -chroma_elim_threshold <int>        E..V...... single coefficient elimination threshold for chrominance (negative values also consider dc coefficient) (from INT_MIN to INT_MAX) (default 0)
  -quantizer_noise_shaping <int>        E..V...... (from 0 to INT_MAX) (default 0)
  -error_rate        <int>        E..V...... Simulate errors in the bitstream to test error concealment. (from 0 to INT_MAX) (default 0)
  -qsquish           <float>      E..V...... how to keep quantizer between qmin and qmax (0 = clip, 1 = use differentiable function) (from 0 to 99) (default 0)
  -rc_qmod_amp       <float>      E..V...... experimental quantizer modulation (from -FLT_MAX to FLT_MAX) (default 0)
  -rc_qmod_freq      <int>        E..V...... experimental quantizer modulation (from INT_MIN to INT_MAX) (default 0)
  -rc_eq             <string>     E..V...... Set rate control equation. When computing the expression, besides the standard functions defined in the section 'Expression Evaluation', the following functions are available: bits2qp(bits), qp2bits(qp). Also the following constants are available: iTex pTex tex mv fCode iCount mcVar var isI isP isB avgQP qComp avgIITex avgPITex avgPPTex avgBPTex avgTex.
  -rc_init_cplx      <float>      E..V...... initial complexity for 1-pass encoding (from -FLT_MAX to FLT_MAX) (default 0)
  -rc_buf_aggressivity <float>      E..V...... currently useless (from -FLT_MAX to FLT_MAX) (default 1)
  -border_mask       <float>      E..V...... increase the quantizer for macroblocks close to borders (from -FLT_MAX to FLT_MAX) (default 0)
  -lmin              <int>        E..V...... minimum Lagrange factor (VBR) (from 0 to INT_MAX) (default 236)
  -lmax              <int>        E..V...... maximum Lagrange factor (VBR) (from 0 to INT_MAX) (default 3658)
  -ibias             <int>        E..V...... intra quant bias (from INT_MIN to INT_MAX) (default 999999)
  -pbias             <int>        E..V...... inter quant bias (from INT_MIN to INT_MAX) (default 999999)
  -rc_strategy       <int>        E..V...... ratecontrol method (from 0 to 1) (default ffmpeg)
     ffmpeg          0            E..V...... deprecated, does nothing
     xvid            0            E..V...... deprecated, does nothing
  -motion_est        <int>        E..Vpython执行ffmpeg 报错:at least one output file must be specified

FFmpeg 'scale' filter not present, cannot convert pixel formats.

FFmpeg deprecated pixel format used问题描述

FFmpeg h.265 MP4编码告警:deprecated pixel format used, make sure you did set range correctly

FFmpeg h.265 MP4编码告警:deprecated pixel format used, make sure you did set range correctly

ERROR: No query specified(Mysql数据库报错)