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..V...... motion estimation algorithm (from 0 to 2) (default epzs)
     zero            0            E..V......
     epzs            1            E..V......
     xone            2            E..V......
  -force_duplicated_matrix <boolean>    E..V...... Always write luma and chroma matrix for mjpeg, useful for rtp streaming. (default false)
  -b_strategy        <int>        E..V...... Strategy to choose between I/P/B-frames (from 0 to 2) (default 0)
  -b_sensitivity     <int>        E..V...... Adjust sensitivity of b_frame_strategy 1 (from 1 to INT_MAX) (default 40)
  -brd_scale         <int>        E..V...... Downscale frames for dynamic B-frame decision (from 0 to 3) (default 0)
  -skip_threshold    <int>        E..V...... Frame skip threshold (from INT_MIN to INT_MAX) (default 0)
  -skip_factor       <int>        E..V...... Frame skip factor (from INT_MIN to INT_MAX) (default 0)
  -skip_exp          <int>        E..V...... Frame skip exponent (from INT_MIN to INT_MAX) (default 0)
  -skip_cmp          <int>        E..V...... Frame skip compare function (from INT_MIN to INT_MAX) (default dctmax)
     sad             0            E..V...... Sum of absolute differences, fast
     sse             1            E..V...... Sum of squared errors
     satd            2            E..V...... Sum of absolute Hadamard transformed differences
     dct             3            E..V...... Sum of absolute DCT transformed differences
     psnr            4            E..V...... Sum of squared quantization errors, low quality
     bit             5            E..V...... Number of bits needed for the block
     rd              6            E..V...... Rate distortion optimal, slow
     zero            7            E..V...... Zero
     vsad            8            E..V...... Sum of absolute vertical differences
     vsse            9            E..V...... Sum of squared vertical differences
     nsse            10           E..V...... Noise preserving sum of squared differences
     dct264          14           E..V......
     dctmax          13           E..V......
     chroma          256          E..V......
     msad            15           E..V...... Sum of absolute differences, median predicted
  -sc_threshold      <int>        E..V...... Scene change threshold (from INT_MIN to INT_MAX) (default 0)
  -noise_reduction   <int>        E..V...... Noise reduction (from INT_MIN to INT_MAX) (default 0)
  -mpeg_quant        <int>        E..V...... Use MPEG quantizers instead of H.263 (from 0 to 1) (default 0)
  -ps                <int>        E..V...... RTP payload size in bytes (from INT_MIN to INT_MAX) (default 0)
  -mepc              <int>        E..V...... Motion estimation bitrate penalty compensation (1.0 = 256) (from INT_MIN to INT_MAX) (default 256)
  -mepre             <int>        E..V...... pre motion estimation (from INT_MIN to INT_MAX) (default 0)
  -intra_penalty     <int>        E..V...... Penalty for intra blocks in block decision (from 0 to 1.07374e+09) (default 0)
  -a53cc             <boolean>    E..V...... Use A53 Closed Captions (if available) (default true)


C:\Users\Arnold\source\repos\20221114_ffmpeg_compile_test2\video>

参考文章:关于ffmpeg必须知道的

20221125:注意,支持的像素格式要具体查看你的ffmpeg!

我在我们英伟达8核盒子上查看

x264编码:

ffmpeg -h encoder=h264

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Dontla

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值