编解码器参数不正确,无法为输出文件写入标头:FFMPEG - Android

Sal*_*aan 0 java video mp4 android ffmpeg

为什么我得到不正确的编解码器参数.... ???
我正在使用Android创建视频MediaRecorder,使用FFMPEG它来修剪它.我只想尝试修剪视频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
Run Code Online (Sandbox Code Playgroud)

这是我得到的日志..
它是从FFMPEG处理开始直到它结束.

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***
Run Code Online (Sandbox Code Playgroud)

我被困在这里2 3天,请帮助我.

Jas*_*ang 6

从错误消息,您似乎正在尝试将H.263编码视频流和aac编解码器音频流包装到mp4文件中,这是不可能的,因为作为容器类型(或传输格式),mp4不能使用H.263视频轨道中的视频负载.

如果将H.264流包装到mp4文件中,它将起作用,在这种情况下,您将需要将视频轨道从H.263转码为H.264,这将需要H.264编码器和比命令更多的计算你是现在正在运行的"复制"模式.为此,您需要使用libx264编译ffmpeg(使用--enable-libx264选项配置ffmpeg,并且需要预编译和安装libx264).然后将代码修改为:

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
Run Code Online (Sandbox Code Playgroud)

此命令将转换视频格式,可以将其包装在mp4文件中.如果您在转码后遇到质量下降,那么您可以使用x264编码参数来保持质量,您可以在互联网上找到很多材料.

希望它有所帮助.