<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Oskar Ahlroth</title>
    <description>The latest articles on DEV Community by Oskar Ahlroth (@oskarahl).</description>
    <link>https://dev.to/oskarahl</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F437998%2F6ec48acc-5922-45e9-9947-e5db865aa7d9.png</url>
      <title>DEV Community: Oskar Ahlroth</title>
      <link>https://dev.to/oskarahl</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/oskarahl"/>
    <language>en</language>
    <item>
      <title>Automated lighthouse score to your PR (with Vercel and Github Actions)</title>
      <dc:creator>Oskar Ahlroth</dc:creator>
      <pubDate>Wed, 14 Oct 2020 14:46:48 +0000</pubDate>
      <link>https://dev.to/oskarahl/automated-lighthouse-score-on-your-pr-with-vercel-and-github-actions-2ng2</link>
      <guid>https://dev.to/oskarahl/automated-lighthouse-score-on-your-pr-with-vercel-and-github-actions-2ng2</guid>
      <description>&lt;p&gt;&lt;a href="https://github.com/OskarAhl/Lighthouse-github-action/blob/main/.github/workflows/lighthouse-on-vercel-preview-url.yml" rel="noopener noreferrer"&gt;TLDR give me the code now!&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Imagine a friendly Github Action bot that adds this to all the PRs (per commit) to your repo:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwh034wt0hxgtedhskzwo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwh034wt0hxgtedhskzwo.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Green Lighthouse metrics
&lt;/h3&gt;

&lt;p&gt;Web pages with Google Lighthouse metrics that are green (&amp;gt;= 90) tend to be faster, more accessible, and come with a better user experience. If you, as a developer, can help your company improve on these metrics it will directly impact your companies bottom line (+ help with your paid marketing efforts and SEO).&lt;/p&gt;

&lt;p&gt;The first step to green Lighthouse metrics is to measure the metrics. Make it easy for you, and your fellow developers, to see how your code changes impact the Lighthouse metrics by including the metrics as a part of your PRs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Github Action workflow
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Get the preview url for the PR (from Vercel).&lt;/li&gt;
&lt;li&gt;Run a Lighthouse audit on the preview url with &lt;a href="https://github.com/treosh/lighthouse-ci-action" rel="noopener noreferrer"&gt;this plugin&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Format the score to a table (+throw in a few emojis).&lt;/li&gt;
&lt;li&gt;Post a comment on the PR with the formatted score.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The comment on the PR will be a sticky comment - e.g. if the comment exists update it else add a new comment.&lt;/p&gt;

&lt;p&gt;The complete action can be found here &lt;a href="https://github.com/OskarAhl/Lighthouse-github-action/blob/main/.github/workflows/lighthouse-on-vercel-preview-url.yml" rel="noopener noreferrer"&gt;here&lt;/a&gt;. Feel free to copy paste this action to your repo.&lt;/p&gt;

&lt;h3&gt;
  
  
  Integrations used:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/treosh/lighthouse-ci-action" rel="noopener noreferrer"&gt;treosh/lighthouse-ci-action&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/marketplace/actions/sticky-pull-request-comment" rel="noopener noreferrer"&gt;sticky-pull-request-comment&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/marketplace/actions/capture-vercel-preview-url" rel="noopener noreferrer"&gt;vercel-preview-url-action&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Not using Vercel?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Update step 1 of the action (and get the preview url from e.g. Netlify or from your own deployment setup)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Limitations:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Always runs the Lighthouse audit on the root page.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Further improvements:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Combine the action with a &lt;a href="https://web.dev/use-lighthouse-for-performance-budgets/" rel="noopener noreferrer"&gt;budget&lt;/a&gt; to prevent PRs that bring the metrics below a set treshhold.&lt;/li&gt;
