FFmpeg-Tutorial-Using-Jupyter-Notebook-to-Create-Youtube-Videos

In [1]:
import os
os.getcwd()
Out[1]:
'/home/jack/Desktop/LinuxToyBox/mylinuxtoybox.com/html/FFmpeg-Tutorial-Using-Jupyter-Notebook-to-Create-Youtube-Videos'
In [2]:
!mkdir vids
mkdir: cannot create directory ‘vids’: File exists
In [3]:
!mkdir images
mkdir: cannot create directory ‘images’: File exists
In [4]:
!tree
.
├── 028.png
├── addmeta
├── FFMPEG-Tutorial-Editing-Videos-Using-Jupyter-Notebook.ipynb
├── FFmpeg-Tutorial-Using-Jupyter-Notebook-to-Create-Youtube-Videos.jpg
├── FFMPEG-Tutorial-YouTube-Video-Toolkit-Jupyter-Notebook-bak.ipynb
├── FFMPEG-Tutorial-YouTube-Video-Toolkit-Jupyter-Notebook.ipynb
├── GETSIZE.py
├── GETSIZE.pyc
├── imageCAP
├── images
│   ├── 028.png
│   ├── 2019-03-14_11:0509.png
│   ├── 2019-03-14_11:0728.png
│   ├── output3.jpg
│   └── output3-TEXT.png
├── scrCAP
├── scrCAPxx
├── test001.sh
├── themesong-reverb.mp3
├── Untitled1.ipynb
├── Untitled.ipynb
├── Utilities.ipynb
└── vids
    ├── 001.mkv
    ├── 2019-03-14_10:2627.mp4
    ├── 2019-03-14_10:3253.mp4
    ├── 2019-03-14_10:5729.mp4
    ├── 2019-03-14_11:2101.mp4
    ├── 2019-03-14_18:4226.mp4
    ├── 2019-03-15-07-14.mp4
    ├── 2019-03-15_07:4431.mp4
    ├── 2019-03-15_07:4520.mp4
    ├── BACK.mkv
    ├── FFmpeg-Tutorial-Using-Jupyter-Notebook-to-Create-Youtube-Videos.mkv
    ├── jupyternotebook.science
    ├── nosound.mp4
    ├── output2-WithAud.mp4
    ├── output.mp4
    ├── smaller.mkv
    ├── Using-FFmpeg-with-Jupyter-Notebook-to-Create-Youtube-Videos-57seconds.mkv
    ├── Using-FFmpeg-with-Jupyter-Notebook-to-Create-Youtube-Videos.mkv
    ├── VIDEO.mp4
    └── XXXX.mkv

2 directories, 41 files
In [5]:
!ls 
028.png
addmeta
FFMPEG-Tutorial-Editing-Videos-Using-Jupyter-Notebook.ipynb
FFmpeg-Tutorial-Using-Jupyter-Notebook-to-Create-Youtube-Videos.jpg
FFMPEG-Tutorial-YouTube-Video-Toolkit-Jupyter-Notebook-bak.ipynb
FFMPEG-Tutorial-YouTube-Video-Toolkit-Jupyter-Notebook.ipynb
GETSIZE.py
GETSIZE.pyc
imageCAP
images
scrCAP
scrCAPxx
test001.sh
themesong-reverb.mp3
Untitled1.ipynb
Untitled.ipynb
Utilities.ipynb
vids

Screen Capture as Video without Sound

