webRTC convert webm to mp4 with ffmpeg.js - ffmpeg

I am trying to convert webM files to mp4 with ffmpeg.js.
I am recording a video from canvas(overlayer with some information) and recording the audio data from the video.
stream = new MediaStream();
var videoElem = document.getElementById('video');
var videoStream = videoElem.captureStream();
stream.addTrack(videoStream.getAudioTracks()[0]);
stream.addTrack(canvas.captureStream().getVideoTracks()[0]);
var options = {mimeType: 'video/webm'};
recordedBlobs = [];
mediaRecorder = new MediaRecorder(stream, options);
mediaRecorder.onstop = handleStop;
mediaRecorder.ondataavailable = handleDataAvailable;
mediaRecorder.start(100); // collect 100ms of data
function handleDataAvailable(event) {
if (event.data && event.data.size > 0) {
recordedBlobs.push(event.data);
}
}
mediaRecorder.stop();
This code works as expected and returns a webm video
var blob = new Blob(recordedBlobs, {type: 'video/webm'});
Now I want a mp4 file and checked the ffmpeg.js from muaz-khan.
The examples just show how to convert to mp4 when you have 2 single streams (audio and video). But I have one stream with an additional audio track. Can I convert such a stream to mp4? How can that be done?

As per the provided code sample, your recorder stream is having only one audio & one video tracks.
If your input file is having both Audio & Video, then you need to specify output codec for both tracks here as following.
worker.postMessage({
type: 'command',
arguments: [
'-i', 'audiovideo.webm',
'-c:v', 'mpeg4',
'-c:a', 'aac', // or vorbis
'-b:v', '6400k', // video bitrate
'-b:a', '4800k', // audio bitrate
'-strict', 'experimental', 'audiovideo.mp4'
],
files: [
{
data: new Uint8Array(fileReaderData),
name: 'audiovideo.webm'
}
]
});
Trans-coding the video inside browser is not recommend, as it will consume more CPU Time & Memory. And ffmpeg_asm.js is heavy. May be ok for POC :)
What is your use case? webm(vp8/vp9) is widely using these days.
Chrome will support following mime types:
"video/webm"
"video/webm;codecs=vp8"
"video/webm;codecs=vp9"
"video/webm;codecs=h264"
"video/x-matroska;codecs=avc1"
So you can get mp4 recording directly from chrome MediaRecorder with following hack
var options = {mimeType: 'video/webm;codecs=h264'};
mediaRecorder = new MediaRecorder(stream, options);
.....
//Before merging blobs change output mime
var blob = new Blob(recordedBlobs, {type: 'video/mp4'});
// And name your file as video.mp4

Related

Stop publisher.cycleVideo() mirroring whe using rear camera in Opentok

When I use publisher.cycleVideo() to switch cameras during a session, the video stream is always mirrored when using the rear camera. Is there any way to change the mirroring when using cycleVideo? I've tried the following code to switch the mirroring after cyclevideo to the rear camera but does nothing:
mirror=true; // Have tried with both mirror true and false
constraints = {
advanced: [{
mirror: mirror
}],
};
OT.getUserMedia().then((stream) => {
populateDeviceSources(audioSelector, 'audioInput');
populateDeviceSources(videoSelector, 'videoInput');
stream.getTracks().forEach(track => track.applyConstraints(constraints));
});

Cant make the google API process a WAV Audio

I want to transcribe a simple audio from a phone call.
I'm currently working with the Speech API
const speech = require('#google-cloud/speech').v1p1beta1;
The Information about the Audio I'm trying to transcribe:
Codec: PCM MU-LAW (mlaw)
Channels: Stereo
Sample Rate: 8000
Bits per Sample: 16
Duration: 35 seconds
I'm using this configuration for the API:
const requestGoogle = {
audio: {
uri: [ my audio location ]
},
config: {
audioChannelCount: 2,
enableSeparateRecognitionPerChannel: true,
enableAutomaticPunctuation: true,
languageCode,
model: 'default',
useEnhanced: true,
interactionType: 'PHONE_CALL',
encoding: 'MULAW',
microphoneDistance: 'NEARFIELD',
recordingDeviceType: 'PHONE_LINE',
}
};
When requesting that to the API I get a 400 response status with the error message:
{
"error": "3 INVALID_ARGUMENT: Invalid recognition 'config': bad channel count."
}
If someone could help me with this would be awesome, Thanks!
Convert the Codec data - from Codec: PCM MU-LAW (mlaw) - to - Codec: PCM - using G711 decoder.
Use the Channel : Mono.

