const ondata = (chunk) => {
console.log(chunk) //Giving - Buffer 00 00 00 1c 66 74 79 70 64 61..........
Streaming(chunk,"rtmps://live-api-s.facebook.com:443/rtmp/FB-108963845678778")
//Streaming function is given below in the next Block};
}
i have a function named ondata which is continuously giving buffer data like this:-
( actually this a Chunk of .MP4 file.)
`<Buffer 00 00 00 1c 66 74 79 70 64 61 73 68 00 00 00 00 69 73 6f 36 61 76 63 31 6d 70 34 31 00 00 02 ca 6d 6f 6f 76 00 00 00 6c 6d 76 68 64 00 00 00 00 df e2 ... 16334 more bytes>`
`<Buffer 14 75 dd ea 7a 72 ef df 4f 24 cb 83 c3 85 a3 17 60 26 87 7a 74 0b 49 e4 6f 09 65 ae c8 6c 7d 0e 02 b1 6b 4a df 63 61 ab d9 44 22 62 3c f6 0d 8c c9 b7 ... 16334 more bytes>`
Now I want to stream this Chunk data to `RTMP Server using FFMPEG
so I doing this:-
const child_process = require('child_process');
var Streaming = function (chunk, Rtmp_Uri) {
ffmpeg_process = child_process.spawn('ffmpeg', \[
'-re',
'-i', \`${chunk}\`, //Buffer 00 00 00 1c 66 74 79 70 64 61..........
'-stream_loop','-1',
'-f', 'flv',
'-profile:v', 'baseline',
'-pix_fmt', 'yuv420p',
'-c:a', 'aac',
'-acodec', 'mp3',
'-ar', '44100',
'-b:a', '128k',
'-vcodec', 'libx264',
'-bufsize', '600k',
'-vb', '400k',
'-maxrate', '3000k',
'-preset', 'ultrafast',
'-r', '30',
'-g', '30',
Rtmp_Uri //"rtmps://live-api-s.facebook.com:443/rtmp/FB-1089638456787788-0..
AbzJ3chy775fhjjjkW2";
\]);
return ffmpeg_process;
}
when I run this Streaming function nothing happens.
so can anyone tell me how to stream the Chunk data to the Rtmp server? or any FFmpeg command that stream Chunk data to rtmp server?
Thanks in Advance.
Related
How can I parse form-data manually at node js?
I get chunks of the large file at the server side. And can't merge it, because it will borrow RAM equals to the (file size + file info size).
As far as I understand, I can't use the libraries, such as multer/connect-busboy/connect-multiparty etc.
In simple terms, now I get following data at server side and can't figure out how to receive, example, a file name, and how to determine, which byte is responsible for the beginning of the file.
[1] Get request...
[1] data: <Buffer 2d 2d 2d 2d 2d 2d 57 65 62 4b 69 74 46 6f 72 6d 42 6f 75 6e 64 61 72 79 62 66 30 31 63 62 36 38 71 4d 41 4d 36 6d 51 31 0d 0a 43 6f 6e 74 65 6e 74 2d ... 65486 more bytes>
[1] data: <Buffer 02 10 00 00 01 ce 00 00 01 ef 00 00 14 e4 00 00 01 de 00 00 01 b2 00 00 01 d8 00 05 f0 1a 00 00 06 70 00 00 00 fa 00 00 00 cf 00 00 0a 3b 00 00 01 4a ... 65486 more bytes>
[1] data: <Buffer 31 52 2e 9a 5b df 11 19 5f c2 5d 38 ed db 23 00 06 05 bd 8f 71 e7 6b 03 9d 3a 88 e3 24 10 00 0f a1 10 43 82 ff 67 bd 5d eb 8e 59 fe a9 d3 e6 45 f2 9e ... 65486 more bytes>
[1] data: <Buffer 2b 6c cf 18 40 13 d8 fd 09 fa 56 25 e6 6d 6a 57 94 8c a4 9c d1 7b 99 bb 20 c0 21 e7 4a 1f 72 5a a5 3d 8e 84 5d 97 eb 1b 0f db b1 a9 81 f9 db ef 06 36 ... 65486 more bytes>
[1] data: <Buffer bb 29 4b 0d 06 1d 69 e1 c7 47 a7 99 c6 e4 c3 48 2e 85 6a b3 57 01 68 09 00 aa 6d b4 7b c7 07 2f 73 c0 c4 6b c4 48 9b 8f 81 64 8e 25 c7 a3 de c3 4f 2a ... 65486 more bytes>
[1] data: <Buffer 21 2b 1c dd 57 02 23 f5 43 a1 70 72 b4 8d 8d a8 4a 4b c1 e1 21 75 84 ed 07 00 34 de 5c 8d b0 0a 6f 99 60 28 34 b1 c5 bd a2 3c 3e d5 01 0f 62 57 a8 e8 ... 65486 more bytes>
[1] data: <Buffer 2d 96 e3 47 75 ce 25 63 77 26 15 96 b6 43 b9 d2 59 7d 12 c9 64 b2 11 f2 39 29 3e bf 83 1a f3 15 7b 14 ee f3 33 52 5c 39 34 75 06 41 2f e7 11 e8 26 4e ... 65486 more bytes>
[1] data: <Buffer 4a 9d 20 c7 a8 55 35 22 26 ff c7 b4 11 d9 6c 4d ce e1 a0 b2 b3 01 37 da 6a ad ae 98 fd 9b 8e 9c 8b 4a 27 8e e3 10 4a dc 80 f2 50 df 88 d9 c8 f9 ef 48 ... 65486 more bytes>
[1] data: <Buffer 52 ee b3 96 1f 7c af df fa 3f 9c 9a f7 01 20 7d 3f ea 4e 7e aa 4e d9 57 31 cb b5 f3 09 49 c7 ee 92 83 2e cb 58 d2 ea 1b b0 35 2a 3c 6c 27 75 0c d0 39 ... 65486 more bytes>
...more
...more
...and more
After receiving all the above data, I need to get file name and send each chunk of the file(not other info, such as name/mime type) to another client. (It's file sharing web resource)
Another solutions?
At the same time, I could to send the file separated manually by the chunks of type ArrayBuffer. Each chunk would be encoded additional information, like a "file name", "mime type". But in this case, I should to separate file at client side and get again the above problem the lack of memory.
A working solution, but a bit insecure. Send the file name and mime type separately from the main file data.
The part of the code responsible for sending data:
app.get(`/${senderId}/get`, (request, response) => {
let countChunks = 0;
// waiting for the sender's request now...
app.post(`/${senderId}/send`, (requestSender, responseSender) => {
// start sharing...
let countChunks = 0;
requestSender.on("data", (chunk) => {
if (countChunks === 0) {
// need get the name from the chunks
const fileName = "test_name";
response.setHeader("Content-Disposition", `attachment; filename="${fileName}"`);
}
countChunks += 1;
// need to get the first byte of the file data and start sending starting with it
response.write(chunk);
})
requestSender.on("end", () => {
response.end();
})
})
})
Hi websocket stream is not working in apple devices. Can I save live stream mp4 for mobile devices.
var nanocon = new WebSocket("wss://bintu-splay.nanocosmos.de/h5live/authstream?url=rtmp%3A%2F%2Fbintu-splay.nanocosmos.de%3A80%2Fsplay&stream="+stream+"&cid=579991&pid=63355099213&expires="+sec.expires+"&tag="+sec.tag+"&token="+sec.token+"&options="+sec.options+"");
nanocon.onmessage = function(onmsg)
{
const dataBuffer = onmsg.data;
const fileStream = Fs.createWriteStream('st/finalvideo.webm', {flags: 'a'});
fileStream.write(dataBuffer);
console.log(dataBuffer);
socket.send(onmsg.data);
}
And response data is
> {"eventType":"onUpdateSourceSuccess","onUpdateSourceSuccess":{"requestId":0,"count":0,"tag":""}}
> {"eventType":"onStreamInfo","onStreamInfo":{"haveVideo":true,"haveAudio":true,"mimeType":"video/mp4; codecs=\"avc1.42E01E, mp4a.40.2\"","prerollDuration":0,"videoInfo":{"width":1280,"height":720,"frameRate":30},"audioInfo":{"sampleRate":48000,"channels":2,"bitsPerSample":16}}}
> <Buffer 00 00 00 24 66 74 79 70 69 73 6f 35 00 00 00 01 61 76 63 31 69 73 6f 35 64 73 6d 73 6d 73 69 78 64 61 73 68 00 00 04 88 6d 6f 6f 76 00 00 00 6c 6d 76 ... >
> {"eventType":"onRandomAccessPoint","onRandomAccessPoint":{"streamTime":0}}
> <Buffer 00 00 00 a8 6d 6f 6f 66 00 00 00 10 6d 66 68 64 00 00 00 00 00 00 00 00 00 00 00 4c 74 72 61 66 00 00 00 10 74 66 68 64 00 02 00 00 00 00 00 01 00 00 ... >
My question is how I get python to read a file where the text is in 16bit characters. The rest of the post describes the situation.
I have a text file which is a playlist export from iTunes.
Here is a short section including the header
Name Artist Composer Album Grouping Work Movement Number Movement Count Movement Name Genre Size Time Disc Number Disc Count Track Number Track Count Year Date Modified Date Added Bit Rate Sample Rate Volume Adjustment Kind Equalizer Comments Plays Last Played Skips Last Skipped My Rating
Keyboard Works of the Masters Randolph Hokanson Pan125b 2054816 64 03/11/2017, 18:00 03/11/2017, 17:01 256 44100 MPEG audio file 1 03/11/2017, 17:02 4 08/03/2018, 16:07
08 Traccia 08 11159905 464 03/11/2017, 17:39 03/11/2017, 16:59 192 48000 MPEG audio file 1 03/11/2017, 16:59
09 Traccia 09 17787361 741 03/11/2017, 17:39 03/11/2017, 16:58 192 48000 MPEG audio file 5 08/03/2018, 10:58
10 Traccia 10 10128290 421 03/11/2017, 17:39 03/11/2017, 16:58 192 48000 MPEG audio file 1 03/11/2017, 16:58
When I use this code to read it, the program hangs. (The i holds the number of lines in the file). The hex dumps which follow seem to show the export from iTunes is in 16bit characters.
The complete code for reading the text file is
file_name="full path to file goes here"
f = open(file_name, "r")
i=227
for x in range(0, i):
line = f.readline()
When I read the code into text wrangler, selected all the text, and pasted it into a new document. The code worked fine.
A text dump of part of the original file looks like this to start with the new file following
00000000: FF FE 4E 00 61 00 6D 00 65 00 09 00 41 00 72 00 ..N.a.m.e...A.r.
00000010: 74 00 69 00 73 00 74 00 09 00 43 00 6F 00 6D 00 t.i.s.t...C.o.m.
00000020: 70 00 6F 00 73 00 65 00 72 00 09 00 41 00 6C 00 p.o.s.e.r...A.l.
00000030: 62 00 75 00 6D 00 09 00 47 00 72 00 6F 00 75 00 b.u.m...G.r.o.u.
00000040: 70 00 69 00 6E 00 67 00 09 00 57 00 6F 00 72 00 p.i.n.g...W.o.r.
00000050: 6B 00 09 00 4D 00 6F 00 76 00 65 00 6D 00 65 00 k...M.o.v.e.m.e.
00000060: 6E 00 74 00 20 00 4E 00 75 00 6D 00 62 00 65 00 n.t. .N.u.m.b.e.
00000070: 72 00 09 00 4D 00 6F 00 76 00 65 00 6D 00 65 00 r...M.o.v.e.m.e.
00000080: 6E 00 74 00 20 00 43 00 6F 00 75 00 6E 00 74 00 n.t. .C.o.u.n.t.
00000090: 09 00 4D 00 6F 00 76 00 65 00 6D 00 65 00 6E 00 ..M.o.v.e.m.e.n.
000000A0: 74 00 20 00 4E 00 61 00 6D 00 65 00 09 00 47 00 t. .N.a.m.e...G.
000000B0: 65 00 6E 00 72 00 65 00 09 00 53 00 69 00 7A 00 e.n.r.e...S.i.z.
000000C0: 65 00 09 00 54 00 69 00 6D 00 65 00 09 00 44 00 e...T.i.m.e...D.
000000D0: 69 00 73 00 63 00 20 00 4E 00 75 00 6D 00 62 00 i.s.c. .N.u.m.b.
000000E0: 65 00 72 00 09 00 44 00 69 00 73 00 63 00 20 00 e.r...D.i.s.c. .
000000F0: 43 00 6F 00 75 00 6E 00 74 00 09 00 54 00 72 00 C.o.u.n.t...T.r.
New file
0000: 4E 61 6D 65 09 41 72 74 69 73 74 09 43 6F 6D 70 Name.Artist.Comp
0010: 6F 73 65 72 09 41 6C 62 75 6D 09 47 72 6F 75 70 oser.Album.Group
0020: 69 6E 67 09 57 6F 72 6B 09 4D 6F 76 65 6D 65 6E ing.Work.Movemen
0030: 74 20 4E 75 6D 62 65 72 09 4D 6F 76 65 6D 65 6E t Number.Movemen
0040: 74 20 43 6F 75 6E 74 09 4D 6F 76 65 6D 65 6E 74 t Count.Movement
0050: 20 4E 61 6D 65 09 47 65 6E 72 65 09 53 69 7A 65 Name.Genre.Size
Your file beginning looks like UTF-16 - see Byte order marks - Wikipedia
Use
file_name="full path to file goes here"
with io.open(file_name,'r', encoding='utf-16-le') as f:
for line in f:
# do something with line
when opening it.
There is no need to use range() or readlines() when reading line by line. If you really need the line-numbers use:
for lineNr,line in enumerate(f):
Only 255kb of data is being sent back, which is the default chunk size in gridfs. In mongolab, however I see that multiple chunks are being stored. So the problem is only with the read code. Here it is-
Retrive from gridfs and send response code-
app.get('/download/:fileid', function(req, res) {
var buffer = [];
var id = req.params.fileid;
var base64string;
var readStream = gfs.createReadStream({_id: id});
readStream.on('data', function(chunk) {
buffer.push(chunk);
});
readStream.on('end', function() {
base64string = Buffer(buffer.concat()[0]).toString('base64');
fs.writeFile("base64.txt", base64string);
res.statusCode = 200;
res.setHeader('Content-Type', 'application/json');
res.write(JSON.stringify({body : base64string}));
res.end();
});
});
[Edit]- Further analysis suggests that I am getting all the chunks. So the problem is in concatenation-
base64string = Buffer(buffer.concat()[0]).toString('base64');
[Edit]- Buffer.concat() does not work. How do I create a single buffer out of these three buffers?
[ <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 02 01 00 60 00 60 00 00 ff e1 0f 07 45 78 69 66 00 00 4d 4d 00 2a 00 00 00
08 00 06 01 32 00 02 00 00 00 14 00 00 ... >,
<Buffer a1 b1 42 92 56 81 43 43 5e b8 46 61 0f 96 09 c1 c4 e8 96 2b 75 52 54 21 2a 7d 46 ba c6 66 80 01 95 3c 3d a7 16
31 ed d9 56 b5 2b 91 5e 07 14 cb 2f ee ... >,
<Buffer a6 b6 92 5a 4f 1a da c9 e8 55 97 8e d1 da 4a b3 88 26 2f e5 2c 23 2a 54 10 59 1b 9e eb 35 e8 92 cc 2e da 8b 16
91 d3 e2 91 93 99 62 e0 8e a3 80 56 aa ... >,
<Buffer 71 e6 83 65 5e b0 f1 5f 61 a6 21 a3 68 83 be 72 0b 7a 7d 47 d6 d3 69 ee 59 37 92 1a de 06 8a 22 2a 3a a0 a3 1f
1a 0e 7e ec 67 3b 8f e9 c5 87 6b 41 5b ... > ]
[EDIT] Piping the readstream into response as per neils recommendation. However I get a syntax error on client side. [Unexpected Token]
RESPONSE CODE-
app.get('/download/:fileid', function(req, res) {
var id = req.params.fileid;
res.set('Content-Type', 'image/jpeg');
gfs.createReadStream({_id: id}).pipe(res); });
CLIENT CODE-
download() {
this._http.get('http://localhost:9000/download/' + this._fileid)
.map(response => response.json())
.subscribe(
data => {
console.log(data);
//this.image = data.body;
},
err => console.log('Error is..:' + err)
);;
}
I'm developing a BitTorrent client and I'm having trouble getting answers to my piece requests.
To debug, I followed a conversation between uTorrent and transmission using Wireshark and tried to imitate same conversation in my client. But it still doesn't work.
Below is an example conversation happening between my client and transmission. (my client also using -TR--- prefixed peer id, this is only for testing purposes and I'll change this)
Indented messages are coming from transmission, others are messages my client send.
Note that this conversation is not exactly same as how uTorrent and transmission would talk, because my client does not support fast extension yet. (BEP 6)
(Output is taken from Wireshark, lines starting with -- are my comments)
00000000 13 42 69 74 54 6f 72 72 65 6e 74 20 70 72 6f 74 .BitTorr ent prot
00000010 6f 63 6f 6c 00 00 00 00 00 10 00 00 f8 9e 0d fd ocol.... ........
00000020 9c fc a8 52 d9 7a d6 af a4 4d 8f 73 ce 70 b6 36 ...R.z.. .M.s.p.6
00000030 2d 54 52 32 38 34 30 2d 36 68 61 67 76 30 73 70 -TR2840- 6hagv0sp
00000040 34 67 37 6b 4g7k
-- ^ my handshake to transmission
00000000 13 42 69 74 54 6f 72 72 65 6e 74 20 70 72 6f 74 .BitTorr ent prot
00000010 6f 63 6f 6c 00 00 00 00 00 10 00 04 f8 9e 0d fd ocol.... ........
00000020 9c fc a8 52 d9 7a d6 af a4 4d 8f 73 ce 70 b6 36 ...R.z.. .M.s.p.6
00000030 2d 54 52 32 38 34 30 2d 72 73 35 68 71 67 32 68 -TR2840- rs5hqg2h
00000040 6e 70 68 64 nphd
-- ^ transmission answers to my handshake
00000044 00 00 00 1a 14 00 64 31 3a 6d 64 31 31 3a 75 74 ......d1 :md11:ut
00000054 5f 6d 65 74 61 64 61 74 61 69 33 65 65 65 _metadat ai3eee
-- ^ my extended handshake to transmission
00000044 00 00 00 72 14 00 64 31 3a 65 69 31 65 31 3a 6d ...r..d1 :ei1e1:m
00000054 64 31 31 3a 75 74 5f 6d 65 74 61 64 61 74 61 69 d11:ut_m etadatai
00000064 33 65 65 31 33 3a 6d 65 74 61 64 61 74 61 5f 73 3ee13:me tadata_s
00000074 69 7a 65 69 31 34 37 65 31 3a 70 69 35 31 34 31 izei147e 1:pi5141
00000084 33 65 34 3a 72 65 71 71 69 35 31 32 65 31 31 3a 3e4:reqq i512e11:
00000094 75 70 6c 6f 61 64 5f 6f 6e 6c 79 69 31 65 31 3a upload_o nlyi1e1:
000000A4 76 31 37 3a 54 72 61 6e 73 6d 69 73 73 69 6f 6e v17:Tran smission
000000B4 20 32 2e 38 34 65 00 00 00 02 05 80 2.84e.. ....
-- ^ transmission's extended handshake and bitfield
000000C0 00 00 00 01 01 .....
-- ^ transmission unchokes me
00000062 00 00 00 01 02 .....
-- ^ my interested message
00000067 00 00 00 0d 06 00 00 00 00 00 00 00 00 00 00 40 ........ .......#
00000077 00 .
-- ^ piece request
-- no answers ...
00000078 00 00 00 0d 06 00 00 00 00 00 00 00 00 00 00 40 ........ .......#
00000088 00 .
-- ^ piece request again, with 10 seconds interval
-- again no answers...
00000089 00 00 00 0d 06 00 00 00 00 00 00 00 00 00 00 40 ........ .......#
00000099 00 .
-- ^ piece request again, with 10 seconds interval
-- no answers...
Any ideas what am I doing wrong?
Thanks.
EDIT: I updated my client to send unchoke just after sending interested, but I'm still having same problem...
The problem was that I was requesting a piece bigger than the total size of the torrent.
The torrent I was using has 2 files, in total of 12KB. However the piece size of the torrent is 16KB and I was requesting 16KB piece even though the torrent file has only one piece and it's 12 KB in total.
After requesting 12KB instead of 16KB, the problem was solved.