In [6]:
!ffmpeg -y -f x11grab -framerate 30 -video_size 1360x768 -i :0.0 \
-c:v libx264 -pix_fmt yuv420p -qp 0 -preset ultrafast - y vids/nosound.mp4
ffmpeg version N-92507-g027f032-0ubuntu0.16.04.1 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.3.0-27ubuntu1~18.04)
  configuration: --prefix=/home/jack/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/jack/ffmpeg_build/include --extra-ldflags=-L/home/jack/ffmpeg_build/lib --bindir=/home/jack/bin --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --cc=gcc --cxx=g++ --enable-cross-compile --enable-version3 --enable-shared --disable-stripping --disable-decoder=libopenjpeg --enable-avresample --enable-avisynth --enable-libass --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwavpack --extra-cflags=-fPIC --enable-libx265 --enable-libxvid --enable-opengl --enable-libdc1394 --enable-frei0r --enable-libx264 --enable-libpulse --enable-indev=alsa --enable-outdev=alsa --enable-static --disable-debug --enable-libwebp --enable-libspeex --enable-fontconfig --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-gray --enable-libopenjpeg --enable-libopus --enable-libsoxr --enable-libfribidi --enable-libzimg
  WARNING: library configuration mismatch
  avutil      configuration: --prefix=/home/jack/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/jack/ffmpeg_build/include --extra-ldflags=-L/home/jack/ffmpeg_build/lib --bindir=/home/jack/bin --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --cc=gcc --cxx=g++ --enable-cross-compile --enable-version3 --enable-shared --disable-stripping --disable-decoder=libopenjpeg --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libgme --enable-libgsm --enable-libmysofa --enable-libopenmpt --enable-librubberband --enable-libshine --enable-libssh --enable-libtwolame --enable-libxml2 --enable-libzvbi --enable-openal --enable-sdl2 --enable-libdrm --enable-ladspa --enable-chromaprint --enable-avisynth --enable-avresample --enable-libass --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwavpack --extra-cflags=-fPIC --enable-libx265 --enable-libxvid --enable-opengl --enable-libdc1394 --enable-frei0r --enable-libx264 --enable-libpulse --enable-indev=alsa --enable-outdev=alsa --enable-static --disable-debug --enable-libwebp --enable-libspeex --enable-fontconfig --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-gray --enable-libopenjpeg --enable-libopus --enable-libsoxr --enable-libfribidi --enable-libzimg --disable-doc --disable-programs --enable-libtesseract
  avcodec     configuration: --prefix=/home/jack/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/jack/ffmpeg_build/include --extra-ldflags=-L/home/jack/ffmpeg_build/lib --bindir=/home/jack/bin --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --cc=gcc --cxx=g++ --enable-cross-compile --enable-version3 --enable-shared --disable-stripping --disable-decoder=libopenjpeg --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libgme --enable-libgsm --enable-libmysofa --enable-libopenmpt --enable-librubberband --enable-libshine --enable-libssh --enable-libtwolame --enable-libxml2 --enable-libzvbi --enable-openal --enable-sdl2 --enable-libdrm --enable-ladspa --enable-chromaprint --enable-avisynth --enable-avresample --enable-libass --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwavpack --extra-cflags=-fPIC --enable-libx265 --enable-libxvid --enable-opengl --enable-libdc1394 --enable-frei0r --enable-libx264 --enable-libpulse --enable-indev=alsa --enable-outdev=alsa --enable-static --disable-debug --enable-libwebp --enable-libspeex --enable-fontconfig --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-gray --enable-libopenjpeg --enable-libopus --enable-libsoxr --enable-libfribidi --enable-libzimg --disable-doc --disable-programs --enable-libtesseract
  avformat    configuration: --prefix=/home/jack/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/jack/ffmpeg_build/include --extra-ldflags=-L/home/jack/ffmpeg_build/lib --bindir=/home/jack/bin --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --cc=gcc --cxx=g++ --enable-cross-compile --enable-version3 --enable-shared --disable-stripping --disable-decoder=libopenjpeg --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libgme --enable-libgsm --enable-libmysofa --enable-libopenmpt --enable-librubberband --enable-libshine --enable-libssh --enable-libtwolame --enable-libxml2 --enable-libzvbi --enable-openal --enable-sdl2 --enable-libdrm --enable-ladspa --enable-chromaprint --enable-avisynth --enable-avresample --enable-libass --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwavpack --extra-cflags=-fPIC --enable-libx265 --enable-libxvid --enable-opengl --enable-libdc1394 --enable-frei0r --enable-libx264 --enable-libpulse --enable-indev=alsa --enable-outdev=alsa --enable-static --disable-debug --enable-libwebp --enable-libspeex --enable-fontconfig --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-gray --enable-libopenjpeg --enable-libopus --enable-libsoxr --enable-libfribidi --enable-libzimg --disable-doc --disable-programs --enable-libtesseract
  avdevice    configuration: --prefix=/home/jack/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/jack/ffmpeg_build/include --extra-ldflags=-L/home/jack/ffmpeg_build/lib --bindir=/home/jack/bin --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --cc=gcc --cxx=g++ --enable-cross-compile --enable-version3 --enable-shared --disable-stripping --disable-decoder=libopenjpeg --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libgme --enable-libgsm --enable-libmysofa --enable-libopenmpt --enable-librubberband --enable-libshine --enable-libssh --enable-libtwolame --enable-libxml2 --enable-libzvbi --enable-openal --enable-sdl2 --enable-libdrm --enable-ladspa --enable-chromaprint --enable-avisynth --enable-avresample --enable-libass --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwavpack --extra-cflags=-fPIC --enable-libx265 --enable-libxvid --enable-opengl --enable-libdc1394 --enable-frei0r --enable-libx264 --enable-libpulse --enable-indev=alsa --enable-outdev=alsa --enable-static --disable-debug --enable-libwebp --enable-libspeex --enable-fontconfig --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-gray --enable-libopenjpeg --enable-libopus --enable-libsoxr --enable-libfribidi --enable-libzimg --disable-doc --disable-programs --enable-libtesseract
  avfilter    configuration: --prefix=/home/jack/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/jack/ffmpeg_build/include --extra-ldflags=-L/home/jack/ffmpeg_build/lib --bindir=/home/jack/bin --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --cc=gcc --cxx=g++ --enable-cross-compile --enable-version3 --enable-shared --disable-stripping --disable-decoder=libopenjpeg --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libgme --enable-libgsm --enable-libmysofa --enable-libopenmpt --enable-librubberband --enable-libshine --enable-libssh --enable-libtwolame --enable-libxml2 --enable-libzvbi --enable-openal --enable-sdl2 --enable-libdrm --enable-ladspa --enable-chromaprint --enable-avisynth --enable-avresample --enable-libass --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwavpack --extra-cflags=-fPIC --enable-libx265 --enable-libxvid --enable-opengl --enable-libdc1394 --enable-frei0r --enable-libx264 --enable-libpulse --enable-indev=alsa --enable-outdev=alsa --enable-static --disable-debug --enable-libwebp --enable-libspeex --enable-fontconfig --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-gray --enable-libopenjpeg --enable-libopus --enable-libsoxr --enable-libfribidi --enable-libzimg --disable-doc --disable-programs --enable-libtesseract
  avresample  configuration: --prefix=/home/jack/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/jack/ffmpeg_build/include --extra-ldflags=-L/home/jack/ffmpeg_build/lib --bindir=/home/jack/bin --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --cc=gcc --cxx=g++ --enable-cross-compile --enable-version3 --enable-shared --disable-stripping --disable-decoder=libopenjpeg --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libgme --enable-libgsm --enable-libmysofa --enable-libopenmpt --enable-librubberband --enable-libshine --enable-libssh --enable-libtwolame --enable-libxml2 --enable-libzvbi --enable-openal --enable-sdl2 --enable-libdrm --enable-ladspa --enable-chromaprint --enable-avisynth --enable-avresample --enable-libass --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwavpack --extra-cflags=-fPIC --enable-libx265 --enable-libxvid --enable-opengl --enable-libdc1394 --enable-frei0r --enable-libx264 --enable-libpulse --enable-indev=alsa --enable-outdev=alsa --enable-static --disable-debug --enable-libwebp --enable-libspeex --enable-fontconfig --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-gray --enable-libopenjpeg --enable-libopus --enable-libsoxr --enable-libfribidi --enable-libzimg --disable-doc --disable-programs --enable-libtesseract
  swscale     configuration: --prefix=/home/jack/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/jack/ffmpeg_build/include --extra-ldflags=-L/home/jack/ffmpeg_build/lib --bindir=/home/jack/bin --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --cc=gcc --cxx=g++ --enable-cross-compile --enable-version3 --enable-shared --disable-stripping --disable-decoder=libopenjpeg --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libgme --enable-libgsm --enable-libmysofa --enable-libopenmpt --enable-librubberband --enable-libshine --enable-libssh --enable-libtwolame --enable-libxml2 --enable-libzvbi --enable-openal --enable-sdl2 --enable-libdrm --enable-ladspa --enable-chromaprint --enable-avisynth --enable-avresample --enable-libass --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwavpack --extra-cflags=-fPIC --enable-libx265 --enable-libxvid --enable-opengl --enable-libdc1394 --enable-frei0r --enable-libx264 --enable-libpulse --enable-indev=alsa --enable-outdev=alsa --enable-static --disable-debug --enable-libwebp --enable-libspeex --enable-fontconfig --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-gray --enable-libopenjpeg --enable-libopus --enable-libsoxr --enable-libfribidi --enable-libzimg --disable-doc --disable-programs --enable-libtesseract
  swresample  configuration: --prefix=/home/jack/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/jack/ffmpeg_build/include --extra-ldflags=-L/home/jack/ffmpeg_build/lib --bindir=/home/jack/bin --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --cc=gcc --cxx=g++ --enable-cross-compile --enable-version3 --enable-shared --disable-stripping --disable-decoder=libopenjpeg --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libgme --enable-libgsm --enable-libmysofa --enable-libopenmpt --enable-librubberband --enable-libshine --enable-libssh --enable-libtwolame --enable-libxml2 --enable-libzvbi --enable-openal --enable-sdl2 --enable-libdrm --enable-ladspa --enable-chromaprint --enable-avisynth --enable-avresample --enable-libass --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwavpack --extra-cflags=-fPIC --enable-libx265 --enable-libxvid --enable-opengl --enable-libdc1394 --enable-frei0r --enable-libx264 --enable-libpulse --enable-indev=alsa --enable-outdev=alsa --enable-static --disable-debug --enable-libwebp --enable-libspeex --enable-fontconfig --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-gray --enable-libopenjpeg --enable-libopus --enable-libsoxr --enable-libfribidi --enable-libzimg --disable-doc --disable-programs --enable-libtesseract
  postproc    configuration: --prefix=/home/jack/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/jack/ffmpeg_build/include --extra-ldflags=-L/home/jack/ffmpeg_build/lib --bindir=/home/jack/bin --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --cc=gcc --cxx=g++ --enable-cross-compile --enable-version3 --enable-shared --disable-stripping --disable-decoder=libopenjpeg --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libgme --enable-libgsm --enable-libmysofa --enable-libopenmpt --enable-librubberband --enable-libshine --enable-libssh --enable-libtwolame --enable-libxml2 --enable-libzvbi --enable-openal --enable-sdl2 --enable-libdrm --enable-ladspa --enable-chromaprint --enable-avisynth --enable-avresample --enable-libass --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwavpack --extra-cflags=-fPIC --enable-libx265 --enable-libxvid --enable-opengl --enable-libdc1394 --enable-frei0r --enable-libx264 --enable-libpulse --enable-indev=alsa --enable-outdev=alsa --enable-static --disable-debug --enable-libwebp --enable-libspeex --enable-fontconfig --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-gray --enable-libopenjpeg --enable-libopus --enable-libsoxr --enable-libfribidi --enable-libzimg --disable-doc --disable-programs --enable-libtesseract
  libavutil      56. 23.101 / 56. 23.101
  libavcodec     58. 39.100 / 58. 39.100
  libavformat    58. 22.100 / 58. 22.100
  libavdevice    58.  6.100 / 58.  6.100
  libavfilter     7. 46.100 /  7. 46.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  4.100 /  5.  4.100
  libswresample   3.  4.100 /  3.  4.100
  libpostproc    55.  4.100 / 55.  4.100
[x11grab @ 0x560424559f00] Stream #0: not enough frames to estimate rate; consider increasing probesize
Input #0, x11grab, from ':0.0':
  Duration: N/A, start: 1555730677.845797, bitrate: N/A
    Stream #0:0: Video: rawvideo (BGR[0] / 0x524742), bgr0, 1360x768, 30 fps, 1000k tbr, 1000k tbn, 1000k tbc
