cypress: ffmpeg: Error initializing output stream: Error while opening encoder for output stream: width not divisible by 2

Current behavior:

Tests doesn’t run without the GUI because of the error with video capture.

$ DEBUG=cypress:server:video node_modules/.bin/cypress run

====================================================================================================

  (Run Starting)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Cypress:    3.1.4                                                                              │
  │ Browser:    Electron 59 (headless)                                                             │
  │ Specs:      1 found (ordering.spec.js)                                                         │
  │ Searched:   cypress/integration/ordering.spec.js                                               │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘


────────────────────────────────────────────────────────────────────────────────────────────────────

  Running: ordering.spec.js...                                                             (1 of 1)
  cypress:server:video capture started { command: 'ffmpeg -n 20 /home/yuri/.cache/Cypress/3.1.4/Cypress/resources/app/packages/server/node_modules/@ffmpeg-installer/linux-x64/ffmpeg -f image2pipe -use_wallclock_as_timestamps 1 -i pipe:0 -y -vcodec libx264 -preset ultrafast /srv/http/s1/cypress/videos/ordering.spec.js.mp4' } +0ms
  cypress:server:video capture stderr log { message: 'ffmpeg version N-45896-g19c3df0cd-static https://johnvansickle.com/ffmpeg/  Copyright (c) 2000-2018 the FFmpeg developers' } +3ms
  cypress:server:video capture stderr log { message: '  built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516' } +1ms
  cypress:server:video capture stderr log { message: '  configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc-6 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libvmaf --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg' } +0ms
  cypress:server:video capture stderr log { message: '  libavutil      56. 17.100 / 56. 17.100' } +0ms
  cypress:server:video capture stderr log { message: '  libavcodec     58. 19.100 / 58. 19.100' } +1ms
  cypress:server:video capture stderr log { message: '  libavformat    58. 13.100 / 58. 13.100' } +0ms
  cypress:server:video capture stderr log { message: '  libavdevice    58.  4.100 / 58.  4.100' } +0ms
  cypress:server:video capture stderr log { message: '  libavfilter     7. 20.100 /  7. 20.100' } +0ms
  cypress:server:video capture stderr log { message: '  libswscale      5.  2.100 /  5.  2.100' } +0ms
  cypress:server:video capture stderr log { message: '  libswresample   3.  2.100 /  3.  2.100' } +0ms
  cypress:server:video capture stderr log { message: '  libpostproc    55.  2.100 / 55.  2.100' } +13ms
  cypress:server:video capture stderr log { message: '[mjpeg @ 0x6883000] EOI missing, emulating' } +370ms


  ordering
  cypress:server:video capture stderr log { message: 'Input #0, image2pipe, from \'pipe:0\':' } +7s
  cypress:server:video capture stderr log { message: '  Duration: N/A, start: 1550258710.960000, bitrate: N/A' } +0ms
  cypress:server:video capture stderr log { message: '    Stream #0:0: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 1023x575 [SAR 1:1 DAR 1023:575], 25 fps, 25 tbr, 25 tbn, 25 tbc' } +0ms
  cypress:server:video capture stderr log { message: 'Stream mapping:' } +1ms
  cypress:server:video capture codec data: { format: 'image2pipe', audio: '', video: 'mjpeg', duration: 'N/A', video_details: [ 'mjpeg', 'yuvj420p(pc', 'bt470bg/unknown/unknown)', '1023x575 [SAR 1:1 DAR 1023:575]', '25 fps', '25 tbr', '25 tbn', '25 tbc' ] } +0ms
  cypress:server:video capture stderr log { message: '  Stream #0:0 -> #0:0 (mjpeg (native) -> h264 (libx264))' } +3ms
  cypress:server:video capture stderr log { message: '[libx264 @ 0x6887a00] width not divisible by 2 (1023x575)' } +3ms
  cypress:server:video capture stderr log { message: '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' } +0ms
  cypress:server:video capture stderr log { message: 'Conversion failed!' } +2ms
  cypress:server:video capture stderr log { message: '' } +1ms
  cypress:server:video capture errored: { error: 'ffmpeg exited with code 1: 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\nConversion failed!\n', stdout: '', stderr: 'ffmpeg version N-45896-g19c3df0cd-static https://johnvansickle.com/ffmpeg/  Copyright (c) 2000-2018 the FFmpeg developers\n  built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516\n  configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc-6 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libvmaf --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg\n  libavutil      56. 17.100 / 56. 17.100\n  libavcodec     58. 19.100 / 58. 19.100\n  libavformat    58. 13.100 / 58. 13.100\n  libavdevice    58.  4.100 / 58.  4.100\n  libavfilter     7. 20.100 /  7. 20.100\n  libswscale      5.  2.100 /  5.  2.100\n  libswresample   3.  2.100 /  3.  2.100\n  libpostproc    55.  2.100 / 55.  2.100\n[mjpeg @ 0x6883000] EOI missing, emulating\nInput #0, image2pipe, from \'pipe:0\':\n  Duration: N/A, start: 1550258710.960000, bitrate: N/A\n    Stream #0:0: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 1023x575 [SAR 1:1 DAR 1023:575], 25 fps, 25 tbr, 25 tbn, 25 tbc\nStream mapping:\n  Stream #0:0 -> #0:0 (mjpeg (native) -> h264 (libx264))\n[libx264 @ 0x6887a00] width not divisible by 2 (1023x575)\nError 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\nConversion failed!\n' } +1ms
