Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FFMPEG: Incompatible pixel format 'rgb24' for codec 'gif', auto-selecting format 'rgb8'

I use ffmpeg to record xvfb desktop with 24 bit color depth and save it in gif format (and then I pipe it to AWS so you can replace the ' - ' symbol with a filename.gif in the end of the command, it doesn't affect this issue):

ffmpeg -f x11grab -video_size 800x600 -r 30 -i :99.0 -f gif -pix_fmt rgb24 -t 5 -

However, I always get the warning:

Incompatible pixel format 'rgb24' for codec 'gif', auto-selecting format 'rgb8'

Which leads to incorrect color reproduction. I tried it both on Windows and Ubuntu Docker container, both pre-compiled and from source, from repository with last commits, but no luck. Also I've seen in the other people's logs that they use --pix_fmt rgb24 or bgr24 and it works just fine.

So the question is: is there anything I need to install or configure in order to use rgb24 with gif encoder? Or maybe there is a workaround like converting it to another format first?

Here is the part of my output:

ffmpeg version git-2017-08-18-f386dd7 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 20160609
  configuration: --enable-gpl --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-librtmp --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-nonfree --enable-version3 --enable-libxcb
  libavutil      55. 74.100 / 55. 74.100
  libavcodec     57.102.100 / 57.102.100
  libavformat    57. 76.100 / 57. 76.100
  libavdevice    57.  7.100 / 57.  7.100
  libavfilter     6. 99.100 /  6. 99.100
  libswscale      4.  7.102 /  4.  7.102
  libswresample   2.  8.100 /  2.  8.100
  libpostproc    54.  6.100 / 54.  6.100


Input #0, x11grab, from ':99.0':
  Duration: N/A, start: 1503077459.413864, bitrate: N/A
    Stream #0:0: Video: rawvideo (BGR[0] / 0x524742), bgr0, 1024x768, 30 fps, 1000k tbr, 1000k tbn, 1000k tbc
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> gif (native))
Press [q] to stop, [?] for help
Incompatible pixel format 'bgr24' for codec 'gif', auto-selecting format 'rgb8'


Output #0, gif, to 'pipe:':
  Metadata:
    encoder         : Lavf57.76.100
    Stream #0:0: Video: gif, rgb8, 1024x768, q=2-31, 200 kb/s, 30 fps, 100 tbn, 30 tbc
    Metadata:
      encoder         : Lavc57.102.100 gif

PS: the only workaround I've found is to split input video into jpegs and pipe them to ImageMagick which then concatenates jpegs to gif. This is extremely slow process and increases render time x20 times.

like image 794
Alexander Korzhykov Avatar asked Oct 30 '22 03:10

Alexander Korzhykov


1 Answers

A solution for me was to install ffmpeg and imagemagick (on mac):

brew install ffmpeg
brew install imagemagick 

then cd to the directory where the .mov file lives and run the following commands.

mkdir output
ffmpeg -i myvideo.mov -vf scale=1024:-1 -r 10 output/ffout%3d.png
convert -delay 8 -loop 0 output/ffout*.png output/animation.gif

The first one creates a output directory. The second command creates a .png file for every frame (specified by the -r flag, meaning 10 fps). The third command uses imagemagick to create a gif file from the previously created image files with a delay of 8ms. The final gif is the output/animation.gif file.

like image 130
Felix Lemke Avatar answered Nov 09 '22 06:11

Felix Lemke