node js

운영자 | 기사입력 2022/05/06 [02:47]
>
필자의 다른기사 보기 인쇄하기 메일로 보내기 글자 크게 글자 작게
node js
 
운영자   기사입력  2022/05/06 [02:47]

cat hello.js

==============

console.log('hi');

==============

node hello.js

hi

 

main.js

=====================================

var http = require('http');

var fs = require('fs');

 

const port = 8080

 

http.createServer(function (request, response) {

    console.log('request starting...');

 

    var filePath = '.' + request.url;

    console.log(filePath);

    fs.readFile(filePath, function(error, content) {

        response.writeHead(200, { 'Access-Control-Allow-Origin': '*' });

        if (error) {

            if(error.code == 'ENOENT'){

                fs.readFile('./404.html', function(error, content) {

                    response.end(content, 'utf-8');

                });

            }

            else {

                response.writeHead(500);

                response.end('Sorry, check with the site admin for error: '+error.code+' ..n');

                response.end();

            }

        }

        else {

            response.end(content, 'utf-8');

        }

    });

 

}).listen(port);

console.log(`Server running at http://127.0.0.1:${port}/`);

=======================================================

 

===================

 

[root@c01 hls]# cat main23.js

=====================================================

var ffmpeg = require('/usr/local/lib/node_modules/fluent-ffmpeg');

 

var rtsp="rtsp://theview:[email protected]:554/stream1";

//var host = ”

 var port = '8000';// var path = ‘/SampleVideo_big.mkv’

 

function callback() {  }

ffmpeg('input.mp4', { timeout: 432000 }).addOptions([

    '-profile:v baseline', // baseline profile (level 3.0) for H264 video codec

    '-level 3.0',

    '-s 640x360',          // 640px width, 360px height output video dimensions

    '-start_number 0',     // start the first .ts segment at index 0

    '-hls_time 10',        // 10 second segment duration

    '-hls_list_size 0',    // Maxmimum number of playlist entries (0 means all entries/infinite)

    '-f hls'               // HLS format

  ]).output('x/output.m3u8').on('end', callback).run()

 

 

var HLSServer = require('hls-server')

var http = require('http')

var fs = require('fs');

 

var server = http.createServer()

var hls = new HLSServer(server, {

  path: '/home2/inswave/hls',     // Base URI to output HLS streams

  dir: 'x'  // Directory that input files are stored

})

 

http.createServer(function (request, response) {

    console.log('request starting...');

 

    var filePath = '.' + request.url;

 

    fs.readFile(filePath, function(error, content) {

        response.writeHead(200, { 'Access-Control-Allow-Origin': '*' });

        if (error) {

            if(error.code == 'ENOENT'){

                fs.readFile('./404.html', function(error, content) {

                    response.end(content, 'utf-8');

                });

            }

            else {

                response.writeHead(500);

                response.end('Sorry, check with the site admin for error: '+error.code+' ..n');

                response.end();

            }

        }

        else {

            response.end(content, 'utf-8');

        }

    });

 

}).listen(port);

console.log(`Server running at http://127.0.0.1:${port}/`);

===========================================================

 

 

cat app.js

=====================================

const express = require('express')

const app = express()

const port = 3000

 

app.get('/', (req, res) => {

  res.send('Hello World!')

})

 

app.listen(port, () => {

  console.log(`Example app listening at http://localhost:${port}`)

})

=======================================

 ff.sh

=========================================

ffmpeg -rtsp_transport tcp -i rtsp://theview:[email protected]:554/stream1 -fflags flush_packets -max_delay 5 -flags -global_header -hls_time 5 -hls_list_size 3 -vcodec copy -y ./mp4/2/index.m3u8

================================================

 

트위터 트위터 페이스북 페이스북 카카오톡 카카오톡
기사입력: 2022/05/06 [02:47]  최종편집: ⓒ iwav