[NULL @ 0x560424565dc0] Unable to find a suitable output format for 'pipe:'
pipe:: Invalid argument
In [15]:
%%HTML
</center>
    <video width="620" controls>
        <source src="vids/nosound.mp4" type="video/mp4">
        Your browser does not support HTML5 video.
    </video>
</center>

Get microphone input

In [7]:
# if you get a response similar to below have alsa installed:
"""**** List of PLAYBACK Hardware Devices ****
card 1: H340 [Logitech USB Headset H340], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: Generic [HD-Audio Generic], device 0: ALC662 rev1 Analog [ALC662 rev1 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: Generic [HD-Audio Generic], device 1: ALC662 rev1 Digital [ALC662 rev1 Digital]
  Subdevices: 1/1
  Subdevice #0: subdevice #0 """
!aplay -l   # note lower-case "L" option
**** List of PLAYBACK Hardware Devices ****
card 0: Generic [HD-Audio Generic], device 0: ALC662 rev1 Analog [ALC662 rev1 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: Generic [HD-Audio Generic], device 1: ALC662 rev1 Digital [ALC662 rev1 Digital]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: H340 [Logitech USB Headset H340], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
In [ ]:
# My microphone:
card 1: H340 [Logitech USB Headset H340], device 0: USB Audio [USB Audio]
        hw(1,0)

Get screen size - Used in ffmpeg command

In [8]:
#In linux how to get screen size:
!xdpyinfo  | grep 'dimensions:'

!xrandr | grep '*'
  dimensions:    1360x768 pixels (359x203 millimeters)
   1360x768      60.02*+
In [9]:
# if you get a response similar to this - you have alsa installed
!aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: Generic [HD-Audio Generic], device 0: ALC662 rev1 Analog [ALC662 rev1 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: Generic [HD-Audio Generic], device 1: ALC662 rev1 Digital [ALC662 rev1 Digital]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: H340 [Logitech USB Headset H340], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

%%HTML


ffmpeg -y -f alsa -ac 2 -i hw:1,0 -strict -2 -f x11grab -framerate 30 -video_size 1360x768 -i :0.0 -c:v libx264 -pix_fmt yuv420p -qp 0 -preset ultrafast vids/$(date +%Y-%m-%d_%H:%M%S).mp4

        Screen capture explained

            
!ffmpeg -y           ... Exclamation point ( ! ) required to run a bash executable - executable is ffmpeg                            the -y overwrites a name if it exists       
-f alsa              ... sound driver
-ac 2                ... audio 
-i hw:1,0            ...  you got that from running ( !aplay -l ) hw is card 1,device 0 
-strict -2           ...  -strict  how strictly to follow the standards (from INT_MIN to INT_MAX)
-f x11grab           ... to get the monitor window  
-framerate 30        ... framerate usuall 30 or 25  
-video_size 1360x768 ... the size of the video to capture
-i :0.0  ... the size of the video to capture ;;    
-c:v libx264 
-pix_fmt yuv420p 
-qp 0 
-preset ultrafast 
vids/$(date +%Y-%m-%d_%H:%M%S).mp4 ... I often use a date to capture video and images is it very
                                       easy to get a director list by time using bash or Python.    


The command required to capture a screen

In [10]:
!ffmpeg -y  -f alsa -ac 2 -i hw:1,0 -strict -2 -f x11grab -framerate 30 -video_size 1360x768 -i :0.0 \
-c:v libx264 -pix_fmt yuv420p -qp 0 -preset ultrafast vids/$(date +%Y-%m-%d_%H:%M%S).mp4
ffmpeg version N-92507-g027f032-0ubuntu0.16.04.1 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.3.0-27ubuntu1~18.04)
  configuration: --prefix=/home/jack/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/jack/ffmpeg_build/include --extra-ldflags=-L/home/jack/ffmpeg_build/lib --bindir=/home/jack/bin --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --cc=gcc --cxx=g++ --enable-cross-compile --enable-version3 --enable-shared --disable-stripping --disable-decoder=libopenjpeg --enable-avresample --enable-avisynth --enable-libass --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwavpack --extra-cflags=-fPIC --enable-libx265 --enable-libxvid --enable-opengl --enable-libdc1394 --enable-frei0r --enable-libx264 --enable-libpulse --enable-indev=alsa --enable-outdev=alsa --enable-static --disable-debug --enable-libwebp --enable-libspeex --enable-fontconfig --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-gray --enable-libopenjpeg --enable-libopus --enable-libsoxr --enable-libfribidi --enable-libzimg
  WARNING: library configuration mismatch
  avutil      configuration: --prefix=/home/jack/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/jack/ffmpeg_build/include --extra-ldflags=-L/home/jack/ffmpeg_build/lib --bindir=/home/jack/bin --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --cc=gcc --cxx=g++ --enable-cross-compile --enable-version3 --enable-shared --disable-stripping --disable-decoder=libopenjpeg --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libgme --enable-libgsm --enable-libmysofa --enable-libopenmpt --enable-librubberband --enable-libshine --enable-libssh --enable-libtwolame --enable-libxml2 --enable-libzvbi --enable-openal --enable-sdl2 --enable-libdrm --enable-ladspa --enable-chromaprint --enable-avisynth --enable-avresample --enable-libass --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwavpack --extra-cflags=-fPIC --enable-libx265 --enable-libxvid --enable-opengl --enable-libdc1394 --enable-frei0r --enable-libx264 --enable-libpulse --enable-indev=alsa --enable-outdev=alsa --enable-static --disable-debug --enable-libwebp --enable-libspeex --enable-fontconfig --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-gray --enable-libopenjpeg --enable-libopus --enable-libsoxr --enable-libfribidi --enable-libzimg --disable-doc --disable-programs --enable-libtesseract
  avcodec     configuration: --prefix=/home/jack/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/jack/ffmpeg_build/include --extra-ldflags=-L/home/jack/ffmpeg_build/lib --bindir=/home/jack/bin --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --cc=gcc --cxx=g++ --enable-cross-compile --enable-version3 --enable-shared --disable-stripping --disable-decoder=libopenjpeg --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libgme --enable-libgsm --enable-libmysofa --enable-libopenmpt --enable-librubberband --enable-libshine --enable-libssh --enable-libtwolame --enable-libxml2 --enable-libzvbi --enable-openal --enable-sdl2 --enable-libdrm --enable-ladspa --enable-chromaprint --enable-avisynth --enable-avresample --enable-libass --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwavpack --extra-cflags=-fPIC --enable-libx265 --enable-libxvid --enable-opengl --enable-libdc1394 --enable-frei0r --enable-libx264 --enable-libpulse --enable-indev=alsa --enable-outdev=alsa --enable-static --disable-debug --enable-libwebp --enable-libspeex --enable-fontconfig --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-gray --enable-libopenjpeg --enable-libopus --enable-libsoxr --enable-libfribidi --enable-libzimg --disable-doc --disable-programs --enable-libtesseract
  avformat    configuration: --prefix=/home/jack/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/jack/ffmpeg_build/include --extra-ldflags=-L/home/jack/ffmpeg_build/lib --bindir=/home/jack/bin --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --cc=gcc --cxx=g++ --enable-cross-compile --enable-version3 --enable-shared --disable-stripping --disable-decoder=libopenjpeg --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libgme --enable-libgsm --enable-libmysofa --enable-libopenmpt --enable-librubberband --enable-libshine --enable-libssh --enable-libtwolame --enable-libxml2 --enable-libzvbi --enable-openal --enable-sdl2 --enable-libdrm --enable-ladspa --enable-chromaprint --enable-avisynth --enable-avresample --enable-libass --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwavpack --extra-cflags=-fPIC --enable-libx265 --enable-libxvid --enable-opengl --enable-libdc1394 --enable-frei0r --enable-libx264 --enable-libpulse --enable-indev=alsa --enable-outdev=alsa --enable-static --disable-debug --enable-libwebp --enable-libspeex --enable-fontconfig --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-gray --enable-libopenjpeg --enable-libopus --enable-libsoxr --enable-libfribidi --enable-libzimg --disable-doc --disable-programs --enable-libtesseract
  avdevice    configuration: --prefix=/home/jack/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/jack/ffmpeg_build/include --extra-ldflags=-L/home/jack/ffmpeg_build/lib --bindir=/home/jack/bin --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --cc=gcc --cxx=g++ --enable-cross-compile --enable-version3 --enable-shared --disable-stripping --disable-decoder=libopenjpeg --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libgme --enable-libgsm --enable-libmysofa --enable-libopenmpt --enable-librubberband --enable-libshine --enable-libssh --enable-libtwolame --enable-libxml2 --enable-libzvbi --enable-openal --enable-sdl2 --enable-libdrm --enable-ladspa --enable-chromaprint --enable-avisynth --enable-avresample --enable-libass --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwavpack --extra-cflags=-fPIC --enable-libx265 --enable-libxvid --enable-opengl --enable-libdc1394 --enable-frei0r --enable-libx264 --enable-libpulse --enable-indev=alsa --enable-outdev=alsa --enable-static --disable-debug --enable-libwebp --enable-libspeex --enable-fontconfig --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-gray --enable-libopenjpeg --enable-libopus --enable-libsoxr --enable-libfribidi --enable-libzimg --disable-doc --disable-programs --enable-libtesseract
  avfilter    configuration: --prefix=/home/jack/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/jack/ffmpeg_build/include --extra-ldflags=-L/home/jack/ffmpeg_build/lib --bindir=/home/jack/bin --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --cc=gcc --cxx=g++ --enable-cross-compile --enable-version3 --enable-shared --disable-stripping --disable-decoder=libopenjpeg --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libgme --enable-libgsm --enable-libmysofa --enable-libopenmpt --enable-librubberband --enable-libshine --enable-libssh --enable-libtwolame --enable-libxml2 --enable-libzvbi --enable-openal --enable-sdl2 --enable-libdrm --enable-ladspa --enable-chromaprint --enable-avisynth --enable-avresample --enable-libass --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwavpack --extra-cflags=-fPIC --enable-libx265 --enable-libxvid --enable-opengl --enable-libdc1394 --enable-frei0r --enable-libx264 --enable-libpulse --enable-indev=alsa --enable-outdev=alsa --enable-static --disable-debug --enable-libwebp --enable-libspeex --enable-fontconfig --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-gray --enable-libopenjpeg --enable-libopus --enable-libsoxr --enable-libfribidi --enable-libzimg --disable-doc --disable-programs --enable-libtesseract
  avresample  configuration: --prefix=/home/jack/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/jack/ffmpeg_build/include --extra-ldflags=-L/home/jack/ffmpeg_build/lib --bindir=/home/jack/bin --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --cc=gcc --cxx=g++ --enable-cross-compile --enable-version3 --enable-shared --disable-stripping --disable-decoder=libopenjpeg --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libgme --enable-libgsm --enable-libmysofa --enable-libopenmpt --enable-librubberband --enable-libshine --enable-libssh --enable-libtwolame --enable-libxml2 --enable-libzvbi --enable-openal --enable-sdl2 --enable-libdrm --enable-ladspa --enable-chromaprint --enable-avisynth --enable-avresample --enable-libass --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwavpack --extra-cflags=-fPIC --enable-libx265 --enable-libxvid --enable-opengl --enable-libdc1394 --enable-frei0r --enable-libx264 --enable-libpulse --enable-indev=alsa --enable-outdev=alsa --enable-static --disable-debug --enable-libwebp --enable-libspeex --enable-fontconfig --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-gray --enable-libopenjpeg --enable-libopus --enable-libsoxr --enable-libfribidi --enable-libzimg --disable-doc --disable-programs --enable-libtesseract
  swscale     configuration: --prefix=/home/jack/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/jack/ffmpeg_build/include --extra-ldflags=-L/home/jack/ffmpeg_build/lib --bindir=/home/jack/bin --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --cc=gcc --cxx=g++ --enable-cross-compile --enable-version3 --enable-shared --disable-stripping --disable-decoder=libopenjpeg --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libgme --enable-libgsm --enable-libmysofa --enable-libopenmpt --enable-librubberband --enable-libshine --enable-libssh --enable-libtwolame --enable-libxml2 --enable-libzvbi --enable-openal --enable-sdl2 --enable-libdrm --enable-ladspa --enable-chromaprint --enable-avisynth --enable-avresample --enable-libass --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwavpack --extra-cflags=-fPIC --enable-libx265 --enable-libxvid --enable-opengl --enable-libdc1394 --enable-frei0r --enable-libx264 --enable-libpulse --enable-indev=alsa --enable-outdev=alsa --enable-static --disable-debug --enable-libwebp --enable-libspeex --enable-fontconfig --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-gray --enable-libopenjpeg --enable-libopus --enable-libsoxr --enable-libfribidi --enable-libzimg --disable-doc --disable-programs --enable-libtesseract
  swresample  configuration: --prefix=/home/jack/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/jack/ffmpeg_build/include --extra-ldflags=-L/home/jack/ffmpeg_build/lib --bindir=/home/jack/bin --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --cc=gcc --cxx=g++ --enable-cross-compile --enable-version3 --enable-shared --disable-stripping --disable-decoder=libopenjpeg --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libgme --enable-libgsm --enable-libmysofa --enable-libopenmpt --enable-librubberband --enable-libshine --enable-libssh --enable-libtwolame --enable-libxml2 --enable-libzvbi --enable-openal --enable-sdl2 --enable-libdrm --enable-ladspa --enable-chromaprint --enable-avisynth --enable-avresample --enable-libass --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwavpack --extra-cflags=-fPIC --enable-libx265 --enable-libxvid --enable-opengl --enable-libdc1394 --enable-frei0r --enable-libx264 --enable-libpulse --enable-indev=alsa --enable-outdev=alsa --enable-static --disable-debug --enable-libwebp --enable-libspeex --enable-fontconfig --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-gray --enable-libopenjpeg --enable-libopus --enable-libsoxr --enable-libfribidi --enable-libzimg --disable-doc --disable-programs --enable-libtesseract
  postproc    configuration: --prefix=/home/jack/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/jack/ffmpeg_build/include --extra-ldflags=-L/home/jack/ffmpeg_build/lib --bindir=/home/jack/bin --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --cc=gcc --cxx=g++ --enable-cross-compile --enable-version3 --enable-shared --disable-stripping --disable-decoder=libopenjpeg --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libgme --enable-libgsm --enable-libmysofa --enable-libopenmpt --enable-librubberband --enable-libshine --enable-libssh --enable-libtwolame --enable-libxml2 --enable-libzvbi --enable-openal --enable-sdl2 --enable-libdrm --enable-ladspa --enable-chromaprint --enable-avisynth --enable-avresample --enable-libass --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwavpack --extra-cflags=-fPIC --enable-libx265 --enable-libxvid --enable-opengl --enable-libdc1394 --enable-frei0r --enable-libx264 --enable-libpulse --enable-indev=alsa --enable-outdev=alsa --enable-static --disable-debug --enable-libwebp --enable-libspeex --enable-fontconfig --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-gray --enable-libopenjpeg --enable-libopus --enable-libsoxr --enable-libfribidi --enable-libzimg --disable-doc --disable-programs --enable-libtesseract
  libavutil      56. 23.101 / 56. 23.101
  libavcodec     58. 39.100 / 58. 39.100
  libavformat    58. 22.100 / 58. 22.100
  libavdevice    58.  6.100 / 58.  6.100
  libavfilter     7. 46.100 /  7. 46.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  4.100 /  5.  4.100
  libswresample   3.  4.100 /  3.  4.100
  libpostproc    55.  4.100 / 55.  4.100
Guessed Channel Layout for Input Stream #0.0 : stereo
Input #0, alsa, from 'hw:1,0':
  Duration: N/A, start: 1555730830.703161, bitrate: 1411 kb/s
    Stream #0:0: Audio: pcm_s16le, 44100 Hz, stereo, s16, 1411 kb/s
[x11grab @ 0x55c0767bc7c0] Stream #0: not enough frames to estimate rate; consider increasing probesize
Input #1, x11grab, from ':0.0':
  Duration: N/A, start: 1555730830.738274, bitrate: N/A
    Stream #1:0: Video: rawvideo (BGR[0] / 0x524742), bgr0, 1360x768, 30 fps, 1000k tbr, 1000k tbn, 1000k tbc
Stream mapping:
  Stream #1:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
  Stream #0:0 -> #0:1 (pcm_s16le (native) -> aac (native))
Press [q] to stop, [?] for help
[libx264 @ 0x55c0767c53c0] using cpu capabilities: MMX2 SSE2Fast LZCNT
[libx264 @ 0x55c0767c53c0] profile High 4:4:4 Predictive, level 3.2, 4:2:0 8-bit
[libx264 @ 0x55c0767c53c0] 264 - core 152 r2854 e9a5903 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=0 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=0 chroma_qp_offset=0 threads=3 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=250 keyint_min=25 scenecut=0 intra_refresh=0 rc=cqp mbtree=0 qp=0
[alsa @ 0x55c07679bf40] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)
Output #0, mp4, to 'vids/2019-04-20_11:2710.mp4':
  Metadata:
    encoder         : Lavf58.22.100
    Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p(progressive), 1360x768, q=-1--1, 30 fps, 15360 tbn, 30 tbc
    Metadata:
      encoder         : Lavc58.39.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
    Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s
    Metadata:
      encoder         : Lavc58.39.100 aac
