3Speak - Video Encoder Nodes - Checking out & running locally to fix known issues

in voilk •  5 months ago

    Hello 3Speak & Hive Community members,

    Most of my posts are related to 3Speak Mobile App & its development.
    This post is slightly different. I'm going to attempt some of the known issues of video-encoder nodes. I'm going out of my comfort zone one more time & see what I can do & contribute here.

    video-encoding
    image-source

    What is HLS (HTTP Live Streaming)?

    • 3Speak is video streaming platforms
    • It uses HLS to provide a better experience to their audience.
    • Some times we are on the move and watching something while traveling. In such cases, HLS is very helpful.
    • If you're traveling & from 4G, your connection drops to poor reception, HLS comes in handy.
    • HLS adjusts automatically & decreases video quality to give you a stutter-free experience.
    • It automatically switches from HD (1080p) resolution to 480p video resolution for streaming.

    Where do I see HLS settings?

    • you can find it on the bottom-right corner of the player
    • Here is an example for you.

    3Speak.tv Video-Player with HLS Settings

    Why? Video-encoder node

    • Why do we need video-encoder nodes?
    • Users - they have raw videos in *.mp4, *.mov or any other extension.
    • These raw videos have to be processed to make it HLS compatible.
    • In video encoding process, original video is resized to 480p, 720p & 1080p
    • After that, each resized video is chopped down into media segments.
    • Once done, HLS Video (these 3 processed videos) is uploaded & pinned to IPFS infra.

    Why am I touching video-encoder?

    • There are some known issues with video-encoder nodes.
    • Improving IPFS pinning efficiency
    • Faster & efficient video encoding
    • Above are few examples to have better/improved video encoder nodes.
    • Instead of working & focusing only on mobile-app, this would be the new area which I would be exploring & try contributing something over here.

    Where is video-encoder node code?

    Prerequisites & basic setup

    nodejs & pm2 installation

    sudo apt update
    sudo apt upgrade -y
    curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
    sudo apt install nodejs -y
    sudo apt install npm -y
    hash -r
    sudo npm install -g npm
    npm i -g pm2
    

    Install ffmpeg

    sudo apt install ffmpeg
    

    Install Kubo(IPFS)

    wget https://dist.ipfs.tech/kubo/v0.18.1/kubo_v0.18.1_linux-amd64.tar.gz
    tar -xf kubo_v0.18.1_linux-amd64.tar.gz
    cd kubo
    chmod +x install.sh
    ./install.sh
    

    Run IPFS

    ipfs init --profile server
    pm2 start "ipfs daemon" --name ipfs
    

    Clone the project

    git clone https://github.com/spknetwork/video-encoder.git
    

    How did I do with my local setup?

    • README.md says follow this for local experimental node.
    • If you want to run the experimental client
    npx ts-node client.js
    
    • I tried it but It failed for me.
    ➜  video-encoder git:(main) npx ts-node client.js       
    node:internal/modules/cjs/loader:1080
      throw err;
      ^
    
    Error: Cannot find module './client.js'
    Require stack:
    - /video-encoder/imaginaryUncacheableRequireResolveScript
        at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
        at Function.resolve (node:internal/modules/cjs/helpers:125:19)
        at requireResolveNonCached (/video-encoder/node_modules/ts-node/dist/bin.js:321:16)
        at getProjectSearchDir (/video-encoder/node_modules/ts-node/dist/bin.js:291:40)
        at main (/video-encoder/node_modules/ts-node/dist/bin.js:193:27)
        at Object.<anonymous> (/video-encoder/node_modules/ts-node/dist/bin.js:351:5)
        at Module._compile (node:internal/modules/cjs/loader:1256:14)
        at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
        at Module.load (node:internal/modules/cjs/loader:1119:32)
        at Module._load (node:internal/modules/cjs/loader:960:12) {
      code: 'MODULE_NOT_FOUND',
      requireStack: [
        '/video-encoder/imaginaryUncacheableRequireResolveScript'
      ]
    }
    
    Node.js v18.18.2
    

    meme found on compile error

    • My best guess is - It's nodejs version.
    • Let's try switching the nodejs to 16
    • I did try & it didn't work.

    Run locally in dev mode

    • I tried npx ts-node client.js which failed for me.
    • So, I started looking into package.json.
    • There I found the script to run it locally as dev

    npm run dev

    • It did the trick & now, I've a local dev video-encoder node running.

    video encoder node running locally in dev mode

    What's next?

    • Now that I am able to run video-encoder-node locally in dev mode, I've following action items.
    • Get basic understanding of javascipt, typescript, ffpmeg commands.
    • Look at the existing source code of video-encoder-node.
    • Get an overview / basic understanding of how it works.
    • Try injecting a local video to encode & debug
    • Improve video-encoder-node efficiency by tweaking video-encoding ffmpeg commands

    What do you think?

    • What do you guys think?
    • Am I heading in right direction?
    • Do you have some tips to share? If yes, add it in comment section.

    Who am I?

    • I'm a Hive Witness
    • 3Speak App Developer
    • I also contributed to mobile-app for HiveAuth
    • Founder of HiveCurators Community - @hive-185924/@hivecurators

    Support me

    • Please upvote my content to motivate me.
    • Do you like the work I do?
    • Do you want me to keep going?
    • Please Reblog
    • Please help me connect with more communities
    • Please vote me as Hive Witness

    Vote me as Hive Witness


    Support @sagarkothari88

    About the SPK Network:

    The SPK Network is a decentralised Web 3.0 protocol that rewards value creators and infrastructure providers appropriately and autonomously by distributing reward tokens so that every user, creator, and platform can earn rewards on a level playing field.


    color3speak.png

    Important Links

    3Speak LinktreeSPK Network Linktree
    3Speak.tv3Speak Twitter3Speak Hive Blog3Speak Telegram
    3Speak in SpanishDownload Android AppDownload iOS AppDownload Desktop App
    Join 3Speak DiscordSetup Encoder NodeVote for SPK Network ProposalBadge Recipients
    appStoreGooglePlayStore

    Vote for 3Speak as Witness - Support @threespeak

    Vote for Sagarkothari88 as Witness - Support @sagarkothari88

      Authors get paid when people like you upvote their post.
      If you enjoyed what you read here, create your account today and start earning FREE VOILK!