Salmaan
Salmaan

Reputation: 3624

Incorrect Codec Parameters, Could not write header for output file: FFMPEG - Android

Why do I get Incorrect Codec Parameters....???
I am creating video using Android MediaRecorder, use FFMPEG over it to trim it. I am just trying to trim the video using FFMPEG.

String[] ffmpegCommand = {
                    "/data/data/uk.org.humanfocus.hfi/ffmpeg",
                     "-ss",
                     "00:00:00",
                     "-i",
                     path,  // string variable, path of file
                     "-t",
                     "00:00:05", // duration of video
                     "-c",
                     "copy",
                     destination + "/trimmmmm.mp4" }; // string

This is log I get..
It is from starting of FFMPEG processing until it ends.

10-24 18:02:06.039: V/ss(22093): ***Starting FFMPEG***
10-24 18:02:06.144: V/asd(22093): ***ffmpeg version N-63700-gbf0e5ac Copyright (c) 2000-2014 the FFmpeg developers***
10-24 18:02:06.144: V/asd(22093): ***  built on Jun  3 2014 13:27:45 with gcc 4.8 (GCC)***
10-24 18:02:06.144: V/asd(22093): ***  configuration: --prefix=/Users/aliasa/Downloads/android-ndk-r9/sources/ffmpeg/android/arm --enable-shared --disable-static --disable-doc --disable-ffplay --disable-ffprobe --disable-ffserver --disable-avdevice --disable-doc --disable-symver --cross-prefix=/Users/aliasa/Downloads/android-ndk-r9/toolchains/arm-linux-androideabi-4.8/prebuilt/darwin-x86_64/bin/arm-linux-androideabi- --target-os=linux --arch=arm --enable-cross-compile --sysroot=/Users/aliasa/Downloads/android-ndk-r9/platforms/android-9/arch-arm/ --extra-cflags='-Os -fpic -marm' --extra-ldflags=***
10-24 18:02:06.149: V/asd(22093): ***  libavutil      52. 89.100 / 52. 89.100***
10-24 18:02:06.149: V/asd(22093): ***  libavcodec     55. 66.100 / 55. 66.100***
10-24 18:02:06.149: V/asd(22093): ***  libavformat    55. 42.100 / 55. 42.100***
10-24 18:02:06.149: V/asd(22093): ***  libavfilter     4.  5.100 /  4.  5.100***
10-24 18:02:06.149: V/asd(22093): ***  libswscale      2.  6.100 /  2.  6.100***
10-24 18:02:06.149: V/asd(22093): ***  libswresample   0. 19.100 /  0. 19.100***
10-24 18:02:06.289: V/asd(22093): ***Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/storage/emulated/0/copymade.mp4':***
10-24 18:02:06.289: V/asd(22093): ***  Metadata:***
10-24 18:02:06.289: V/asd(22093): ***    major_brand     : isom***
10-24 18:02:06.289: V/asd(22093): ***    minor_version   : 0***
10-24 18:02:06.289: V/asd(22093): ***    compatible_brands: isom3gp4***
10-24 18:02:06.289: V/asd(22093): ***    creation_time   : 2014-10-24 12:25:55***
10-24 18:02:06.294: V/asd(22093): ***  Duration: 00:00:11.65, start: 0.000000, bitrate: 3147 kb/s***
10-24 18:02:06.294: V/asd(22093): ***    Stream #0:0(eng): Video: h263 (s263 / 0x33363273), yuv420p, 720x480 [SAR 12:11 DAR 18:11], 3276 kb/s, 16.61 fps, 16.67 tbr, 90k tbn, 29.97 tbc (default)***
10-24 18:02:06.294: V/asd(22093): ***    Metadata:***
10-24 18:02:06.294: V/asd(22093): ***      creation_time   : 2014-10-24 12:25:55***
10-24 18:02:06.294: V/asd(22093): ***      handler_name    : VideoHandle***
10-24 18:02:06.294: V/asd(22093): ***    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 8000 Hz, mono, fltp, 12 kb/s (default)***
10-24 18:02:06.294: V/asd(22093): ***    Metadata:***
10-24 18:02:06.294: V/asd(22093): ***      creation_time   : 2014-10-24 12:25:55***
10-24 18:02:06.294: V/asd(22093): ***      handler_name    : SoundHandle***
10-24 18:02:06.294: V/asd(22093): ***[mp4 @ 0x50ce0] Could not find tag for codec h263 in stream #0, codec not currently supported in container***
10-24 18:02:06.294: V/asd(22093): ***Output #0, mp4, to '/storage/emulated/0/trimmmmm.mp4':***
10-24 18:02:06.294: V/asd(22093): ***  Metadata:***
10-24 18:02:06.294: V/asd(22093): ***    major_brand     : isom***
10-24 18:02:06.294: V/asd(22093): ***    minor_version   : 0***
10-24 18:02:06.294: V/asd(22093): ***    compatible_brands: isom3gp4***
10-24 18:02:06.294: V/asd(22093): ***    encoder         : Lavf55.42.100***
10-24 18:02:06.294: V/asd(22093): ***    Stream #0:0(eng): Video: h263 (s263 / 0x33363273), yuv420p, 720x480 [SAR 12:11 DAR 18:11], q=2-31, 3276 kb/s, 16.61 fps, 90k tbn, 90k tbc (default)***
10-24 18:02:06.294: V/asd(22093): ***    Metadata:***
10-24 18:02:06.294: V/asd(22093): ***      creation_time   : 2014-10-24 12:25:55***
10-24 18:02:06.294: V/asd(22093): ***      handler_name    : VideoHandle***
10-24 18:02:06.294: V/asd(22093): ***    Stream #0:1(eng): Audio: aac ([64][0][0][0] / 0x0040), 8000 Hz, mono, 12 kb/s (default)***
10-24 18:02:06.294: V/asd(22093): ***    Metadata:***
10-24 18:02:06.294: V/asd(22093): ***      creation_time   : 2014-10-24 12:25:55***
10-24 18:02:06.299: V/asd(22093): ***      handler_name    : SoundHandle***
10-24 18:02:06.299: V/asd(22093): ***Stream mapping:***
10-24 18:02:06.299: V/asd(22093): ***  Stream #0:0 -> #0:0 (copy)***
10-24 18:02:06.299: V/asd(22093): ***  Stream #0:1 -> #0:1 (copy)***
10-24 18:02:06.299: V/asd(22093): ***Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument***
10-24 18:02:06.299: V/asdas(22093): ***Ending FFMPEG***

I am badly stuck here from 2 3 days, please help me out.

Upvotes: 0

Views: 10166

Answers (2)

Salmaan
Salmaan

Reputation: 3624

With the help of @JasonYang answer and description i concluded that H.264 should be used..
While initializing MediaRecorder...

i was using prMediaRecorder.setVideoEncoder(VideoEncoder.DEFAULT);
instead i used prMediaRecorder.setVideoEncoder(VideoEncoder.H264);

and it worked magically :)

Upvotes: 0

JasonYang
JasonYang

Reputation: 786

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 = {
                "/data/data/uk.org.humanfocus.hfi/ffmpeg",
                 "-ss",
                 "00:00:00",
                 "-i",
                 path,  // string variable, path of file
                 "-t",
                 "00:00:05", // duration of video
                 "-vcodec",
                 "libx264",
                 "-acodec",
                 "copy",
                 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.

Upvotes: 6

Related Questions