frame=  584 fps= 30 q=-1.0 Lsize=   11144kB time=00:00:19.43 bitrate=4697.7kbits/s speed=0.996x    
video:10817kB audio:304kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.207573%
[libx264 @ 0x55c0767c53c0] frame I:3     Avg QP: 0.00  size:141800
[libx264 @ 0x55c0767c53c0] frame P:581   Avg QP: 0.00  size: 18331
[libx264 @ 0x55c0767c53c0] mb I  I16..4: 100.0%  0.0%  0.0%
[libx264 @ 0x55c0767c53c0] mb P  I16..4: 49.5%  0.0%  0.0%  P16..4:  0.4%  0.0%  0.0%  0.0%  0.0%    skip:50.1%
[libx264 @ 0x55c0767c53c0] coded y,uvDC,uvAC intra: 4.9% 0.9% 0.9% inter: 0.5% 0.1% 0.1%
[libx264 @ 0x55c0767c53c0] i16 v,h,dc,p: 97%  3%  0%  0%
[libx264 @ 0x55c0767c53c0] i8c dc,h,v,p: 96%  3%  1%  0%
[libx264 @ 0x55c0767c53c0] kb/s:4551.78
[aac @ 0x55c0767c6980] Qavg: 256.805
Exiting normally, received signal 2.
In [11]:
!ls -t vids
2019-04-20_11:2710.mp4
jupyternotebook.science
2019-03-14_10:5729.mp4
2019-03-14_10:3253.mp4
2019-03-14_11:2101.mp4
smaller.mkv
2019-03-15_07:4520.mp4
2019-03-15_07:4431.mp4
2019-03-15-07-14.mp4
001.mkv
2019-03-14_18:4226.mp4
XXXX.mkv
output2-WithAud.mp4
output.mp4
VIDEO.mp4
nosound.mp4
2019-03-14_10:2627.mp4
FFmpeg-Tutorial-Using-Jupyter-Notebook-to-Create-Youtube-Videos.mkv
Using-FFmpeg-with-Jupyter-Notebook-to-Create-Youtube-Videos-57seconds.mkv
BACK.mkv
Using-FFmpeg-with-Jupyter-Notebook-to-Create-Youtube-Videos.mkv

