<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Restless Ladder on Medium]]></title>
        <description><![CDATA[Stories by Restless Ladder on Medium]]></description>
        <link>https://medium.com/@restlessladder?source=rss-690971600a0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*2m3WQ2ba8eXmIdOOtjpNrg.png</url>
            <title>Stories by Restless Ladder on Medium</title>
            <link>https://medium.com/@restlessladder?source=rss-690971600a0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 07:46:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@restlessladder/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Poems 1 —  Seagulls]]></title>
            <link>https://medium.com/@restlessladder/poems-1-seagulls-ed6dc428e384?source=rss-690971600a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/ed6dc428e384</guid>
            <category><![CDATA[sweet]]></category>
            <category><![CDATA[funny]]></category>
            <category><![CDATA[seagulls]]></category>
            <category><![CDATA[short-poem]]></category>
            <dc:creator><![CDATA[Restless Ladder]]></dc:creator>
            <pubDate>Sat, 07 May 2022 13:10:33 GMT</pubDate>
            <atom:updated>2022-05-07T13:10:53.081Z</atom:updated>
            <content:encoded><![CDATA[<h3>Poem 1 — Seagulls</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qxobG0mCbsIyfwhAUDtXwA.jpeg" /></figure><blockquote>Seagulls flew over the sea<br>Cotton candy machine fell into their sight<br>Sugar is scattered, corpses on floor<br>Happy seagulls are eating sweet roll</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ed6dc428e384" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating cool ascii animation and watching in the terminal]]></title>
            <link>https://medium.com/@restlessladder/creating-cool-ascii-animation-and-watching-in-the-terminal-56f1c46ee35a?source=rss-690971600a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/56f1c46ee35a</guid>
            <category><![CDATA[ascii-art]]></category>
            <category><![CDATA[animation]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[terminal]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Restless Ladder]]></dc:creator>
            <pubDate>Sat, 07 May 2022 11:06:25 GMT</pubDate>
            <atom:updated>2022-05-07T11:06:25.570Z</atom:updated>
            <content:encoded><![CDATA[<p>Want to see cute anime-chan dancing on each terminal start? Or maybe something badass like jolly roger waving? Watch this. The code included.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6W8aN5YpMAD4Lv7wcQ8s-Q.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zPjlB2RV0dbZ4kKfFI6U-w.gif" /></figure><h3>Code</h3><p>This story is logical continuation of the <a href="https://medium.com/@restlessladder/watching-webcam-stream-in-terminal-using-ascii-characters-python-b2830dd6d121">watching webcam in terminal</a>, just different usage of the same code… The only difference is mode = VIDEO, and path to the video here.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e702302404405cad452129a3db84a486/href">https://medium.com/media/e702302404405cad452129a3db84a486/href</a></iframe><p>To run this animation on terminal start, just run this script in <em>$HOME/.bashrc</em></p><h3>Result</h3><p>Best of all this code works for the highly contrast videos. Like black background fire/lightning animations. Check this out:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7cSkXXMsOU6DFMMCa6HJCg.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U7ltB0ppKBR0uXnQS0CXSg.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TAiEQX8vBRthm412v_jqlQ.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rjouE_tMah4Ga8waBwUCzg.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=56f1c46ee35a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[15 best pictures I took on the east Lycian trail with locations]]></title>
            <link>https://medium.com/@restlessladder/15-best-pictures-i-took-on-the-east-lycian-trail-with-locations-d85c0b22a5c9?source=rss-690971600a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/d85c0b22a5c9</guid>
            <category><![CDATA[tourism]]></category>
            <category><![CDATA[turkey]]></category>
            <category><![CDATA[lycian-way]]></category>
            <category><![CDATA[tracking]]></category>
            <category><![CDATA[photography]]></category>
            <dc:creator><![CDATA[Restless Ladder]]></dc:creator>
            <pubDate>Sat, 07 May 2022 07:11:40 GMT</pubDate>
            <atom:updated>2022-05-07T07:11:40.683Z</atom:updated>
            <content:encoded><![CDATA[<h3>15 best pictures I took on the East Lycian trail with locations</h3><p>Better use Maps.me, to check the locations.</p><p><a href="https://goo.gl/maps/Ka3XacbEYG4uhimj8">36.674951, 30.511624</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ohviSl_o7x-sUCvjCunqVQ.jpeg" /></figure><p><a href="https://goo.gl/maps/woS64YQyar1USX1F9">36.632599, 30.445499</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-6MUQaJ8M7U8K7OFs2IsZQ.jpeg" /></figure><p><a href="https://goo.gl/maps/gq11crEftaECYY2J8">36.67587, 30.480702</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VTWYCojhS1H3vs_ee_mxjw.jpeg" /></figure><p><a href="https://goo.gl/maps/KEXJ4L9y4GU2z4bz9">36.523774, 30.544874</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ud3xK3vVvvFosnZRIeiHxA.jpeg" /></figure><p><a href="https://goo.gl/maps/3kr6Zgxjw82LhpoSA">36.533483, 30.560886</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mr-s_oPIgw50csk67SZSYg.jpeg" /></figure><p><a href="https://goo.gl/maps/epn6XyxZ35jau3cj6">36.675887, 30.524369</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zPJxEnJfHO03D3mnOSZ3lg.jpeg" /></figure><p><a href="https://goo.gl/maps/vinGEx7R9bvZkGp9A">36.533988, 30.560461</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0WeYJO0-nLFgeB3hm4pwGA.jpeg" /></figure><p><a href="https://goo.gl/maps/AnjuNTGp5Amp4XcW7">36.456462, 30.507676</a> (not sure about this loc)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u6MC8cz6OlsJYYmCNDy4Aw.jpeg" /></figure><p><a href="https://goo.gl/maps/WEqtgJSm4XQx7Vu19">36.470447, 30.510528</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_Gq_cCzjhgLiGES-jQ48TA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V8S_nPCJOmfsZ3OCI6yp8A.jpeg" /></figure><p><a href="https://goo.gl/maps/eMECuv9LVpd6zmMG8">36.522112, 30.551076</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7Gv1D-TmF4ctrnea9IMgjg.jpeg" /></figure><p><a href="https://goo.gl/maps/yjLuvcBk4SeG7d2U8">36.523645, 30.552709</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gTgLMbmR2tw4AYeJ2AVhCQ.jpeg" /></figure><p><a href="https://goo.gl/maps/bJeQa5p6aJhbxeoT7">36.546522, 30.413191</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ekYnpA_4GbCE7hhvghMeDA.jpeg" /></figure><p><a href="https://goo.gl/maps/heK9koMTHhh122s67">36.425253, 30.4839</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*npAbFf1lEhoG5cYX8h09fg.jpeg" /></figure><p><a href="https://goo.gl/maps/Gyg9He2zqgUGK4Yg7">36.396665, 30.473404</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hnezhTvcto5F1dilPDrb6g.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d85c0b22a5c9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Watching webcam stream in terminal, using ascii characters & Python]]></title>
            <link>https://medium.com/@restlessladder/watching-webcam-stream-in-terminal-using-ascii-characters-python-b2830dd6d121?source=rss-690971600a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/b2830dd6d121</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[streaming]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[terminal]]></category>
            <category><![CDATA[ascii-art]]></category>
            <dc:creator><![CDATA[Restless Ladder]]></dc:creator>
            <pubDate>Fri, 06 May 2022 21:13:55 GMT</pubDate>
            <atom:updated>2022-05-06T21:17:01.259Z</atom:updated>
            <content:encoded><![CDATA[<p>It may be helpful if you want to watch webcam on the machine without x-server, ssh-connected machine, or just took a picture of ascii yourself for the Instagram.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cMveXC1apGgwdJs4eRCrGA.gif" /></figure><h3>Requirements</h3><p>I’m using Ubuntu, so get ready for apt install command… Why am I using Konsole? because it’s <a href="https://stackoverflow.com/questions/3857052/why-is-printing-to-stdout-so-slow-can-it-be-sped-up">faster</a>, and displaying all without glitches VS ubuntu terminal, xterm or tmux.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2bf645e4e5c2efb2205e292a0c594f69/href">https://medium.com/media/2bf645e4e5c2efb2205e292a0c594f69/href</a></iframe><h3>Import</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/91e38c8fb271434c78adfbd3a6d3992e/href">https://medium.com/media/91e38c8fb271434c78adfbd3a6d3992e/href</a></iframe><h3>Webcam stream</h3><p>This code was created to transform recorded video to the ascii format too, but more about this in some future article…</p><h4>Play modes</h4><p>For now I will use REALTIME mode only, just skipping frames in order to get lower fps, that is needed to lower the stdout load. So we can watch webcam in lower fps, but higher resolution without glitches.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/98c6bb22db2467db1d173c278d15d725/href">https://medium.com/media/98c6bb22db2467db1d173c278d15d725/href</a></iframe><h4>Clearing console</h4><p>I gonna clear console after ctrl+c typed(SIGINT), before each frame printed and on ok program exit.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3173c02cdd2a341ca6a3a722458422ea/href">https://medium.com/media/3173c02cdd2a341ca6a3a722458422ea/href</a></iframe><h4>Reading video stream</h4><p>Here we doing all top-level stuff:</p><ul><li>reading webcam stream with opencv</li><li>transforming into grayscale frame</li><li>resizing to the terminal size</li><li>transforming into ascii-frame</li><li>printing it in the terminal.</li></ul><p>Also here I set the fps limit to max_fps arg, in 2 different ways, as written above…</p><p><strong>black2white_chars</strong> — contains chars, that will be used, to replace frame pixels. The pixel range is [0, 255] =&gt; black…white, so if you pass [‘.’, ‘+’, ‘@’], — the black pixels will be replaced with ‘.’, gray with ‘+’ and white with ‘@’. You can pass more different characters, to make image more funky.</p><p><strong>black2white_ansi_colors </strong>— contains <a href="https://en.wikipedia.org/wiki/ANSI_escape_code">ansi escape codes</a>, that will be used, to print certain pixel, respective to it’s value. It’s similar to <strong>black2white_chars, </strong>but instead of characters I using colors, which is <a href="https://en.wikipedia.org/wiki/ANSI_escape_code">ansi escape codes</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d646a245106733ad06f4a074350017cd/href">https://medium.com/media/d646a245106733ad06f4a074350017cd/href</a></iframe><h3>Frame to ascii</h3><p>Here I doing 2 things:</p><ul><li>replacing pixel grayscale value with ascii character, respective to black2white_chars</li><li>colorizing ascii chars, using ansi escape codes, respective to black2white_ansi_colors</li><li>vectorizing this process, using np.vectorize(), to get much faster code.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4f0d58c19435dd804ecca8239577e0da/href">https://medium.com/media/4f0d58c19435dd804ecca8239577e0da/href</a></iframe><h3>Print ascii frame</h3><p>So… I just concatenating all ascii chars, inserting \n to form rows, then clearing console and printing it with flush option to get all in terminal immediately(not allowing to buffer it).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/42ddf79e78dbc0d8063fb122422e75f0/href">https://medium.com/media/42ddf79e78dbc0d8063fb122422e75f0/href</a></iframe><h3>Main</h3><p>Here the fun stuff begins :) I picked few color pallets for frames colorizing and some nice set of ascii characters. Let’s try them all!!!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8bbf1ba2a808ea1763b082288e765e0f/href">https://medium.com/media/8bbf1ba2a808ea1763b082288e765e0f/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-SUlYE6JfYThe41lsNr2uQ.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D-a6dTZUko4gdHMUAkEVxw.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n5mij8GtM2agejSeVhs5aA.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b2830dd6d121" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[15 funniest South Park episodes]]></title>
            <link>https://medium.com/@restlessladder/15-funniest-south-park-episodes-aa233971dc46?source=rss-690971600a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/aa233971dc46</guid>
            <category><![CDATA[sarcastic]]></category>
            <category><![CDATA[south-park]]></category>
            <category><![CDATA[cartoon]]></category>
            <category><![CDATA[funny]]></category>
            <category><![CDATA[top-10]]></category>
            <dc:creator><![CDATA[Restless Ladder]]></dc:creator>
            <pubDate>Fri, 06 May 2022 17:27:41 GMT</pubDate>
            <atom:updated>2022-05-06T17:27:41.292Z</atom:updated>
            <content:encoded><![CDATA[<p>In case you’re wondering for something funny and sarcastic.</p><h3>1. S2 E3</h3><p><a href="https://www.southparkstudios.com/episodes/i3ry4k/south-park-ike-s-wee-wee-season-2-ep-3"><strong><em>Ikes wee wee</em></strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*aqOWQgGwL06xU-InnXs2Qg.png" /></figure><h3>2. S3 E17</h3><p><a href="https://www.southparkstudios.com/episodes/gxlmci/south-park-world-wide-recorder-concert-season-3-ep-17"><strong><em>World wide recorder concert</em></strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/1*Ja_HKxRYIbub-1VAQ3GPog.png" /></figure><h3>3. S4 E6</h3><p><a href="https://www.southparkstudios.com/episodes/dgwub0/south-park-cherokee-hair-tampons-season-4-ep-6"><strong><em>Cherokee hair tampons</em></strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EqiSdTVCoMDjsjXbhqMSSg.png" /></figure><h3>4. S5 E7</h3><p><a href="https://www.southparkstudios.com/episodes/t746u2/south-park-proper-condom-use-season-5-ep-7"><strong><em>Proper condom use</em></strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/965/1*e-YSLGf2A3tvLoQhc4WRhw.png" /></figure><h3>5. S5 E14</h3><p><a href="https://www.southparkstudios.com/episodes/8gq1cu/south-park-butters-very-own-episode-season-5-ep-14"><strong><em>Butters Very own episode</em></strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/897/1*UL77w2tOW76hYvawBqwzDw.png" /></figure><h3>6. S6 E8</h3><p><a href="https://www.southparkstudios.com/episodes/9sz0th/south-park-red-hot-catholic-love-season-6-ep-8"><strong><em>Red hot catholic love</em></strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5qQ33hFmrNwWQ68HJGwuZg.png" /></figure><h3>7. S6 E10</h3><p><a href="https://www.southparkstudios.com/episodes/g3404w/south-park-bebe-s-boobs-destroy-society-season-6-ep-10"><strong><em>Bebe’s boobs destroy society</em></strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*UMTwFAoUQ0WO7CZNFiYT6Q.png" /></figure><h3>8. S8 E3</h3><p><a href="https://www.southparkstudios.com/episodes/d7grkc/south-park-the-passion-of-the-jew-season-8-ep-3"><strong><em>The passion of the jew</em></strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/1*toXkrzBczP0cQZ5c8uW2-g.png" /></figure><h3>9. S10 E7</h3><p><a href="https://www.southparkstudios.com/episodes/h7679l/south-park-tsst-season-10-ep-7"><strong><em>Tsst</em></strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*fV4wQBGTMUoyYl4mFGc3Qg.png" /></figure><h3>10. S11 E2</h3><p><a href="https://www.southparkstudios.com/episodes/pomjzh/south-park-cartman-sucks-season-11-ep-2"><strong><em>Cartman sucks</em></strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ph_L9_3-i7m16ltPtHkPRA.png" /></figure><h3>11. S12 E3</h3><p><a href="https://www.southparkstudios.com/episodes/4r4367/south-park-major-boobage-season-12-ep-3"><strong><em>Major boobage</em></strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3fIPgAikmYVU91mBsO8Qgw.png" /></figure><h3>12. S13 E9</h3><p><a href="https://www.southparkstudios.com/episodes/mphf21/south-park-butters-bottom-bitch-season-13-ep-9"><strong><em>Butter’s bottom bitch</em></strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*v0jHnp7OqBXTvXZuHDnkPQ.png" /></figure><h3>13. S14 E2</h3><p><a href="https://www.southparkstudios.com/episodes/rb5qgf/south-park-the-tale-of-scrotie-mcboogerballs-season-14-ep-2"><strong><em>The Tale of Scrotie McBoogerBalls</em></strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/991/1*VUpGU3k63x-MrxKBlY1r-w.png" /></figure><h3>14. S16 E1</h3><p><a href="https://www.southparkstudios.com/episodes/c98dqj/south-park-reverse-cowgirl-season-16-ep-1"><strong><em>Reverse cowgirl</em></strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/1*8_6ENZ1DRR4GMRGrrs32wQ.png" /></figure><h3>15. S18 E7</h3><p><a href="https://www.southparkstudios.com/episodes/y3uvvc/south-park-grounded-vindaloop-season-18-ep-7"><strong><em>Grounded Vindaloop</em></strong></a><strong><em>.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NwIs41qu3JBljhmGFl7o9g.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aa233971dc46" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[15 metal tracks I listening again and again]]></title>
            <link>https://medium.com/@restlessladder/15-metal-tracks-i-listening-again-and-again-af23dc2c7aa1?source=rss-690971600a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/af23dc2c7aa1</guid>
            <category><![CDATA[music]]></category>
            <category><![CDATA[top-10]]></category>
            <category><![CDATA[metal]]></category>
            <category><![CDATA[heavy-metal]]></category>
            <dc:creator><![CDATA[Restless Ladder]]></dc:creator>
            <pubDate>Tue, 03 May 2022 23:11:15 GMT</pubDate>
            <atom:updated>2022-05-03T23:11:15.898Z</atom:updated>
            <content:encoded><![CDATA[<p>Do you want to find new juicy tracks? Here it comes! Share your favourites in comments.</p><h3>1 — Judas Priest — Painkiller</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FkO_EdmtR5Ck%3Flist%3DPLzVjpJnTUl80d_QQfUrcP1svahNpbRUQZ&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DkO_EdmtR5Ck&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FkO_EdmtR5Ck%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/e407587de151ce336a7a1b4b95bfe9d3/href">https://medium.com/media/e407587de151ce336a7a1b4b95bfe9d3/href</a></iframe><h3>2 — Airbourne — Breakin’ Outta Hell</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FgTYZWJEaOUA%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DgTYZWJEaOUA&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FgTYZWJEaOUA%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/43a2033087912b782ae72f86889e22d2/href">https://medium.com/media/43a2033087912b782ae72f86889e22d2/href</a></iframe><h3>3 — Motorhead — Ace of spades</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F86Iwytfa6ms%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D86Iwytfa6ms&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F86Iwytfa6ms%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/0686adbfd82c2872242552c842d8692f/href">https://medium.com/media/0686adbfd82c2872242552c842d8692f/href</a></iframe><h3>4 — Orden Ogan — The Things We Believe In</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F1BNYtqsjeEc%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D1BNYtqsjeEc&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F1BNYtqsjeEc%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/a550ff2e78ea54221ab5bcb844fc4aa4/href">https://medium.com/media/a550ff2e78ea54221ab5bcb844fc4aa4/href</a></iframe><h3>5— Powerwolf — Amen &amp; Attack</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fz90QYMeh0lk%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dz90QYMeh0lk&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fz90QYMeh0lk%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/42767e4b44c93691556e1a122aff3f53/href">https://medium.com/media/42767e4b44c93691556e1a122aff3f53/href</a></iframe><h3>6— Celldweller — Shapeshifter</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FkRrOq4NipQQ%3Flist%3DPLzVjpJnTUl80d_QQfUrcP1svahNpbRUQZ&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DkRrOq4NipQQ&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FkRrOq4NipQQ%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/9a686f2ed093ce50767be5f25a4a6657/href">https://medium.com/media/9a686f2ed093ce50767be5f25a4a6657/href</a></iframe><h3>7— Sticky Jams — Kickstart my heart</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FonlzPQS8lP4%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DonlzPQS8lP4&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FonlzPQS8lP4%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/18ccc2f9c6a1a888bd12e2900f4ab478/href">https://medium.com/media/18ccc2f9c6a1a888bd12e2900f4ab478/href</a></iframe><h3>8 — Story of the year — And Hero Will Drown</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FjIdeXOQutBM%3Flist%3DPLzVjpJnTUl80d_QQfUrcP1svahNpbRUQZ&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DjIdeXOQutBM&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FjIdeXOQutBM%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/ec638b11a6b5e4b7d498a3bb025f755c/href">https://medium.com/media/ec638b11a6b5e4b7d498a3bb025f755c/href</a></iframe><h3>9 — Mick Gordon — The only thing they fear is you</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FfOsB5AoKDJc%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DfOsB5AoKDJc&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FfOsB5AoKDJc%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/f81ee3260273c2450b1b4275ce38c2b5/href">https://medium.com/media/f81ee3260273c2450b1b4275ce38c2b5/href</a></iframe><h3>10— Mick Gordon — The Super Gore Nest</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fvfoj7t7NZkI%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dvfoj7t7NZkI&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fvfoj7t7NZkI%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/c678992d33529d5253dcd4de5dc08702/href">https://medium.com/media/c678992d33529d5253dcd4de5dc08702/href</a></iframe><h3>11— Mick Gordon — Gladiator</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fy7lyi3KvgCs%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dy7lyi3KvgCs&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fy7lyi3KvgCs%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/8d4c5a49a9727e45891f3f5a94ba6080/href">https://medium.com/media/8d4c5a49a9727e45891f3f5a94ba6080/href</a></iframe><h3>12 — Mick Gordon — Meathook</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FIgyX6K237xI%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DIgyX6K237xI&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FIgyX6K237xI%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/ff1988fc349742a81d36fa4c6a4384cf/href">https://medium.com/media/ff1988fc349742a81d36fa4c6a4384cf/href</a></iframe><h3>13— Alter Bridge — Metallingus</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fs2NgG0M-Hdk%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Ds2NgG0M-Hdk&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fs2NgG0M-Hdk%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/d1192bd69eb09b8910d553df581d35cf/href">https://medium.com/media/d1192bd69eb09b8910d553df581d35cf/href</a></iframe><h3>14 — Motorhead — Born to raise hell</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FlFbnQQ6t98Q%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DlFbnQQ6t98Q&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FlFbnQQ6t98Q%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/fabff2077f2f72b2bfa5cdb7132a3fbd/href">https://medium.com/media/fabff2077f2f72b2bfa5cdb7132a3fbd/href</a></iframe><h3>15 — Drowning pool — Bodies</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F04F4xlWSFh0%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D04F4xlWSFh0&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F04F4xlWSFh0%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/8b1e47d3632271588fff64996c1d3e9b/href">https://medium.com/media/8b1e47d3632271588fff64996c1d3e9b/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=af23dc2c7aa1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Real-time H-265 video stream decoding with c++ and libavcodec]]></title>
            <link>https://medium.com/@restlessladder/real-time-h-265-video-stream-decoding-with-c-and-libavcodec-d364072a80da?source=rss-690971600a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/d364072a80da</guid>
            <category><![CDATA[decoding]]></category>
            <category><![CDATA[cpp]]></category>
            <category><![CDATA[h265]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[streaming]]></category>
            <dc:creator><![CDATA[Restless Ladder]]></dc:creator>
            <pubDate>Tue, 03 May 2022 21:07:20 GMT</pubDate>
            <atom:updated>2022-05-03T21:18:49.027Z</atom:updated>
            <content:encoded><![CDATA[<p>This is second part of the libavcodec series, encoding is covered in the <a href="https://medium.com/@restlessladder/real-time-h-265-video-stream-encoding-with-c-and-libavcodec-77eafc20fa9e">first one</a>, and I’m going to decode packet, encoded in the first chapter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*F0soHIDr6Y92GfndwMSR9Q.png" /></figure><p>Let’s assume the encoded frame data was copied from packet to some container like protobuff or ros2 message and sent to the client, using certain transport like ZMQ socket or ros2 topic, etc….</p><p>Client received the message, and got to decode it now.</p><h3>Init frame &amp; packet</h3><p>Again we are using AVPacket for encoded and AVFrame for decoded data. More details about packet and frame you can get in the <a href="https://medium.com/@restlessladder/real-time-h-265-video-stream-encoding-with-c-and-libavcodec-77eafc20fa9e">encoding chapter</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc84fd7e54f677fc03853ff043c80367/href">https://medium.com/media/dc84fd7e54f677fc03853ff043c80367/href</a></iframe><h3>Init context</h3><p>The packet was encoded with H-265 codec, so we should specify it for decoding too. Also I defining sws context here it’s purpose descried below. I can create it when 1-th frame will be decoded and it’s heigth, width parameters became known.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cc9df41c7d1ed926f08f7938b9974ea8/href">https://medium.com/media/cc9df41c7d1ed926f08f7938b9974ea8/href</a></iframe><h4>Getting bytes per pixel</h4><p>Like I did in the encoding chapter…</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7cee23f9c0dcb795975c072dda9ca8c8/href">https://medium.com/media/7cee23f9c0dcb795975c072dda9ca8c8/href</a></iframe><p>Huuh, initialization finished, let’s move to the decoding part and enjoy some nice pictures…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JJxwPBRLVERq-DNJf7WVFA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R5z3qbP6tQNTFbQZ79XMGA.jpeg" /></figure><h3>Decoding loop</h3><h4>Fill packet</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4555868e870249ab37e4d71f41292a2f/href">https://medium.com/media/4555868e870249ab37e4d71f41292a2f/href</a></iframe><h4>Send Packet</h4><p>Send packet to the decoder algorithm. There are 6 possible return values of avcodec_send_packet(…):</p><p><strong>0</strong> — packet sent successfully</p><p><strong>AVERROR(EAGAIN)</strong> - input is not accepted in the current state, user must read output with avcodec_receive_frame(). Once all output is read, the packet should be resent, and the call will not fail with EAGAIN.</p><p><strong>AVERROR_EOF</strong> - the decoder has been flushed, and no new packets can be sent to it (also returned if more than 1 flush packet is sent)</p><p><strong>AVERROR(ENOMEM)</strong> - failed to add packet to internal queue, or similar other errors: legitimate decoding errors</p><p><strong>default</strong> — avcodec_receive_frame() error, probably first received NOT key frame, skipping (more about key frames in the <a href="https://medium.com/@restlessladder/real-time-h-265-video-stream-encoding-with-c-and-libavcodec-77eafc20fa9e">encoding chapter</a>). If frame is key — packet.flags == 1.</p><p>What you should do in each scenario depends on your custom code logic. I gonna just exit on each false scenario, except default, because it may happen. For example if client joined after encoder, and first frame it receive is not key frame, so it can’t decode it. In this case you can just wait for key frame, or send some signal to your encoder to send key frame now. Again, I explained how make encoder produce key frames in the <a href="https://medium.com/@restlessladder/real-time-h-265-video-stream-encoding-with-c-and-libavcodec-77eafc20fa9e">1th chapter</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e5b44f11c98af886e1d60386626affaf/href">https://medium.com/media/e5b44f11c98af886e1d60386626affaf/href</a></iframe><h4>Receive frame</h4><p>Receive decoded data from decoder algorithm. There are 5 possible return values:</p><p><strong>0</strong> — data decoded successfully.</p><p><strong>AVERROR(EAGAIN)</strong> — output is not available in the current state, user must try to send input…</p><p><strong>AVERROR_EOF</strong> — the encoder has been fully flushed, and there will be no more output packets.</p><p><strong>AVERROR(EINVAL) </strong>— codec not opened, or other errors…</p><p><strong>other negative values</strong> — some decoding errors</p><p>So, again cases handling depends on your custom code logic. For my encoder and decoder context options just 1th case can happen, otherwise — exit. More about options in the <a href="https://medium.com/@restlessladder/real-time-h-265-video-stream-encoding-with-c-and-libavcodec-77eafc20fa9e">encoding chapter</a>.</p><p>So if frame is decoded successfully I going to transfer it’s pixel format, because H265 codec supports only <em>AV_PIX_FMT_YUV420P </em>format, but I need<em> AV_PIX_FMT_RGB24</em> to show it to the client and I gonna use SwsContext in order to do this. The <em>YUVFrameToRGBData()</em> function is described below.</p><p>Also I performing check that decoder has only 1 out frame, assuming 1 in packet — 1 out frame real-time decoding.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e9f2637cd433a4fbba26da842ec22c94/href">https://medium.com/media/e9f2637cd433a4fbba26da842ec22c94/href</a></iframe><h4>Transforming pixel format</h4><p>Here we’re creating swsContext, using frame size data (assuming it isn’t gonna change). And transferring pix format and putting result in the ‘data’ array.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/27103abbae156f743f23aa0ba7e538db/href">https://medium.com/media/27103abbae156f743f23aa0ba7e538db/href</a></iframe><h3>Conclusion</h3><p>We have decoded data array, it’s width, height and bytes per pixel(channels), and we can restore initial video stream. And can enjoy more nice images.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w0tQPctV_fDqDwerDZ0PcQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2xtkuGRQhZYV9pE52PbXxQ.jpeg" /></figure><h3>Full example</h3><p>This tutorials just experiment and I don’t know if someone gonna read this stuff. Let me know in comments if you want to see full tutorial with web cam video stream reading, sending messages through network, using ZMQ socket and protobuff messages and input, output video stream visualization.</p><p>Also this knowledge is what I figured out in ~2 weeks on my own, so there may be <strong>MISTAKES</strong>. So better <strong>double-check</strong>, making something important.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d364072a80da" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Real-time H-265 video stream encoding with c++ and libavcodec]]></title>
            <link>https://medium.com/@restlessladder/real-time-h-265-video-stream-encoding-with-c-and-libavcodec-77eafc20fa9e?source=rss-690971600a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/77eafc20fa9e</guid>
            <category><![CDATA[h265]]></category>
            <category><![CDATA[video-encoding]]></category>
            <category><![CDATA[streaming]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[cpp]]></category>
            <dc:creator><![CDATA[Restless Ladder]]></dc:creator>
            <pubDate>Sun, 01 May 2022 22:42:21 GMT</pubDate>
            <atom:updated>2023-03-30T02:52:34.557Z</atom:updated>
            <content:encoded><![CDATA[<p>Trying to efficiently transfer video stream through internet in real time you will probably get stuck, searching for good library, codec, and then implementing it with lot of struggling and “Why it doesn’t work?!” screaming. I already did, and gonna save your life (or at least part of it).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*gvNXG68HjKkKemFR" /></figure><h3>Environment</h3><p>It’s just for debugging purposes, you don’t need exactly same environment to follow the guide…</p><ul><li>x86_64 architecture</li><li>Ubuntu 20.04</li><li>clang 10.0</li><li>Cmake 3.19.2</li><li>libavcodec major.minor.micro = 58.54.100<br>version is specified in libavcodec/version.h</li></ul><h3>Set-up</h3><p>The installation is pretty simple (at least for Ubuntu)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/620fa0a02d17130190dac4f484d101ae/href">https://medium.com/media/620fa0a02d17130190dac4f484d101ae/href</a></iframe><p>I somehow run in troubles, linking avcodec lib — I got “DSO missing from command line” error, trying link it to main exe, but error is gone when linking to intermediate shared lib…<em> Feel free to write solution in comments.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/63fbf8fd7e428bf770a822596fd58fe4/href">https://medium.com/media/63fbf8fd7e428bf770a822596fd58fe4/href</a></iframe><h3>Includes</h3><p>You should use extern “C” thing, to include it into your c++ code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d3e05553209da432f134909f404b2db/href">https://medium.com/media/3d3e05553209da432f134909f404b2db/href</a></iframe><h3>Context</h3><p>First of all you should choose codec and initialize AVCodecContext. I used H265 codec as effective one, frequently used in production as H264 codecs’ improved successor.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c7287731e2e2cb4e47089035bbe26678/href">https://medium.com/media/c7287731e2e2cb4e47089035bbe26678/href</a></iframe><p>No, it’s only beginning… Now we go setting context options.</p><h4>Context options</h4><p>The options<a href="https://drive.google.com/file/d/1j2JIdiX5xFYlle7kotK5q0IDshL3q5Sl/view?usp=sharing"> advices</a>. <a href="https://trac.ffmpeg.org/wiki/Encode/H.264">H264</a>, <a href="https://trac.ffmpeg.org/wiki/Encode/H.265">H265</a> options description.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/43e4eac605d8cdee80bade155897e7c5/href">https://medium.com/media/43e4eac605d8cdee80bade155897e7c5/href</a></iframe><h4>Get bytes per pixel value</h4><p>It’s may be helpful for calculating packet size and input frame size. The check is optional, it’s more like superstitions… The <em>AV_PIX_FMT_RGB24 </em>format explained in the “ SWS context” chapter.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7cee23f9c0dcb795975c072dda9ca8c8/href">https://medium.com/media/7cee23f9c0dcb795975c072dda9ca8c8/href</a></iframe><h4>Opening</h4><p>Finally… Parameters set! It’s time to open our context.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/858a0451a31e83057755fb70388505f4/href">https://medium.com/media/858a0451a31e83057755fb70388505f4/href</a></iframe><p>Bad news, we still need SOME initialization, but here is cat image:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/787/0*3Y5o1fLXMLEwyFq4" /></figure><p><strong>Remember, cats like programmers, so keep going…</strong></p><h3>SWS context</h3><p>Another thing, to make life harder, right? We need it for input images transformations like scaling and pixel format change.</p><p>H265|4 codec take as input only <em>AV_PIX_FMT_YUV420P </em>format, but what if we just reading video or webcam with cv2::VideoCapture, and our images in BGR24 or RGB24 format or want to effectively lower image resolution? Let’s assume RGB24 as input pixel format. 24 means 8 bits per channel (Red, Green, Blue), which is supposed to be [0; 255] unsigned char value. I used no scaling, thus same height, width passed.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7a1b79971f11ab3af5d2b99bf90075cb/href">https://medium.com/media/7a1b79971f11ab3af5d2b99bf90075cb/href</a></iframe><h3>Data containers</h3><h4>Frame</h4><p>Input image container. I will describe it’s fields, that will be used further:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/0*eQzz7QMuaux82l4F" /></figure><p>More pict_type details<a href="https://drive.google.com/file/d/1j2JIdiX5xFYlle7kotK5q0IDshL3q5Sl/view?usp=sharing"> here</a>. Also you can check libavcodec headers.</p><p>In short I frames is full size images, used as milestones by encoder and decoder. And P frames in simple words are some sort of difference between prev k frame and input frame. So if new user connects to encoder he need first I-frame in order to decode P-frames. And encoder produce I-frames not frequently, because of it’s big size. For some codecs you can set I-frames frequency, but I don’t know how to make it work for H265, and if it’s possible,<a href="https://superuser.com/questions/908280/what-is-the-correct-way-to-fix-keyframes-in-ffmpeg-for-dash"> someone say it’s not</a>.</p><p>Luckily you can make encoder produce I-frames by setting next 2 options:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f230cebf645a901fc5a0889b11ea5655/href">https://medium.com/media/f230cebf645a901fc5a0889b11ea5655/href</a></iframe><p>Otherwise — encoder will make this decision. It may be helpful when new user connected to stream and want to see picture right now, without waiting when encoder decide output key frame.</p><h4>Packet</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/0*lKHc1TNX5DCx4qu5" /></figure><p>Detailed description in libavcodec/avcodec.h</p><h4>Frame &amp; Packet init</h4><p>Now it’s time to allocate space and initialize some of frame and packet fields. The ‘data’ and ‘size’ packet and frame fileds set further.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6348f12780a3c5a495aa492c8b8b6d30/href">https://medium.com/media/6348f12780a3c5a495aa492c8b8b6d30/href</a></iframe><p>Hooray! Initialization completed! Let’s enjoy some careless images.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*vuVgigFZrAZm3M5S" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*W8AL7UluqURhaY_R" /></figure><h3>Encoding loop</h3><h4>Fill frame</h4><p>Now we going to transform input data format and fill frame with it. Also we will choose to make this frame key frame or not.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e3fbf09a431238f4221652a31b45feaa/href">https://medium.com/media/e3fbf09a431238f4221652a31b45feaa/href</a></iframe><h4>Send frame</h4><p>Now I going to send filled frame to the encoding algorithm. It’s implemented as state machine, and there are 5 possible outcomes, depends on avcodec_send_frame() return value:</p><p><strong>0 </strong>— Frame sent successfully</p><p><strong>AVERROR(EAGAIN) </strong>— Input is not accepted in the current state —</p><p>user must read output with avcodec_receive_packet(). Once all output is read, the packet should be resent, and the call will not fail with EAGAIN.</p><p><strong>AVERROR_EOF — </strong>The encoder has been flushed, and no new frames can be sent to it.</p><p><strong>AVERROR(EINVAL)</strong> — Codec not opened, refcounted_frames not set, it is a decoder, or requires flush.</p><p><strong>AVERROR(ENOMEM)</strong> — “Failed to add packet to internal queue, or similar other errors: legitimate decoding errors”</p><p>What you should do in each scenario depends on your use case. For example you can try read output frames on EAGAIN, or just exit with error. I going to exit with error on all error cases, because this errors not expected to happen with my code in any way, I believe :) . And if it’s happen I going to fix the code. Also remember keeping frame index in range [1, fps]</p><p>Detailed description in libavcodec/avcodec.h;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9e14302aa66818e8f3b438ae40b9a8a5/href">https://medium.com/media/9e14302aa66818e8f3b438ae40b9a8a5/href</a></iframe><h4>Receive packet</h4><p>The frame was sent, and now we are going to get our encoded data and put it in packet. There are 4 possible outcomes:</p><p><strong>0 </strong>— The packet received successfully, so we can save it and unref the packet. Also i want to check there is no more packets for me in encoder. Because i want make sure there is 1 input frame — 1 output packet for real-time encoding.</p><p><strong>AVERROR(EAGAIN)</strong> — Output is not available in the current state, user must try to send input…</p><p><strong>AVERROR_EOF </strong>— The encoder has been fully flushed, and there will be no more output packets.</p><p><strong>AVERROR(EINVAL) </strong>— Codec not opened, or it is an encoder other errors: legitimate decoding errors.</p><p>Note that packet data is allocated by encoder and should be ‘unrefed’ after packed was used. Frame ‘unrefed’ automaticly.</p><p>I’m not exiting on <strong>AVERROR(EAGAIN) </strong>scenario, because it may happen when context opt not set to ‘zerolatency’, so encoder will need to take few frames on input, before output packet can be produced.</p><p>Detailed description in libavcodec/avcodec.h</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e89134b21457f252519185474fe6129f/href">https://medium.com/media/e89134b21457f252519185474fe6129f/href</a></iframe><h3>Free resources</h3><p>Do this after encoder work finished to prevent memory leaks.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f137a9823681e8ab5c82ee66b6ff5505/href">https://medium.com/media/f137a9823681e8ab5c82ee66b6ff5505/href</a></iframe><h3>Comparing sizes</h3><p>The input frame size is const value = width*height*bytes_per_pix, and for 640x480 RGB image is 921600 Bytes, almost 1 MB.</p><p>The compressed Frame varies from 200 Bytes to 2 KB, depending on Video Stream content — more static image results in lower compressed frame size. <strong>So we decreased video stream traffic in more, than 50 times in mean.</strong></p><p><em>Horray! Let’s enjoy more pictures…</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*00EGZK0rppwLrDPf" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*ouuvwQDMRp3PnPh3" /></figure><h3>Info sources</h3><ul><li>Examples — <a href="https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples">ffmpeg github</a> (look for your lib version)</li><li>General details in the libavcodec/avcodec.h <strong>beginning</strong></li><li>Specific details in other lib headers</li><li><a href="https://trac.ffmpeg.org/wiki/Encode/H.264">H264</a>,<a href="https://trac.ffmpeg.org/wiki/Encode/H.265"> H265</a> codecs info on<a href="https://trac.ffmpeg.org/wiki"> ffmpeg wiki</a></li><li>Context options info on the<a href="https://superuser.com/questions/490683/cheat-sheets-and-presets-settings-that-actually-work-with-ffmpeg-1-0"> StackExchange</a></li><li>Context options<a href="https://drive.google.com/file/d/1j2JIdiX5xFYlle7kotK5q0IDshL3q5Sl/view?usp=sharing"> advices</a> and info guide</li><li><a href="http://ffmpeg.org/doxygen/trunk/encoding-example_8c-source.html">ffmpeg docs</a></li></ul><h3>Decoding</h3><p>Check out the <a href="https://medium.com/@restlessladder/real-time-h-265-video-stream-decoding-with-c-and-libavcodec-d364072a80da">next part</a>, where I decoding packet back into frame.</p><p>Also this knowledge is what I figured out in ~2 weeks on my own, so there may be <strong>MISTAKES</strong>. So better <strong>double-check</strong>, making something important.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=77eafc20fa9e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>