ffmpeg convert from H.264 (High 4:2:2 Profile) MOV to H.264 (Baseline Profile) MP4

Viewed 140

How can I convert a video (MOV) from H.264 (High 4:2:2 Profile) to H.264 (Baseline Profile) MP4 using ffmpeg? I would run that mp4 video on android mobile in a VideoView to support as many mobile types as possible.

I can't do that with this command: ffmpeg -i o1.mov -c:v libx264 -profile:v baseline -c:a aac -ar 44100 -ac 2 -b:a 128k out.mp4.

That'd return an error:

ffmpeg version 5.0.1-essentials_build-www.gyan.dev Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 11.2.0 (Rev7, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-sdl2 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libgme --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libtheora --enable-libvo-amrwbenc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-librubberband
  libavutil      57. 17.100 / 57. 17.100
  libavcodec     59. 18.100 / 59. 18.100
  libavformat    59. 16.100 / 59. 16.100
  libavdevice    59.  4.100 / 59.  4.100
  libavfilter     8. 24.100 /  8. 24.100
  libswscale      6.  4.100 /  6.  4.100
  libswresample   4.  3.100 /  4.  3.100
  libpostproc    56.  3.100 / 56.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'o1.mov':
  Metadata:
    major_brand     : qt
    minor_version   : 537199360
    compatible_brands: qt
    creation_time   : 2022-07-19T16:56:39.000000Z
  Duration: 00:00:07.72, start: 0.000000, bitrate: 117473 kb/s
  Stream #0:0[0x1](eng): Video: prores (Standard) (apcn / 0x6E637061), yuv422p10le(tv, bt709, progressive), 1080x1920, 114850 kb/s, SAR 1:1 DAR 9:16, 23.98 fps, 23.98 tbr, 24k tbn (default)
    Metadata:
      creation_time   : 2022-07-19T16:56:39.000000Z
      handler_name    : Apple Video Media Handler
      vendor_id       : appl
      encoder         : Apple ProRes 422
      timecode        : 00:00:00:04
  Stream #0:1[0x2](eng): Audio: pcm_s16le (sowt / 0x74776F73), 48000 Hz, stereo, s16, 1536 kb/s (default)
    Metadata:
      creation_time   : 2022-07-19T16:56:39.000000Z
      handler_name    : Apple Sound Media Handler
      vendor_id       :
      timecode        : 00:00:00:04
  Stream #0:2[0x3](eng): Data: none (tmcd / 0x64636D74), 0 kb/s (default)
    Metadata:
      creation_time   : 2022-07-19T16:56:39.000000Z
      handler_name    : Time Code Media Handler
      timecode        : 00:00:00:04
Stream mapping:
  Stream #0:0 -> #0:0 (prores (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (pcm_s16le (native) -> aac (native))
Press [q] to stop, [?] for help
x264 [error]: baseline profile doesn't support 4:2:2
[libx264 @ 0000014713a31ac0] Error setting profile baseline.
[libx264 @ 0000014713a31ac0] Possible profiles: baseline main high high10 high422 high444
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Conversion failed!
1 Answers

You need to apply color format conversion to adhere to baseline profile restrictions. Otherwise FFmpeg copies the format from source and that is why it is throwing the error.

Just add -vf format=yuv420p to your commandline which invokes video filter that converts any source color format to YUV 4:2:0 that baseline profile accepts and which is essentially the most supported also by various devices.

Related