Create a bash script to capture screen video

the %%writefile scrCAP saves the filename scrCAP

In [312]:
!scrCAP
Usage must include a delay time in seconds Example:
scrCAP 10

In [18]:
%%writefile scrCAPxx
trash and junk
Writing scrCAPxx
In [20]:
%%writefile scrCAPxx
trash and junk
and a few things more
Overwriting scrCAPxx
In [ ]:
# %load scrCAPxx
trash and junk
and a few things more
In [17]:
%%writefile scrCAP
#!/bin/bash
if [ -z "$1" ]
  then
    echo "Usage must include a delay time in seconds Example:"
    echo "vidCAP 10"
    exit 0
fi
sleep $1
ffmpeg -y  -f alsa -ac 2 -i hw:1,0 -strict -2 -f x11grab -framerate 30 -video_size 1360x768 -i :0.0 \
-c:v libx264 -pix_fmt yuv420p -qp 0 -preset ultrafast vids/$(date +%Y-%m-%d_%H:%M%S).mp4
Overwriting scrCAP

Make the script scrCAP executable

In [ ]:
!chmod +x scrCAP
In [22]:
# Get the current directory
import os
os.getcwd()

## now the file can be run from the notebook or the terminal in the this directory
Out[22]:
'/home/jack/Desktop/MyLinuxToyBox/FFmpeg-Tutorial-Using-Jupyter-Notebook-to-Create-Youtube-Videos'
In [ ]:
./home/jack/Desktop/MyLinuxToyBox/FFmpeg-Tutorial-Using-Jupyter-Notebook-to-Create-Youtube-Videos/scrCAP
In [ ]:
!./scrCAP 5
In [23]:
!ls vids
2019-03-14_10:2627.mp4	2019-03-14_10:3253.mp4
2019-03-14_10:3203.mp4	nosound.mp4

Playback the capture

Created to capture 640x640 Instagram Video

In [12]:
%%HTML
<div style="width:646px;height:640px;border:3px solid black;padding:10px;">
    <video width="620" controls>
      <source src="vids/2019-04-20_11:2710.mp4" type="video/mp4">
      Your browser does not support HTML5 video.
    </video> <center>
    <h1 style="font-size:40px;color:navy;">JupyterJones Video</h1>
    </center><br/><center>
    <span>This video was generated for Instagram using Jupyer Notebook<br/>
    and FFmpeg command line. Below is the command line required.<br /><br />
        <p style = 'margin-left:125px;'>ffmpeg -y  -f alsa -ac 2 -i hw:1,0 -strict -2 -f x11grab \<br />
        -framerate 30 -video_size 1360x768 -i :0.0 \<br />
        -c:v libx264 -pix_fmt yuv420p -qp 0 -preset ultrafast \<br />
        vids/$(date +%Y-%m-%d_%H:%M%S).mp4</p>
    </span>
    </center>
    </div>

JupyterJones Video


This video was generated for Instagram using Jupyer Notebook
and FFmpeg command line. Below is the command line required.

ffmpeg -y -f alsa -ac 2 -i hw:1,0 -strict -2 -f x11grab \
-framerate 30 -video_size 1360x768 -i :0.0 \
-c:v libx264 -pix_fmt yuv420p -qp 0 -preset ultrafast \
vids/$(date +%Y-%m-%d_%H:%M%S).mp4

capture the file location 246x114 898 756

