Matt Jones Tech
  • Blog
  • Video Projects
  • Web Projects
  • How to Use ffmpeg (The Basics)

    The Problem

    It all started when Premiere Pro started glitching out. When I was trying to import a simple image sequence, like I’d done a thousand times before, it only imported the first 25% of the frames. Everything else was missing. There was no inconsistency in the file naming convention. Everything was sequential. There were no missing frames. Premiere is just glitchy.

    The Workaround

    I came up with an idea for a workaround. Instead of importing an image sequence, what if I just concatenated all those image files into a ProRes MOV? That way I can just drop the whole thing into Premiere with no problems. I tried to get Adobe Media Encoder to do that, but it wasn’t the most intuitive experience of my life. Every time I tried to import a sequence, it only gave me the first frame, and ended up rendering frame 1 over the entire length of the sequence. Solution? FFMPEG.

    What is FFMPEG?

    Ffmpeg is a command line application that allows you to manipulate images, video, and audio. It does take some getting used to, but once you get the hang of it, it is WELL worth the time you put in to learn the basics of the application. I do want to emphasize just the basics, as ffmpeg and all of its options are pretty vast.

    As a 3D artist and animator, I deal a lot with image sequences. Unfortunately Premiere and other NLEs can sometimes glitch out and not give you what you want when you import a sequence. FFMPEG allows you to concatenate a series of images and encode those frames into a single video file with a codec and container of your choosing.

    If you have other open source video applications like VLC player or Handbrake, you might already have ffmpeg installed on your system. You can check by running this in the terminal:

    ffmpeg -version

    If you don’t have it, you can get it easily by running:

    sudo apt install ffmpeg

    Now that you’ve got ffmpeg, you can do TONS of stuff with it. There’s a giant list of commands or you can check out the man page:

    man ffmpeg

    You can convert video files as simply as:

    ffmpeg -i input.mp4 output.avi

    The Tricks

    ffmpeg is used to initialize the program, -i is used to set your input file(s), and you can add more options like scale, fps, codecs, bit rates, and more with a long list of options available. For my purposes, I usually want to take a folder full of .png files and convert them into an MOV file for editing. For that, I can just ‘cd’ into the folder containing all my .png frames, and run something like:

    ffmpeg -f image2 -pattern_type glob -framerate 23.976 -i cyclesShotFour_*.png shotFour.mov

    Let’s break that down. The -f tack lets you indicate a format. To see all available formats, just run:

    ffmpeg -formats

    It’s worth noting that formats are different than codecs. To view the massive list of codecs available in ffmpeg, just run:

    ffmpeg -codecs

    Easy, right? Next we told ffmpeg to grab all the .png files in the current working directory matching the pattern we defined. In my example, all my files were named cyclesShotFour_0001.png, cyclesShotFour_0002.png, etc. There’s quite a few ways to define a pattern, and you can learn more here. Once ffmpeg has all your images defined, all you need to set your framerate and other stuff you may want and you’re good to go! Tack -framerate defines your framerate. At the end, just type the name of your output file. That’s it!

    Some of the other options that wasn’t mentioned in the above example, that I use quite frequently is setting the bitrate and the codec. The tacks for those options are -b:v (bitrate for video) -b:a (bitrate for audio) -c:v (codec for video) -c:a (codec for audio). So let’s say I want to encode a bunch of .jpg files into a Apple ProRes MOV file. Clearly, the output won’t have audio, so we don’t have to specify any audio options.

    ffmpeg -f image2 -c:v prores -framerate 23.976 -b:v 6000k -pattern_type glob -i frame*.jpg output.mov

    Anway, there are tons of different things you can do with ffmpeg, and it’s an absolutely amazing tool. It saved my butt just last week! Have fun and keep learning.

    matt

    February 26, 2019
    3D Animation, Linux, Ubuntu, Video Editing
    audio, bitrates, codecs, encoding, ffmpeg, formats, handbrake, linux, media, postproduction, transcoding, video
  • Swap Memory: It’s Like Downloading More RAM

    How Do I Download More RAM?

    It’s kinda like changing the blinker fluid in your car. You can’t. You shouldn’t. I mean… stuff like that doesn’t exist. But, if you’re finding yourself in a situation where you are running shy on your current installed amount of RAM, is there anything you can do without hitting up Newegg for a few more RAM sticks? Luckily, you can! Read on to learn how to add swap memory in Ubuntu 18.04.

    Just recently, I tried rendering a complex Blender scene on my computer. Unfortunately it crashed before I ever saw the first tile start to render. Blender was all like, “ERROR: Out of Memory”. I tried rendering again, but this time I opened my system resources window and monitored the RAM usage. I have 16GB of RAM installed, and 2GB of swap. As the scene loaded, the RAM started climbing up to the top of the usage graph, hit the top, then the swap started filling up. They both hit the top, and Blender crashed again.

    Fortunately, there’s a somewhat hacky thing called swap memory. So instead of purchasing extra RAM for your machine and going through all the trouble of installing it, you can add “virtual RAM” with just a few lines of code. This swap memory is designed as a sort of fail-safe should your machine demand more RAM memory than is physically installed. My problem was I was exceeding both my physical and my swap memory limitations. By default, Ubuntu was giving me 2GB of swap memory, and I had 16GB of RAM installed, but the Blender scene I was trying to render required more than my physical plus swap total of 18GB.

    Step One: Check If You Have Swap Enabled

    I’m using Ubuntu 18.04, so I can check my swap status by running this in the terminal:

    sudo swapon --show

    If there’s no output after running that command, you don’t have any swap memory enabled. If you do have swap enabled, you should get something like this:

    NAME      TYPE      SIZE USED PRIO
    /dev/sda2 partition 1.9G 0B -2

    The swap information in Ubuntu (size and settings and all that) can be found in /swapfile. To enable the swap file, you’d run:

    sudo swapon /swapfile

    To learn more about the ‘swapon’ and ‘swapoff’ command, you can check out:

    man swapon

    Step Two: Disable Your Swapfile

    Before you edit your swapfile, you need to disable it, otherwise you’ll get an error that’s something like “ERROR: file in use”. To do this, disable your swap file by running:

    sudo swapoff /swapfile

    Step Three: Edit Your Swapfile

    You can edit your current swapfile (or add a new swapfile if you don’t have one) using the fallocate command. You can learn more by running “man fallocate”. To increase your swap memory, run the following command (and change the number of GB to your preference):

    sudo fallocate -l 50GB /swapfile

    Step Four: Re-Enable Your Swapfile

    The -l flag stands for ‘length’ which essentially adjusts how much swap you’ve got. Next, you’ll need to reactivate your swap file by running

    sudo swapon /swapfile 

    Step Five: Confirm Changes Were Applied

    That should give your as many GB of swap as you need! You can double check your swap memory by running the Ubuntu System monitor by running:

    gnome-system-monitor

    and click the Resources tab at the top. You should see your swap memory reflect (not exactly, but pretty close) the amount of swap that you set using the fallocate command.

    Swap = 46.6 GB

    Now you should be able to render huge scenes in Blender without buying more RAM! Woot!

    Just a disclaimer: This is more of a note for myself so I can go back and visit this later. If you spot anything wrong or catch some mistakes, feel free to let me know! Thanks.

    matt

    February 19, 2019
    3D Animation, General Computing, Linux, Ubuntu
    animation, Blender, blender 3d, computing, general computing, hack, memory, RAM
  • Using DaVinci Resolve 15 on Ubuntu

    Default Experience

    If you’re like me, you’ve been on a quest to find the best video editing software that you can run on your Ubuntu Linux PC build. If you’ve been in the video world for any amount of time, you’ll probably know that Resolve 15 is arguably one of the most robust tools in the industry. Here’s my experience on running DaVinci Resolve 15 on Ubuntu 18.04

    After the initial install, everything seemed to have went fine, but when I clicked the new icon in my application tray… nothing happened. After a few more clicks, I uninstalled it and went on with my life. A few months later, DaVinci Resolve came up in conversation when talking about postproduction solutions for Linux. So I decided to give it another shot. Same issue.

    Unfortunately, in Linux_Installation_Instructions.PDF there is literally nothing telling you that you should install dependencies. I ended up finding the required dependencies somewhere online.

    Install Dependencies:

    sudo apt install libssl1.0.0 ocl-icd-opencl-dev fakeroot

    After that simple line in the terminal, Resolve fired right up in Ubuntu 18.04 On to the next hurdle: limited file type imports.

    Convert footage using FFMPEG.

    Only some file types work with Davinci Resolve 15. The ones I’ve tested that work are:

    • Apple ProRes (.mov)
    • Motion JPEG (.mov)

    If you can afford the space, I’d choose Apple ProRes before anything else. Unfortunately I haven’t found a way to specify 4:2:2, 4:4:4, or HQ preferences. It’s just ProRes, and from the looks of it, it’s the highest quality possible. You may be able to change this with the -q value. Still testing this.

    ffmpeg -i input.mov -vcodec prores -acodec pcm_s24le -max_muxing_queue_size 1024 output.mov

    In my 10+ years as a video editing professional, I have never used the motion jpeg codec. However, after running a few tests, playback in Resolve 15 is flawless, and the file size is the same, if not slightly smaller than the original file. My original test file was a Panasonic .MTS file clip at 1.7GB. After the transcode to motion jpeg, the result was 1.6GB, and played perfectly inside Resolve.

    The further I tested this transcode setting in ffmpeg, this reduced the file size just a little bit. The biggest clips were originally 4.3GB and the resulting files were hanging out around 2.3GB-2.7GB.

    ffmpeg -i input.MTS -vcodec mjpeg -acodec pcm_s24le -max_muxing_queue_size 1024 output.mov

    First Paid Project

    The only way to truly test if this is a viable alternative to Adobe CC on Mac or Windows is to actually test it on a live project with a real deadline. This may have been unwise, but I found it to be thoroughly worth it. I tried the above ffmpeg commands, only to realize after exporting that the resulting transcodes were sub-par. Pixelated garbage in, pixelated garbage out. So this time I hit up Handbrake. This one got me. Handbrake is essentially ffmpeg under the hood, but it doesn’t offer all the options that the command line does. So my exports out of Handbrake looked great, but there was no audio supported. On Ubuntu, Davinci Resolve only supports PCM audio, and that’s the one thing you can’t kick out of Handbrake (at least from the options I have).

    New Plan

    The original exports from my ffmpeg commands above looked like garbage, but the audio (pcm_s24le) was supported and sounded fine. So I ended up exporting Mpeg4 video out of Handbrake with no audio. I synced those clips up with the existing PCM audio in Resolve, and everything looked and sounded awesome. Next objective, getting an H.264/AAC file out of the free version of Resolve.

    Instead, I exported 20-30 minute bits of my 3 hour long timeline as Quicktime MOV files with MPEG4 codecs. They looked and sounded great, but were a touch big on the file size. Next. I just dropped them in order into Shotcut, and encoded the whole thing as H.264/ACC. Done. So for future reference, it probably wouldn’t hurt to just encode everything as Quicktime ProRes PCM, do my work in Resolve, then export QT ProRes PCM as an intermediate, then concatenate in Shotcut or Kdenlive. Kind of a wonky workaround for now, until I can afford the full version.

    Notes about the free version of Resolve 15

    The editing capabilities of the free version are quite nice, but they clamp down your options when it comes to exporting. First cheap shot: they don’t support H.264 encoding on export for Ubuntu. And at the time of this writing, DNxHD and DNxHR both cause Resolve to crash upon export. So without H.264 and DNxHD/HR… your export options become extremely limited. This is especially true if you have a long (3 hour) timeline that you need to deliver to a client. So is there a workaround? Fortunately there is one, but it requires a bit of hard drive space, extra time, and some FFMPEG knowledge. First, trying kicking out your timeline with these goofy settings:

    I thought a Kakadu was a bird…

    Here’s the gigantic and disheartening list of features that they hold back from the free version. Also, here’s another magic setting that seems even smaller than Kakadu:

    Project Complete

    I eventually exported the video in about 10 different sections, using MPEG4 encoded Quicktime MOV files. Decent quality, and decent file size. I ended up assembling all those color graded and sound-edited files in Shotcut and rendering the H.264 MP4 that I was looking to deliver in the first place. A super wonky workflow, but in hindsight, I think it will be worth picking up a copy of Lightworks for my edit work Resolve Studio for my color work, and cutting audio in Resolve’s Fairlight, or if Fairlight absolutely cannot handle the task at hand, I can always grab a copy of Ardour. Those softwares paired with Blender, Kritia, Inkscape, and GIMP, I don’t think there’s anything I’d be missing from Adobe CC that these platforms can’t provide.

    matt

    February 12, 2019
    Compositing, Linux, Motion Graphics, Video Editing
    blackmagic design, color grading, davinci resolve 15, postproduction, ubuntu, video editing
  • How to Access Your Desktop When You’re Away

    We’ve all been in a situation where a client calls you in a panic and they need something right away. Only problem is, the file they need is on your desktop at work or at home or… basically somewhere you’re not. Remote access can save you from trouble and offer a level of convenience like few other apps can.

    Where To Start

    There are tons of remote access applications out there, some free, some paid, closed source and open source. Previously, I used the free version of TeamViewer. That is, until they were hacked. So are there any decent applications that can just connect you without having to give up your email address? Thankfully, yes.

    Remmina

    Remmina is awesome. However, it can be terrible if it’s not set up properly, or if you’re not quite sure exactly how to use it. I’ve learned the hard way, and hopefully I can share enough info to get you up and running in no time!

    Install Remmina

    If you’re running Ubuntu, Remmina comes in the box. If not, you can grab the snap version by running this in the terminal:

    sudo snap install remmina

    Alternatively, you can grab the PPA like so:

    sudo add-apt-repository ppa:remmina-ppa-team/remmina-next
    sudo apt-get update
    sudo apt-get install remmina remmina-plugin-* libfreerdp-plugins-standard

    Uninstall Remmina

    If later on, you feel like this wasn’t working for you, or you just want to uninstall everything, just run:

    sudo apt-get install ppa-purge && sudo ppa-purge ppa:remmina-ppa-team/remmina-next

    Once you’ve got Remmina on your machine, you should see a window that looks kinda like this:

    So fresh and so clean

    Set up the Computer You Want To Access Remotely

    On the computer you want to access remotely, your first step is to enable screen sharing.

    Linux was hitting up that dark theme about 35 years before Apple. Just sayin

    By default, screen sharing is disabled, but for this to work, you’re gonna want to turn that on.

    Clickity click

    Now you should see the screen sharing options. You’ll want to allow others to access the screen, and prompt them with a password upon logging in.

    All good

    Establishing A Remote Connection

    Now, all you need to do is open Remmina on the computer you’ll be accessing FROM, and enter the IP address of your remote computer. This can be tricky if you’ve never done this before. If you’re at home and the computer you want to control is also at home, you’re more than likely on the same network. This is known as a local network connection. You can access your machine easily just by typing in its local IP address. However, if you try this from your local coffee shop wifi, it won’t work.

    What’s My IP Address?

    As mentioned earlier, there’s your public (external) IP address, and your private (internal) IP address. Which is which, and why does it matter? Your internal IP is used for local networks, like your home wifi that’s connecting your laptop, desktop, Chromecast, AppleTV, Roku, your friend’s phone, and your Alexa. All those devices have their own individual IP addresses, and are connected to your wireless router (wifi), that has its own public IP address, which is accessable over the internet.

    Use your PUBLIC IP Address

    The point of remote access is… being remote, AKA outside the network where your other computer is. So before you leave the house, go to whatsmyip.com and copy that address to your clipboard. This is your public IP address (hence, why you can just hit that website and it displays it to you).

    Set Up Your Router

    Paste the IP address you got from whatsmyip.com into your favorite browser. This will bring up the login page to your home router. If you’ve never seen this before, the username and password is typically printed on a sticker on the side or bottom of your router. Look for a button that says “Port Forwarding”. Find the computer that you want to connect to and create a new rule for it. Set your port number to 5900 and save.

    Set Up the Remote Computer

    You need to install a VNC server that will allow your remote computer to listen for incomming connections. You can do this by running:

    sudo apt install vnc4server

    Connect

    Okay, back to Remmina. In the main window, select VNC from the dropdown at the top.

    RDP is only for connecting to Windows, and SSH is just terminal access

    Next, type your IP from whatsmyip.com into the bar, and ending it with :5900. So, for example, yours might look something like this:

    65.88.88.127:5900

    Next, you’ll be prompted for that password you set up earlier.

    Tales from the Encrypt

    Then, badda bing, you’re looking at your remote desktop! You did it!

    such linux. much awesome.

    Did I miss a step? Having trouble? If you had any questions or ran into any issues while trying to set up your connection, feel free to reach out! Drop a comment below, or hit me up on Twitter.

    matt

    November 28, 2018
    General Computing, Lifestyle, Linux, Ubuntu
    desktop, networking, remmina, remote, remote access, remote desktop, remote work, ubuntu
Previous Page
1 … 3 4 5

Prove all things; hold fast that which is good. 1 Thess 5:21