w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Incorrect Codec Parameters, Could not write header for output file: FFMPEG - Android

From the error message, it seems like you are trying to wrap H.263 coded video stream and aac codec audio stream into a mp4 file, which is not possible because as a container type (or transport format), mp4 cannot use H.263 video payload in video tracks.

It will be working if you wrap H.264 streams to mp4 files, in this case, you will be required to transcode video track from H.263 to H.264, which will require a H.264 encoder and more computation than the command you are "copy" mode you are running now. To do this, you need to compile ffmpeg with libx264 (configure ffmpeg with --enable-libx264 option and libx264 needs to be pre-compiled and installed). Then modify your code to:

String[] ffmpegCommand = {
                 path,  // string variable, path of file
                 "00:00:05", // duration of video
                 destination + "/trimmmmm.mp4" }; // string

This command will convert the video format, which will be OK to be wrapped in mp4 file. If you experience quality degrading after transcoding, then you can toy with x264 encoding parameters to maintain quality, which you will find a lot of materials on the internet.

Hope it helped.

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.