In [17]:
!ffmpeg -y  -f alsa -ac 2 -i hw:1,0 -strict -2 -f x11grab -framerate 30 -video_size 640x640 \
-i :0.0+252,114 -c:v libx264 -pix_fmt yuv420p -qp 0 -preset ultrafast -t 57 vids/instagram.mp4
ffmpeg version N-92507-g027f032-0ubuntu0.16.04.1 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.3.0-27ubuntu1~18.04)
  configuration: --prefix=/home/jack/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/jack/ffmpeg_build/include --extra-ldflags=-L/home/jack/ffmpeg_build/lib --bindir=/home/jack/bin --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --cc=gcc --cxx=g++ --enable-cross-compile --enable-version3 --enable-shared --disable-stripping --disable-decoder=libopenjpeg --enable-avresample --enable-avisynth --enable-libass --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwavpack --extra-cflags=-fPIC --enable-libx265 --enable-libxvid --enable-opengl --enable-libdc1394 --enable-frei0r --enable-libx264 --enable-libpulse --enable-indev=alsa --enable-outdev=alsa --enable-static --disable-debug --enable-libwebp --enable-libspeex --enable-fontconfig --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-gray --enable-libopenjpeg --enable-libopus --enable-libsoxr --enable-libfribidi --enable-libzimg
  WARNING: library configuration mismatch
  avutil      configuration: --prefix=/home/jack/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/jack/ffmpeg_build/include --extra-ldflags=-L/home/jack/ffmpeg_build/lib --bindir=/home/jack/bin --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --cc=gcc --cxx=g++ --enable-cross-compile --enable-version3 --enable-shared --disable-stripping --disable-decoder=libopenjpeg --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libgme --enable-libgsm --enable-libmysofa --enable-libopenmpt --enable-librubberband --enable-libshine --enable-libssh --enable-libtwolame --enable-libxml2 --enable-libzvbi --enable-openal --enable-sdl2 --enable-libdrm --enable-ladspa --enable-chromaprint --enable-avisynth --enable-avresample --enable-libass --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwavpack --extra-cflags=-fPIC --enable-libx265 --enable-libxvid --enable-opengl --enable-libdc1394 --enable-frei0r --enable-libx264 --enable-libpulse --enable-indev=alsa --enable-outdev=alsa --enable-static --disable-debug --enable-libwebp --enable-libspeex --enable-fontconfig --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-gray --enable-libopenjpeg --enable-libopus --enable-libsoxr --enable-libfribidi --enable-libzimg --disable-doc --disable-programs --enable-libtesseract
  avcodec     configuration: --prefix=/home/jack/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/jack/ffmpeg_build/include --extra-ldflags=-L/home/jack/ffmpeg_build/lib --bindir=/home/jack/bin --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --cc=gcc --cxx=g++ --enable-cross-compile --enable-version3 --enable-shared --disable-stripping --disable-decoder=libopenjpeg --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libgme --enable-libgsm --enable-libmysofa --enable-libopenmpt --enable-librubberband --enable-libshine --enable-libssh --enable-libtwolame --enable-libxml2 --enable-libzvbi --enable-openal --enable-sdl2 --enable-libdrm --enable-ladspa --enable-chromaprint --enable-avisynth --enable-avresample --enable-libass --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwavpack --extra-cflags=-fPIC --enable-libx265 --enable-libxvid --enable-opengl --enable-libdc1394 --enable-frei0r --enable-libx264 --enable-libpulse --enable-indev=alsa --enable-outdev=alsa --enable-static --disable-debug --enable-libwebp --enable-libspeex --enable-fontconfig --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-gray --enable-libopenjpeg --enable-libopus --enable-libsoxr --enable-libfribidi --enable-libzimg --disable-doc --disable-programs --enable-libtesseract
  avformat    configuration: --prefix=/home/jack/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/jack/ffmpeg_build/include --extra-ldflags=-L/home/jack/ffmpeg_build/lib --bindir=/home/jack/bin --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --cc=gcc --cxx=g++ --enable-cross-compile --enable-version3 --enable-shared --disable-stripping --disable-decoder=libopenjpeg --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libgme --enable-libgsm --enable-libmysofa --enable-libopenmpt --enable-librubberband --enable-libshine --enable-libssh --enable-libtwolame --enable-libxml2 --enable-libzvbi --enable-openal --enable-sdl2 --enable-libdrm --enable-ladspa --enable-chromaprint --enable-avisynth --enable-avresample --enable-libass --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwavpack --extra-cflags=-fPIC --enable-libx265 --enable-libxvid --enable-opengl --enable-libdc1394 --enable-frei0r --enable-libx264 --enable-libpulse --enable-indev=alsa --enable-outdev=alsa --enable-static --disable-debug --enable-libwebp --enable-libspeex --enable-fontconfig --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-gray --enable-libopenjpeg --enable-libopus --enable-libsoxr --enable-libfribidi --enable-libzimg --disable-doc --disable-programs --enable-libtesseract
  avdevice    configuration: --prefix=/home/jack/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/jack/ffmpeg_build/include --extra-ldflags=-L/home/jack/ffmpeg_build/lib --bindir=/home/jack/bin --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --cc=gcc --cxx=g++ --enable-cross-compile --enable-version3 --enable-shared --disable-stripping --disable-decoder=libopenjpeg --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libgme --enable-libgsm --enable-libmysofa --enable-libopenmpt --enable-librubberband --enable-libshine --enable-libssh --enable-libtwolame --enable-libxml2 --enable-libzvbi --enable-openal --enable-sdl2 --enable-libdrm --enable-ladspa --enable-chromaprint --enable-avisynth --enable-avresample --enable-libass --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwavpack --extra-cflags=-fPIC --enable-libx265 --enable-libxvid --enable-opengl --enable-libdc1394 --enable-frei0r --enable-libx264 --enable-libpulse --enable-indev=alsa --enable-outdev=alsa --enable-static --disable-debug --enable-libwebp --enable-libspeex --enable-fontconfig --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-gray --enable-libopenjpeg --enable-libopus --enable-libsoxr --enable-libfribidi --enable-libzimg --disable-doc --disable-programs --enable-libtesseract
  avfilter    configuration: --prefix=/home/jack/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/jack/ffmpeg_build/include --extra-ldflags=-L/home/jack/ffmpeg_build/lib --bindir=/home/jack/bin --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --cc=gcc --cxx=g++ --enable-cross-compile --enable-version3 --enable-shared --disable-stripping --disable-decoder=libopenjpeg --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libgme --enable-libgsm --enable-libmysofa --enable-libopenmpt --enable-librubberband --enable-libshine --enable-libssh --enable-libtwolame --enable-libxml2 --enable-libzvbi --enable-openal --enable-sdl2 --enable-libdrm --enable-ladspa --enable-chromaprint --enable-avisynth --enable-avresample --enable-libass --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwavpack --extra-cflags=-fPIC --enable-libx265 --enable-libxvid --enable-opengl --enable-libdc1394 --enable-frei0r --enable-libx264 --enable-libpulse --enable-indev=alsa --enable-outdev=alsa --enable-static --disable-debug --enable-libwebp --enable-libspeex --enable-fontconfig --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-gray --enable-libopenjpeg --enable-libopus --enable-libsoxr --enable-libfribidi --enable-libzimg --disable-doc --disable-programs --enable-libtesseract
  avresample  configuration: --prefix=/home/jack/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/jack/ffmpeg_build/include --extra-ldflags=-L/home/jack/ffmpeg_build/lib --bindir=/home/jack/bin --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --cc=gcc --cxx=g++ --enable-cross-compile --enable-version3 --enable-shared --disable-stripping --disable-decoder=libopenjpeg --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libgme --enable-libgsm --enable-libmysofa --enable-libopenmpt --enable-librubberband --enable-libshine --enable-libssh --enable-libtwolame --enable-libxml2 --enable-libzvbi --enable-openal --enable-sdl2 --enable-libdrm --enable-ladspa --enable-chromaprint --enable-avisynth --enable-avresample --enable-libass --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwavpack --extra-cflags=-fPIC --enable-libx265 --enable-libxvid --enable-opengl --enable-libdc1394 --enable-frei0r --enable-libx264 --enable-libpulse --enable-indev=alsa --enable-outdev=alsa --enable-static --disable-debug --enable-libwebp --enable-libspeex --enable-fontconfig --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-gray --enable-libopenjpeg --enable-libopus --enable-libsoxr --enable-libfribidi --enable-libzimg --disable-doc --disable-programs --enable-libtesseract
  swscale     configuration: --prefix=/home/jack/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/jack/ffmpeg_build/include --extra-ldflags=-L/home/jack/ffmpeg_build/lib --bindir=/home/jack/bin --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --cc=gcc --cxx=g++ --enable-cross-compile --enable-version3 --enable-shared --disable-stripping --disable-decoder=libopenjpeg --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libgme --enable-libgsm --enable-libmysofa --enable-libopenmpt --enable-librubberband --enable-libshine --enable-libssh --enable-libtwolame --enable-libxml2 --enable-libzvbi --enable-openal --enable-sdl2 --enable-libdrm --enable-ladspa --enable-chromaprint --enable-avisynth --enable-avresample --enable-libass --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwavpack --extra-cflags=-fPIC --enable-libx265 --enable-libxvid --enable-opengl --enable-libdc1394 --enable-frei0r --enable-libx264 --enable-libpulse --enable-indev=alsa --enable-outdev=alsa --enable-static --disable-debug --enable-libwebp --enable-libspeex --enable-fontconfig --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-gray --enable-libopenjpeg --enable-libopus --enable-libsoxr --enable-libfribidi --enable-libzimg --disable-doc --disable-programs --enable-libtesseract
  swresample  configuration: --prefix=/home/jack/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/jack/ffmpeg_build/include --extra-ldflags=-L/home/jack/ffmpeg_build/lib --bindir=/home/jack/bin --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --cc=gcc --cxx=g++ --enable-cross-compile --enable-version3 --enable-shared --disable-stripping --disable-decoder=libopenjpeg --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libgme --enable-libgsm --enable-libmysofa --enable-libopenmpt --enable-librubberband --enable-libshine --enable-libssh --enable-libtwolame --enable-libxml2 --enable-libzvbi --enable-openal --enable-sdl2 --enable-libdrm --enable-ladspa --enable-chromaprint --enable-avisynth --enable-avresample --enable-libass --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwavpack --extra-cflags=-fPIC --enable-libx265 --enable-libxvid --enable-opengl --enable-libdc1394 --enable-frei0r --enable-libx264 --enable-libpulse --enable-indev=alsa --enable-outdev=alsa --enable-static --disable-debug --enable-libwebp --enable-libspeex --enable-fontconfig --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-gray --enable-libopenjpeg --enable-libopus --enable-libsoxr --enable-libfribidi --enable-libzimg --disable-doc --disable-programs --enable-libtesseract
  postproc    configuration: --prefix=/home/jack/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/jack/ffmpeg_build/include --extra-ldflags=-L/home/jack/ffmpeg_build/lib --bindir=/home/jack/bin --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --cc=gcc --cxx=g++ --enable-cross-compile --enable-version3 --enable-shared --disable-stripping --disable-decoder=libopenjpeg --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libgme --enable-libgsm --enable-libmysofa --enable-libopenmpt --enable-librubberband --enable-libshine --enable-libssh --enable-libtwolame --enable-libxml2 --enable-libzvbi --enable-openal --enable-sdl2 --enable-libdrm --enable-ladspa --enable-chromaprint --enable-avisynth --enable-avresample --enable-libass --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwavpack --extra-cflags=-fPIC --enable-libx265 --enable-libxvid --enable-opengl --enable-libdc1394 --enable-frei0r --enable-libx264 --enable-libpulse --enable-indev=alsa --enable-outdev=alsa --enable-static --disable-debug --enable-libwebp --enable-libspeex --enable-fontconfig --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-gray --enable-libopenjpeg --enable-libopus --enable-libsoxr --enable-libfribidi --enable-libzimg --disable-doc --disable-programs --enable-libtesseract
  libavutil      56. 23.101 / 56. 23.101
  libavcodec     58. 39.100 / 58. 39.100
  libavformat    58. 22.100 / 58. 22.100
  libavdevice    58.  6.100 / 58.  6.100
  libavfilter     7. 46.100 /  7. 46.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  4.100 /  5.  4.100
  libswresample   3.  4.100 /  3.  4.100
  libpostproc    55.  4.100 / 55.  4.100