Unable to send gifs using Twilio

I am trying to send this gif - https://media.giphy.com/media/YVBC4HdSpB7z2/giphy.gif - using Twilio but I am getting this error - Channel did not accept given content. Please see Channel specific error message for more information.
This is my code -
try{
$client = new Client(env('TWILIO_SID'), env('TWILIO_TOKEN'));
$send = $client->messages->create(
"whatsapp:".$my_phone_number, // Text this number
array(
'from' => "whatsapp:".env('TWILIO_NUMBER'),
'body' => 'hey',
'mediaUrl' => 'https://media.giphy.com/media/YVBC4HdSpB7z2/giphy.gif',
'contentType' => ['image/gif']
)
);
}catch (\Exception $exception){
}
The content-type is image/gif, which is acceptable by Twilio. So what might be the problem here?
Looking at the documentation for Twilio WhatsApp supported MIME types:
Accepted Content Types for Media
It calls out the following:
The Twilio API for WhatsApp supports sending and receiving images,
audio, PDF files, and video. The following formats are currently
supported:
Images: JPG, JPEG, PNG Audio: MP3, OGG, AMR Documents: PDF Video: MP4

Webrtc video/audio chat in Laravel+Vue.JS

I am making a video+voice chat in webrtc. The issue i am facing is that my voice is coming back to me and other person's to him. We both can listen each other but we both should not listen our own voices in our speakers. We are using headphones and away from each other. This is not an echo issue. If someone know any configuration option for this or any other solution please let me know.
VueJS:
export default {
props: ['conversation' , 'currentUser', 'threads'],
data() {
return {
data:"",
conversationId : this.conversation.conversationId,
channel : this.conversation.channel_name,
messages : this.conversation.messages,
withUser : this.conversation.user,
text : '',
constraints : {
audio: true,
video: false
},
}
}
I am using this api:
navigator.mediaDevices.getUserMedia({
audio: true,
video: false
})
Make sure the local video is muted. See e.g. the left video on https://simpl.info/rtcpeerconnection/
If you can hear yourself before you are even connected that is most likely the issue.

Laravel .mov validation

In a project I want to upload video. in my request I use 'path' => 'mimes:mp4,mov,avi,mpg,mpeg;quicktime|nullable',
When uploading a .mov video I always get the error "The video path must be a file of type: mp4, mov, avi, mpg, mpeg, quicktime.". The meme type of the video is video/quicktime.
Uploading .mp4 files works perfect, didn't test with other video types yet. Does anyone have a solution?
You can manually check for mime-type if the validation is not working for you:
$video = Input::file('path');
$mime = $video->getMimeType();
$accepted_mimes = array("video/x-flv", "video/mp4", "application/x-mpegURL",
"video/MP2T", "video/3gpp", "video/quicktime",
"video/x-msvideo", "video/x-ms-wmv");
if(in_array($mime, $accepted_mimes)) {
//valid video format begin upload
} else {
//invalid video mime type
// return back with errors
return redirect->back()->withErrors(['msg', 'Invalid video']);
}
For a list of all available mime-types see here
.mov Is just a container. So maybe the mime type / codec is still wrong. You should first verify this with a tool like this: https://mediaarea.net/. As a solution to you problem however (which is less secure) you could only verify the extension (pathname).
Here you see an example of a .mxf file but with an MPEG codec to help you understand that containers do not have only one mime type (and codec) that belongs to it most of the time.
Warning for just validating file extensions: this is very insecure and could lead to all kinds of trouble. Like people uploading php files or other type of files.
$Video= request('PostDetailsVideo');//this is name of posted file
$rules=[
'PostDetailsVideo' => 'required|mimetypes:video/x-ms-wmv,video/x-msvideo,video/quicktime,video/3gpp,video/MP2T,application/x-mpegURL,video/mp4,video/x-flv|max:32768'
];
$CheckIsVideo = Validator::make($request->all(),$rules);
if($CheckIsVideo->fails()){//this not video
return response()->json([
'Success'=> false,
], 200);
}
else
return response()->json([
'Success'=> true,
], 200);

Resources