Warning: We failed to record the video.

This error will not alter the exit code.

Error: ffmpeg exited with code 1: 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!

    at ChildProcess.<anonymous> (/home/yuri/.cache/Cypress/3.1.4/Cypress/resources/app/packages/server/node_modules/fluent-ffmpeg/lib/processor.js:182:22)
    at emitTwo (events.js:125:13)
    at ChildProcess.emit (events.js:213:7)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)

{ Error: ffmpeg exited with code 1: 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!

    at ChildProcess.<anonymous> (/home/yuri/.cache/Cypress/3.1.4/Cypress/resources/app/packages/server/node_modules/fluent-ffmpeg/lib/processor.js:182:22)
    at emitTwo (events.js:125:13)
    at ChildProcess.emit (events.js:213:7)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
 recordingVideoFailed: true }
Error: ffmpeg exited with code 1: 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!

    at ChildProcess.<anonymous> (/home/yuri/.cache/Cypress/3.1.4/Cypress/resources/app/packages/server/node_modules/fluent-ffmpeg/lib/processor.js:182:22)
    at emitTwo (events.js:125:13)
    at ChildProcess.emit (events.js:213:7)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
$ xrandr
Screen 0: minimum 8 x 8, current 1024 x 576, maximum 32767 x 32767
eDP1 connected primary 1024x576+0+0 (normal left inverted right x axis y axis) 290mm x 170mm
   1920x1080     60.00 +  59.93    40.00  
   1680x1050     59.88  
   1400x1050     59.98  
   1600x900      60.00    59.95    59.82  
   1280x1024     60.02  
   1400x900      59.96    59.88  
   1280x960      60.00  
   1368x768      60.00    59.88    59.85  
   1280x800      59.81    59.91  
   1280x720      59.86    60.00    59.74  
   1024x768      60.00  
   1024x576      60.00*   59.90    59.82  
   960x540       60.00    59.63    59.82  
   800x600       60.32    56.25  
   864x486       60.00    59.92    59.57  
   640x480       59.94  
   720x405       59.51    60.00    58.99  
   640x360       59.84    59.32    60.00  
DP1 disconnected (normal left inverted right x axis y axis)
HDMI1 disconnected (normal left inverted right x axis y axis)
HDMI2 disconnected (normal left inverted right x axis y axis)
VIRTUAL1 disconnected (normal left inverted right x axis y axis)