Guessed Channel Layout for Input Stream #0.0 : stereo
Input #0, alsa, from 'hw:1,0':
  Duration: N/A, start: 1555731121.840488, bitrate: 1411 kb/s
    Stream #0:0: Audio: pcm_s16le, 44100 Hz, stereo, s16, 1411 kb/s
Input #1, x11grab, from ':0.0+252,114':
  Duration: N/A, start: 1555731121.875752, bitrate: N/A
    Stream #1:0: Video: rawvideo (BGR[0] / 0x524742), bgr0, 640x640, 30 fps, 30 tbr, 1000k tbn, 1000k tbc
Stream mapping:
  Stream #1:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
  Stream #0:0 -> #0:1 (pcm_s16le (native) -> aac (native))
Press [q] to stop, [?] for help
[libx264 @ 0x55f87661e600] using cpu capabilities: MMX2 SSE2Fast LZCNT
[libx264 @ 0x55f87661e600] profile High 4:4:4 Predictive, level 3.1, 4:2:0 8-bit
[libx264 @ 0x55f87661e600] 264 - core 152 r2854 e9a5903 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=0 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=0 chroma_qp_offset=0 threads=3 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=250 keyint_min=25 scenecut=0 intra_refresh=0 rc=cqp mbtree=0 qp=0
[alsa @ 0x55f8765f4f40] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)
Output #0, mp4, to 'vids/instagram.mp4':
  Metadata:
    encoder         : Lavf58.22.100
    Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p(progressive), 640x640, q=-1--1, 30 fps, 15360 tbn, 30 tbc
    Metadata:
      encoder         : Lavc58.39.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
    Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s
    Metadata:
      encoder         : Lavc58.39.100 aac
frame=  706 fps= 30 q=-1.0 Lsize=    4727kB time=00:00:23.50 bitrate=1647.9kbits/s speed=   1x    
video:4332kB audio:367kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.591463%
[libx264 @ 0x55f87661e600] frame I:3     Avg QP: 0.00  size:166770
[libx264 @ 0x55f87661e600] frame P:703   Avg QP: 0.00  size:  5598
[libx264 @ 0x55f87661e600] mb I  I16..4: 100.0%  0.0%  0.0%
[libx264 @ 0x55f87661e600] mb P  I16..4: 25.8%  0.0%  0.0%  P16..4:  0.3%  0.0%  0.0%  0.0%  0.0%    skip:73.9%
[libx264 @ 0x55f87661e600] coded y,uvDC,uvAC intra: 8.0% 0.6% 0.6% inter: 0.3% 0.0% 0.0%
[libx264 @ 0x55f87661e600] i16 v,h,dc,p: 97%  3%  0%  0%
[libx264 @ 0x55f87661e600] i8c dc,h,v,p: 99%  0%  0%  0%
[libx264 @ 0x55f87661e600] kb/s:1507.95
[aac @ 0x55f876621000] Qavg: 248.732
Exiting normally, received signal 2.
In [14]:
!ls vids
001.mkv
2019-03-14_10:2627.mp4
2019-03-14_10:3253.mp4
2019-03-14_10:5729.mp4
2019-03-14_11:2101.mp4
2019-03-14_18:4226.mp4
2019-03-15-07-14.mp4
2019-03-15_07:4431.mp4
2019-03-15_07:4520.mp4
2019-04-20_11:2710.mp4
BACK.mkv
FFmpeg-Tutorial-Using-Jupyter-Notebook-to-Create-Youtube-Videos.mkv
jupyternotebook.science
nosound.mp4
output2-WithAud.mp4
output.mp4
smaller.mkv
Using-FFmpeg-with-Jupyter-Notebook-to-Create-Youtube-Videos-57seconds.mkv
Using-FFmpeg-with-Jupyter-Notebook-to-Create-Youtube-Videos.mkv
VIDEO.mp4
XXXX.mkv
In [23]:
%%HTML
<div style="width:650px;height:640px;border:3px solid black;padding:10px;">
    <video width="620" controls>
      <source src="vids/instagram.mp4" type="video/mp4">
      Your browser does not support HTML5 video.
    </video>
    <center><br/>
    <h1 style="font-size:40px;color:navy;">JupyterJones Video</h1>
    </center><br/><center>
    <span>This video was generated for Instagram using Jupyer Notebook<br/>
    and FFmpeg command line. Below is the command line required.<br /><br />
        <p style = 'margin-left:125px;'>ffmpeg -y  -f alsa -ac 2 -i hw:1,0 -strict -2 -f x11grab \<br />
        -framerate 30 -video_size 1360x768 -i :0.0 \<br />
        -c:v libx264 -pix_fmt yuv420p -qp 0 -preset ultrafast \<br />
        vids/$(date +%Y-%m-%d_%H:%M%S).mp4</p>
    </span>
    </center>