&lt;li&gt;Run the audit only on the pages affected by the PR.&lt;/li&gt;
&lt;li&gt;Compare the collected metrics with the actual metrics of your production site.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Did this help you out? Like and share the article and follow me on Twitter (i'm building &lt;a href="https://glitterly.app/" rel="noopener noreferrer"&gt;Glitterly&lt;/a&gt; - a web based video editor).&lt;/p&gt;

</description>
      <category>webperf</category>
      <category>webdev</category>
      <category>github</category>
      <category>devops</category>
    </item>
    <item>
      <title>FFMPEG: Overlay a video on a video after x seconds</title>
      <dc:creator>Oskar Ahlroth</dc:creator>
      <pubDate>Fri, 24 Jul 2020 10:07:31 +0000</pubDate>
      <link>https://dev.to/oskarahl/ffmpeg-overlay-a-video-on-a-video-after-x-seconds-4fc9</link>
      <guid>https://dev.to/oskarahl/ffmpeg-overlay-a-video-on-a-video-after-x-seconds-4fc9</guid>
      <description>&lt;p&gt;I’m currently working on a video editor and there is a feature where you can select a gif from Giphy and overlay it on top of your video after a header transition.&lt;/p&gt;

&lt;p&gt;With FFmpeg you can manipulate, combine, add effects with filters. There is a filter called &lt;code&gt;overlay&lt;/code&gt; - that we can use.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;This did not work as I expected:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;To apply a filter after a certain amount of time we'll use the option &lt;code&gt;enable&lt;/code&gt; (this option allows for &lt;a href="https://ffmpeg.org/ffmpeg-filters.html#Timeline-editing"&gt;timeline editing&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;The below script overlays the gif.mp4 on top of main_video.mp4 during the 1 - 3 seconds duration.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;ffmpeg &lt;span class="nt"&gt;-i&lt;/span&gt; main_video.mp4 &lt;span class="nt"&gt;-i&lt;/span&gt; gif.mp4 &lt;span class="nt"&gt;-filter_complex&lt;/span&gt;
  “[0:v][1:v]overlay&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;enable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'between(t,1,3)'&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;out]”
&lt;span class="nt"&gt;-map&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;out] complete.mp4
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;** &lt;code&gt;[0:v]&lt;/code&gt; --&amp;gt; first video (main_video.mp4)&lt;br&gt;
** &lt;code&gt;[1:v]&lt;/code&gt; --&amp;gt; the second video (gif.mp4)&lt;br&gt;
** &lt;code&gt;[out]&lt;/code&gt; --&amp;gt; first and second video combined into one after the overlay.&lt;/p&gt;

&lt;p&gt;Problem: gif.mp4 will start playing from the beginning so after 1 second has passed the gif video will be 1 second in already.&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Solution:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Use the &lt;code&gt;setpts&lt;/code&gt; filter to delay the overlay video (gif.mp4) start with x seconds.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;ffmpeg &lt;span class="nt"&gt;-i&lt;/span&gt; main_video.mp4 &lt;span class="nt"&gt;-i&lt;/span&gt; gif.mp4 &lt;span class="nt"&gt;-filter_complex&lt;/span&gt;
    “[1:v]setpts&lt;span class="o"&gt;=&lt;/span&gt;PTS-STARTPTS+1/TB[delayedGif]&lt;span class="p"&gt;;&lt;/span&gt;
     &lt;span class="o"&gt;[&lt;/span&gt;0:v][delayedGif]overlay&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;enable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'between(t,1,3)'&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;out]”
&lt;span class="nt"&gt;-map&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;out] complete.mp4
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The setpts filter evaluates its expression and assigns the value as the timestamp for the current frame it is processing. For a detailed explanation check out this &lt;a href="https://stackoverflow.com/questions/43333542/what-is-video-timescale-timebase-or-timestamp-in-ffmpeg"&gt;awesome post&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For &lt;code&gt;setpts=PTS-STARTPTS+1/TB&lt;/code&gt;:&lt;br&gt;
** &lt;code&gt;+1&lt;/code&gt; is the time in seconds we want to delay our offset &lt;br&gt;
** TB is the timebase.&lt;/p&gt;

&lt;p&gt;Too see the gif-overlay in action check out &lt;a href="https://app.glitterly.app/"&gt;Glitterly&lt;/a&gt; - a web based video editor I've been working on.&lt;/p&gt;

&lt;p&gt;I'm constantly posting more FFmpeg tips and tricks on Twitter (and happy to answer any questions!) - &lt;a href="https://twitter.com/AhlrothOskar"&gt;@AhlrothOskar&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>ffmpeg</category>
    </item>
  </channel>
</rss>
