cordova-plugin-video-editor
cordova-plugin-video-editor copied to clipboard
android.media.MediaCodec$CodecException: Error 0xfffffc0e
Below is the code which i am using to edit the video. Cordova version - 7.0.1 Plugin Version - "cordova-plugin-video-editor" spec="^1.1.3"
function videoCapture() {
var options = {
limit: 1,
height: 600,
width:600,
duration: 12
};
navigator.device.capture.captureVideo(onSuccess, onError, options);
function onSuccess(mediaFiles) {
var i, path, len;
for (i = 0, len = mediaFiles.length; i < len; i += 1) {
videopath = mediaFiles[i].fullPath;
vidname = mediaFiles[i].name;
console.log(mediaFiles);
// alert(path);
}
myFunction();
}
function onError(error) {
navigator.notification.alert('Error code: ' + error.code, null, 'Capture Error');
}
}
//alert(path);
var myVar;
function myFunction() {
myVar = setTimeout(alertFunc, 300);
}
function alertFunc() {
//alert('300ms');
alert(videopath);
videoCaptureSuccess();
}
var VideoEditorOptions = {
OptimizeForNetworkUse: {
NO: 0,
YES: 1
},
OutputFileType: {
M4V: 0,
MPEG4: 1,
M4A: 2,
QUICK_TIME: 3
}
};
function videoCaptureSuccess() {
// Wrap this below in a ~100 ms timeout on Android if
// you just recorded the video using the capture plugin.
// For some reason it is not available immediately in the file system.
console.log(videopath);
var file = videopath;
var videoFileName = 'video-name-here.mp4'; // I suggest a uuid
//alert(file.fullPath);
VideoEditor.transcodeVideo(
videoTranscodeSuccess,
videoTranscodeError,
{
fileUri: file,
outputFileName: videoFileName,
outputFileType: VideoEditorOptions.OutputFileType.MPEG4,
optimizeForNetworkUse: VideoEditorOptions.OptimizeForNetworkUse.YES,
saveToLibrary: true,
maintainAspectRatio: true,
width: 400,
height: 400,
videoBitrate: 1000000, // 1 megabit
audioChannels: 2,
audioSampleRate: 44100,
audioBitrate: 128000, // 128 kilobits
progress: function(info) {
console.log('transcodeVideo progress callback, info: ' + info);
}
}
);
}
function videoTranscodeSuccess(result) {
// result is the path to the transcoded video on the device
alert('videoTranscodeSuccess, result: ' + result);
document.write(result);
}
function videoTranscodeError(err) {
alert('videoTranscodeError, err: ' + err);
document.write(err);
}
Sorry about long code. Problem is video is getting captured but it is not getting transcode. I am getting error - android.media.MediaCodec$CodecException: Error 0xfffffc0e
As mentioned in another issue, you can only make it work by using a magic number 640 for width and height :)
I had this problem and solved them!
if (originalHeight > originalWidth) {
resultWidth = 360;
resultHeight = 640;
float targetRatio = (float) originalWidth / originalHeight;
if (targetRatio > 0) {
resultWidth = Math.round(originalWidth * targetRatio / 2) * 2;
resultHeight = Math.round(originalHeight * targetRatio / 2) * 2;
}
}
I fixed this by changing line 66 & 71 in src/android/CustomAndroidFormatStrategy.java like this:
Old:
outHeight = Double.valueOf(outWidth / aspectRatio).intValue(); // Line 66
outWidth = Double.valueOf(outHeight / aspectRatio).intValue(); // Line 71
New:
outHeight = Double.valueOf(Math.round(outWidth / aspectRatio / 2) * 2).intValue(); // Line 66
outWidth = Double.valueOf(Math.round(outHeight / aspectRatio / 2) * 2).intValue(); // Line 71
português (BR): Fala galera, consegui uma solução para esse erro no meu Android 11 Samsung A20
No meu caso usei o VideoEditor.getVideoInfo para obter o width e o height do vídeo de entrada, e após pegar esses valores eu joguei eles para o width e height da função transcodeVideo.
(English) Hey guys, I got a solution for this error on my Android 11 Samsung A20
In my case I used VideoEditor.getVideoInfo to get the width and height of the input video, and after getting these values I threw them to the width and height of the transcodeVideo function.
this.videoEditor.getVideoInfo({ fileUri: video, }).then((res) => { this.videoEditor.transcodeVideo({ width: res.width, height: res.height, fileUri: video, maintainAspectRatio: true, outputFileName: output_filename, outputFileType: this.videoEditor.OutputFileType.MPEG4, optimizeForNetworkUse: this.videoEditor.OptimizeForNetworkUse.YES, saveToLibrary: false, progress: function (info) { } }).then((video) => {}).catch((error: any) => { }); }).catch((error) => {});