</div>

JupyterJones Video


This video was generated for Instagram using Jupyer Notebook
and FFmpeg command line. Below is the command line required.

ffmpeg -y -f alsa -ac 2 -i hw:1,0 -strict -2 -f x11grab \
-framerate 30 -video_size 1360x768 -i :0.0 \
-c:v libx264 -pix_fmt yuv420p -qp 0 -preset ultrafast \
vids/$(date +%Y-%m-%d_%H:%M%S).mp4

create a script for a screen image capture

In [45]:
%%writefile imageCAP
#!/bin/bash
if [ -z "$1" ]
  then
    echo "Usage must include a delay time in seconds Example:"
    echo "scrCAP 10"
    echo ""
    exit 0
fi
sleep $1
ffmpeg -hide_banner -f x11grab -framerate 1 -video_size 1360x668 -i :0.0+0,100 -vframes 1 -y \
images/$(date +%Y-%m-%d_%H:%M%S).png
Overwriting imageCAP
In [50]:
print "this is a test \ all in one line"
this is a test \ all in one line

If you try to run the file:

!./imageCAP

.... and get

/bin/sh: 1: ./imageCAP: Permission denied

You will need to run the following to make the file executable

!chmod +x imageCAP

In [46]:
!ls 
addmeta
BACK.mkv
FFmpeg-Tutorial-Using-Jupyter-Notebook-to-Create-Youtube-Videos.jpg
FFmpeg-Tutorial-Using-Jupyter-Notebook-to-Create-Youtube-Videos.mkv
FFMPEG-Tutorial-YouTube-Video-Toolkit-Jupyter-Notebook-bak.ipynb
FFMPEG-Tutorial-YouTube-Video-Toolkit-Jupyter-Notebook.ipynb
imageCAP
images
InputFile.mkv
scrCAP
scrCAPxx
test.mp4
themesong-reverb.mp3
Untitled.ipynb
Using-FFmpeg-with-Jupyter-Notebook-to-Create-Youtube-Videos.mkv
Using-FFmpeg-with-Jupyter-Notebook-to-Create-Youtube-Videos-v1.mkv
V2.mkv
vids
In [51]:
!./imageCAP 2
[x11grab @ 0x55e2a47eaa80] Stream #0: not enough frames to estimate rate; consider increasing probesize
Input #0, x11grab, from ':0.0+0,100':
  Duration: N/A, start: 1552532849.776923, bitrate: N/A
    Stream #0:0: Video: rawvideo (BGR[0] / 0x524742), bgr0, 1360x668, 1 fps, 1000k tbr, 1000k tbn, 1000k tbc
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> png (native))
Press [q] to stop, [?] for help
Output #0, image2, to 'images/2019-03-14_11:0728.png':
  Metadata:
    encoder         : Lavf58.22.100
    Stream #0:0: Video: png, rgb24, 1360x668, q=2-31, 200 kb/s, 1 fps, 1 tbn, 1 tbc
    Metadata:
      encoder         : Lavc58.39.100 png
frame=    1 fps=0.0 q=-0.0 Lsize=N/A time=00:00:01.00 bitrate=N/A speed=11.9x    
video:75kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
In [38]:
!chmod +x imageCAP
In [52]:
!ls -rant images 
total 156
-rw-r--r-- 1 1000 1000 69988 Mar 14 11:05 2019-03-14_11:0509.png
drwxr-xr-x 5 1000 1000  4096 Mar 14 11:06 ..
drwxr-xr-x 2 1000 1000  4096 Mar 14 11:07 .
-rw-r--r-- 1 1000 1000 76461 Mar 14 11:07 2019-03-14_11:0728.png
In [68]:
!ls 
2019-03-13_10:58.mp4
Cheech_and_Chong-Basketball_Jones-Festival_Supreme_2014-okbcNOa1gVk.mkv
Cheech_and_Chong_Basketball_Jones_with_better_sound-xdzljz.mp4
FFMPEG-Tutorial-YouTube-Video-Toolkit-Jupyter-Notebook.ipynb
imageCAP
images
JavaScript-Notebook-Custom-riesco.github.io.ipynb
JupyterJones-theme.mp3
notebook.list
output2.jpg
scrCAP
themesong.mp3
Untitled.ipynb
vidCAP
vidimages
vids
YouTube-Channel-JupyterJones-Introduction.ipynb
In [286]:
from IPython.display import *
Audio("themesong.mp3", autoplay=True)
Out[286]:
In [66]:
#!/bin/bash
!ffmpeg -hide_banner -f x11grab -framerate 1 -video_size 1360x668 -i :0.0+0,100 -vframes 1 \
-y images/output3.jpg
[x11grab @ 0x5572dfdcba80] Stream #0: not enough frames to estimate rate; consider increasing probesize
Input #0, x11grab, from ':0.0+0,100':
  Duration: N/A, start: 1552533700.672617, bitrate: N/A
    Stream #0:0: Video: rawvideo (BGR[0] / 0x524742), bgr0, 1360x668, 1 fps, 1000k tbr, 1000k tbn, 1000k tbc
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> mjpeg (native))
Press [q] to stop, [?] for help
[swscaler @ 0x5572dfde6240] deprecated pixel format used, make sure you did set range correctly
Output #0, image2, to 'images/output3.jpg':
  Metadata:
    encoder         : Lavf58.22.100
    Stream #0:0: Video: mjpeg, yuvj444p(pc), 1360x668, q=2-31, 200 kb/s, 1 fps, 1 tbn, 1 tbc
    Metadata:
      encoder         : Lavc58.39.100 mjpeg
    Side data:
      cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
frame=    1 fps=0.0 q=7.0 Lsize=N/A time=00:00:01.00 bitrate=N/A speed=14.3x    
video:69kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
In [67]:
!ls images
2019-03-14_11:0509.png	2019-03-14_11:0728.png	output3.jpg  output3-TEXT.png
In [69]:
from PIL import Image
imgz = Image.open("images/output3.jpg")
print imgz.size
imgz
(1360, 668)
Out[69]:
In [ ]:
!locate *.ttf
In [70]:
from PIL import Image, ImageFont, ImageDraw

image = Image.open('images/output3.jpg')
w,h =image.size
draw = ImageDraw.Draw(image)
txt = "YouTube"
fontsize = 1  # starting font size
# portion of image width you want text width to be
img_fraction = 0.75
color = 'rgb(255, 255, 255)' # white color
fontstyle = "/home/jack/Jav8/jre/lib/fonts/LucidaSansDemiBold.ttf"
#fontstyle = "/usr/share/fonts/truetype/tlwg/Laksaman-Bold.ttf"
#fontstyle ="/usr/share/fonts/truetype/liberation/LiberationSans-Bold.ttf"
font = ImageFont.truetype(fontstyle,fontsize)
while font.getsize(txt)[0] < img_fraction*image.size[0]:
    # iterate until the text size is just larger than the criteria
    fontsize += 1
    font = ImageFont.truetype(fontstyle, fontsize)

# optionally de-increment to be sure it is less than criteria
fontsize -= 1
font = ImageFont.truetype(fontstyle, fontsize)

print 'final font size',fontsize
print font.getsize(txt)
MARGIN = (w-font.getsize(txt)[0])/2
HEIGHT = ((h-font.getsize(txt)[1])/2)-120
print HEIGHT
SPACE = font.getsize(txt)[1]
draw.text((MARGIN, HEIGHT), txt, fill=(255,0,0), font=font) # put the text on the image
draw.text((MARGIN, HEIGHT+SPACE), "Tool Kit", fill=(255,0,0), font=font) # put the text on the image
image.save('images/output3-TEXT.png') # save it
image
final font size 222
(1016, 215)
106
Out[70]: