Unable to send gifs using Twilio - laravel

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

Related

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.

Upload APK file via Gradle/Groovy Multipart Request task

I'm trying to implement a gradle task to upload an APK file to my web service using http-builder-ng. I'm struggling with the encoding part.
An APK file effectively is a ZIP format file, so I tried using the content type application/zip but it's not recognized by the encoders provided:
task publish(...) {
// ...
post {
request.contentType = 'multipart/form-data'
request.encoder 'multipart/form-data', OkHttpEncoders.&multipart
request.body = multipart {
part 'file', 'myApp.apk', 'application/zip', new File(System.getProperty('user.dir'), 'myApp.apk')
}
response.success { fs, content ->
prinln "success"
}
}
}
The error message is following:
Could not find encoder for content-type (application/zip)
Can anybody help me which encoder to use and how?

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);

webRTC convert webm to mp4 with ffmpeg.js

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

Upload file in S3 using Laravel 5.3

Installation Process
I followed this tutorial to install aws Package in Laravel 5.3
My Code is below
$s3 = \App::make('aws')->createClient('s3');
$s3->putObject(array(
'Bucket' => 'Bucket_Name',
'Key' => 'AWS_ACCESS_KEY_ID',
'SourceFile' => 'http://domainname/sample.txt',
));
I am trying a txt file with around 50 bytes contents and got below error.
A sha256 checksum could not be calculated for the provided upload
body, because it was not seekable. To prevent this error you can
either 1) include the ContentMD5 or ContentSHA256 parameters with your
request, 2) use a seekable stream for the body, or 3) wrap the
non-seekable stream in a GuzzleHttp\Psr7\CachingStream object. You
should be careful though and remember that the CachingStream utilizes
PHP temp streams. This means that the stream will be temporarily
stored on the local disk.
Am I missing something?
SourceFile must be a local file path. The Body parameter allows stream, so you should be able to do a request with guzzle and pass the body to it.
$client = new GuzzleHttp\Client();
$response = $client->get('http://domainname/sample.txt');
$s3->putObject([
'Bucket' => 'Bucket_Name',
'Key' => 'AWS_ACCESS_KEY_ID',
'Body' => $response->getBody(),
]);

Resources