Desired behavior:

Tests run.

And by the way, isn’t it supposed to run all the tests even if it can’t record the video?

Steps to reproduce: (app code and test code)

Run the following test without GUI:

describe('My First Test', function() {
  it('Visits the Kitchen Sink', function() {
    cy.wait(3000);   // or more to make it finish abnormally (prematurely)
    // low values still produce an error, but tests continue to run
  })
})
$ npx cypress run

If your screen resolution is greater than 1280x720. Otherwise:

$ xvfb-run -s '-screen 0 1280x720x24' npx cypress run

electron bug: Screen dimensions are off by one pixel in offscreen mode.

Workarounds

$ xvfb-run -s '-screen 0 1280x800x24' npx cypress run

Add .outputOptions("-vf pad=ceil(iw/2)*2:ceil(ih/2)*2") after the following line. Based on the following Stack Overflow answer. This fixes it for me.

Or probably .videoFilter('pad=ceil(iw/2)*2:ceil(ih/2)*2').

Versions

cypress-3.1.4, Arch Linux, Electron 59 (headless)

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 24 (5 by maintainers)

Most upvoted comments

We just saw this error popping up in our cypress tests after upgrading to chrome 89 - rolling back to 88 solved this issue for us, maybe this helps someone else.

@nickbreid The next release is awaiting some specific feature work, so it will go out as soon as possible - this is off from our normal release schedule.

Solved by adding xvfb-run -s '-screen 0 1280x800x24' before cypress run

Sorry for the delay everyone. We’re working on getting a release out today, been some extra juggling of feature work. 🤞

@nickbreid The next release is awaiting some specific feature work, so it will go out as soon as possible - this is off from our normal release schedule.

@jennifer-shehane It looks like Azure DevOps have just upgraded their images to now ship with Chrome v89, which means video recordings are failing for all tests. We’ve just upgraded to Cypress Dashboard so no videos is a bit of a bummer.

Do you have an estimate release date at this time?

@narinepoghosyan The answer was in one of the previous posts, but to add more details, you’ve got to change

~/.cache/Cypress/3.1.4/Cypress/resources/app/packages/server/lib/video_capture.js

Add

.outputOptions("-vf pad=ceil(iw/2)*2:ceil(ih/2)*2

or

.videoFilter('pad=ceil(iw/2)*2:ceil(ih/2)*2')

after

.outputOptions("-preset ultrafast")

Or make resolution bigger than 1280x720, or possibly more.

If you don’t actually need the video, here’s a potential workaround for anyone dealing with this error:

Go into your cypress config.json and add a line video: false, or alternatively, call cypress with the CLI option cypress run --config video=false. This was helpful for my team as we can live without the video until this release occurs.

How did you specify the version? Through cypress/browsers or did you download it from google directly?

We do not use cypress/browsers for this since we use centos as our linux distribution for all Docker images. So yes, we download it directly from google via the following link:

https://dl.google.com/linux/chrome/rpm/stable/x86_64/google-chrome-stable-88.0.4324.182-1.x86_64.rpm

If you need a different version, just take a look at this stackexchange answer on how to get the version you might need.

Thank you @Spea , we use linux and deb images for chrome. I’ve read that google doesn’t share the older version download links so it is pretty hard to figure them out.

In case someone need the debian file for Chrome version 88:

wget https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_88.0.4324.182-1_amd64.deb

How did you specify the version? Through cypress/browsers or did you download it from google directly?

We do not use cypress/browsers for this since we use centos as our linux distribution for all Docker images. So yes, we download it directly from google via the following link:

https://dl.google.com/linux/chrome/rpm/stable/x86_64/google-chrome-stable-88.0.4324.182-1.x86_64.rpm

If you need a different version, just take a look at this stackexchange answer on how to get the version you might need.