5

Gnome has a built-in screencast tool using ctrl plus shift plus alt plus R. It's a great tool with consistent quality video output!

But, I need the output in mp4. I have tried this: ffmpeg -i screencast.webm -crf 0 screencast.mp4 as specified in other AskUbuntu posts, but it doesn't work well for me, even though it's supposed to be lossless.

My screencast in mp4 jumps around, freezes on a single frame, and the file sizes are drastically different.

I need h.264 mp4, ideally with a constant frame rate, at high definition.

What ffmpeg command can I use?

Here's an example file: ffmpeg -i input.webm

$ ffmpeg -i Screencast\ from\ 03-18-2023\ 04\:57\:59\ PM.webm 
ffmpeg version 4.4.2-0ubuntu0.22.04.1 Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 11 (Ubuntu 11.2.0-19ubuntu1)
  configuration: --prefix=/usr --extra-version=0ubuntu0.22.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-pocketsphinx --enable-librsvg --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  WARNING: library configuration mismatch
  avcodec     configuration: --prefix=/usr --extra-version=0ubuntu0.22.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-pocketsphinx --enable-librsvg --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared --enable-version3 --disable-doc --disable-programs --enable-libaribb24 --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libtesseract --enable-libvo_amrwbenc --enable-libsmbclient
  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
Input #0, matroska,webm, from 'Screencast from 03-18-2023 04:57:59 PM.webm':
  Metadata:
    encoder         : GStreamer matroskamux version 1.20.3
    creation_time   : 2023-03-18T20:57:59.129336Z
  Duration: 00:16:48.47, start: 0.028000, bitrate: 858 kb/s
  Stream #0:0(eng): Video: vp8, yuv420p(tv, bt709, progressive), 1920x1080, SAR 1:1 DAR 16:9, 1k tbr, 1k tbn, 1k tbc (default)
    Metadata:
      title           : Video
At least one output file must be specified

6
  • 1
    Can you post the command itself and subsequent full terminal output for this command: ffmpeg -i screencast.webm and then it should be a simple matter to suggest the appropriate FFmpeg command...
    – andrew.46
    Mar 20, 2023 at 4:37
  • Updated! Thanks : ) Mar 21, 2023 at 5:07
  • 1
    Interestingly enough a VP8 video stream should be ok in an mp4 container so only remuxing is required: ffmpeg -i input.webm -c:v copy output.mp4 Support for VP8/9 in mp4 has been around a while but just check that your copy of FFmpeg is new enough to do this and that your playback application is also happy...
    – andrew.46
    Mar 21, 2023 at 6:17
  • And what happens to frame rates? It's variable in webm, and I'd need constant in mp4, no? Mar 21, 2023 at 18:48
  • 1
    I don't know. I would recommend a test run and see if FFmpeg will sort it out for you :). On a test encode here on my local machine there were no issues but best to test on your own setup...
    – andrew.46
    Mar 23, 2023 at 5:34

1 Answer 1

7

This works to output your screencast as an mp4 that plays as expected in VLC and others:

ffmpeg -i screencast.webm -filter:v "fps=30" screencast.mp4

This works in more cases and avoids ffmpeg throwing 'not divisible by 2' errors:

ffmpeg -i screencast.webm -filter:v "scale=trunc(iw/2)*2:trunc(ih/2)*2,fps=30" screencast.mp4

The above sets a constant frame rate of 30 frames per second (fps). It resizes your video by one pixel at most and makes sure your input width and height (iw and ih) are even numbers.

You can also specify codec options like -codec:v libx264. Check out ffmpeg's Video Options for your particulars.

Your questions and related Q&A I've found helpful during this research include these:

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .