Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Comments

@x-yuri
Copy link

x-yuri commented Feb 15, 2019

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)

@x-yuri
Copy link
Author

x-yuri commented Feb 15, 2019

Supposedly it happens when screen size (particularly height) is less than or equal to requested browser size (1280x720).

requested -> real (passed to paint event handler)
1024x576 -> 1023x575
1280x720 -> 1279x719
1280x800 -> 1280x720
1368x768 -> 1280x720

@jennifer-shehane
Copy link
Member

Hey @x-yuri, could you provide an example of a failing test file? Are you setting the size using cy.viewport()?

@cypress-bot cypress-bot bot added stage: needs information Not enough info to reproduce the issue and removed stage: needs investigating Someone from Cypress needs to look at this labels Feb 19, 2019
@x-yuri
Copy link
Author

x-yuri commented Feb 19, 2019

// see original post
describe('My First Test', function() {
  it('Visits the Kitchen Sink', function() {
    cy.visit('https://example.cypress.io')
  })
})

I'm not using cy.viewport(). Try with screen resolution less than 1280x720.

@narinepoghosyan
Copy link

narinepoghosyan commented Apr 30, 2019

I am using cy.viewport(), but have a same problem too.. How I can fix it?

@x-yuri
Copy link
Author

x-yuri commented Jun 18, 2019

@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.

@x-yuri
Copy link
Author

x-yuri commented Dec 4, 2019

As you might see, I've found a way to reproduce it without cypress. Under certain conditions (offscreen mode, show: false, (width == 1280, height == 720) >= (real_screen_width, real_screen_height), is there a way to change the 1280/720 thing?):

screen.width == real_screen_width - 1
screen.height == real_screen_height - 1

But I wonder if it's okay to demand a window to fit the screen. Generally that is not possible, since there usually exist some sort of a taskbar.

@randing89
Copy link

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

@x-yuri
Copy link
Author

x-yuri commented Mar 6, 2020

Indeed with -s '-screen 0 1280x720x24' it fails, but increasing either of those makes it work.

@ManuelTS
Copy link

This issue may also come if you switch hardware screens. Removing the old file does the trick.

@dsnunes07
Copy link

This issue may also come if you switch hardware screens. Removing the old file does the trick.

Which old file? I am currently facing this issue running specs with MS Edge.

@ManuelTS
Copy link

This issue may also come if you switch hardware screens. Removing the old file does the trick.

Which old file? I am currently facing this issue running specs with MS Edge.

The video file created by running cypress and tests, should be from the top of my head in this path ./cypress/videos/yourTestName.mp4.

@Spea
Copy link

Spea commented Mar 3, 2021

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.

@tboulis
Copy link

tboulis commented Mar 3, 2021

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.

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

@Spea
Copy link

Spea commented Mar 3, 2021

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.

@tboulis
Copy link

tboulis commented Mar 3, 2021

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

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Mar 3, 2021

The code for this is done in cypress-io/cypress#15295, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@nickbreid
Copy link

Thanks maintainers for moving so quickly on this! Do you have a target release date for this fix?

@jennifer-shehane
Copy link
Member

@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.

@clarkd
Copy link

clarkd commented Mar 11, 2021

@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?

@jo-sm
Copy link

jo-sm commented Mar 11, 2021

I'm running into this issue as well in GitHub Actions (which presumably uses the same images as Azure). For anyone running into this issue using GitHub Actions, you can use the Cypress Chrome 87 container to mitigate until Chrome 89 works:

jobs:
  job:
    runs-on: ubuntu-latest
    container: cypress/browsers:node12.18.3-chrome87-ff82

Seeing this issue I'd probably recommend pegging your workflow to a specific container/image to prevent this issue from happening in the future and periodically upgrade the container in the workflow.

@pmerwin
Copy link

pmerwin commented Mar 11, 2021

Starting seeing this in our github actions with 89 :(
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/runner/.cache/Cypress/6.6.0/Cypress/resources/app/packages/server/node_modules/fluent-ffmpeg/lib/processor.js:182:22)
at ChildProcess.emit (events.js:315:20)
at Process.ChildProcess._handle.onexit (internal/child_process.js:275: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!

@nickbreid
Copy link

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.

@jennifer-shehane
Copy link
Member

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

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Mar 15, 2021

Released in 6.7.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v6.7.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Mar 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.