gpt4 book ai didi

android - 压缩视频FFMPEG不起作用

转载 作者:行者123 更新时间:2023-12-04 23:03:49 24 4
gpt4 key购买 nike

我正在尝试使用 FFMPEG 和这个库压缩视频:https://github.com/guardianproject/android-ffmpeg-java

我将 ffmpeglib 作为模块导入到我的项目中。这是用于压缩的代码:

public class MainActivity extends Activity {

private ArrayList<Object> listVideoPaths = new ArrayList<>();

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

getGalleryVideos();

File videoFolderFile = new File("/storage/emulated/0/DCIM/Camera/");

if(videoFolderFile.exists())
Log.e("TEST FFMPEG", "video folder exist");
else
Log.e("TEST FFMPEG", "video folder DON'T exist");


File videoInputFile = new File(listVideoPaths.get(0).toString());

if(videoInputFile.exists())
Log.e("TEST FFMPEG", "video input file exist");
else
Log.e("TEST FFMPEG", "video input file DON'T exist");

File videoOutputFile = new File(videoFolderFile,"output.mp4");

if(videoOutputFile.exists())
Log.e("TEST FFMPEG", "video output file exist");
else
Log.e("TEST FFMPEG", "video output file DON'T exist");

FfmpegController ffmpegController;

try {
ffmpegController = new FfmpegController(this,videoFolderFile);

Clip mediaIn = new Clip();

mediaIn.path = videoInputFile.getAbsolutePath();

mediaIn.videoFps = "25";

ffmpegController.convertToMPEG(mediaIn, videoOutputFile.getAbsolutePath(), new ShellUtils.ShellCallback() {

@Override
public void shellOut(String shellLine) {
Log.e("TEST FFMPEG", "shellOut - " + shellLine);
}

@Override
public void processComplete(int exitValue) {
Log.e("TEST FFMPEG", "proccess complete - " + exitValue);
}
});


} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}finally {

if(videoOutputFile.exists())
Log.e("TEST FFMPEG", "finished ffmpeg ---> video output file exist");
else
Log.e("TEST FFMPEG", "finished ffmpeg ---> video output file DON'T exist");

}
}

private void getGalleryVideos(){

Cursor videoCursor = null;

try {

final String[] columns = { Media.DATA,
Media._ID,
Media.DATE_ADDED };

final String orderBy = Media.DATE_ADDED;

videoCursor = getContentResolver().query(
MediaStore.Video.Media.EXTERNAL_CONTENT_URI, columns,
null, null, orderBy);

if (videoCursor != null && videoCursor.getCount() > 0) {

while (videoCursor.moveToNext()) {

int dataColumnIndex = videoCursor
.getColumnIndex(Media.DATA);

listVideoPaths.add(videoCursor
.getString(dataColumnIndex));

}

}

Collections.sort(listVideoPaths,new Comparator());

} catch (Exception e) {

e.printStackTrace();

} finally {

if (videoCursor != null) {

if (!videoCursor.isClosed()) {

videoCursor.close();

}

}

}

}

}

我没有收到任何错误,但视频无法播放。日志文件是:

3096-3096/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ video folder exist 07-30 14:31:57.389
3096-3096/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ video input file exist 07-30 14:31:57.389
3096-3096/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ video output file DON'T exist 07-30 14:31:58.363
3096-3096/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - /data/data/douglasanunciacao.androidffmpegjavateste/app_bin/ffmpeg -y -i /storage/emulated/0/DCIM/Camera/VID_20150730_142330563.mp4 -f mpeg /storage/emulated/0/DCIM/Camera/output.mp4 07-30 14:31:58.385
3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - WARNING: linker: /data/data/douglasanunciacao.androidffmpegjavateste/app_bin/ffmpeg has text relocations. This is wasting memory and prevents security hardening. Please fix. 07-30 14:31:58.390
3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - ffmpeg version 0.11.1 Copyright (c) 2000-2012 the FFmpeg developers 07-30 14:31:58.391
3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - built on Dec 22 2014 12:52:34 with gcc 4.6 20120106 (prerelease) 07-30 14:31:58.391
3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - configuration: --arch=arm --cpu=cortex-a8 --target-os=linux --enable-runtime-cpudetect --prefix=/data/data/info.guardianproject.ffmpeg/app_opt --enable-pic --disable-shared --enable-static --cross-prefix=/home/n8fr8/dev/android/ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/arm-linux-androideabi- --sysroot=/home/n8fr8/dev/android/ndk/platforms/android-16/arch-arm --extra-cflags='-I../x264 -mfloat-abi=softfp -mfpu=neon -fPIE -pie' --extra-ldflags='-L../x264 -fPIE -pie' --enable-version3 --enable-gpl --disable-doc --enable-yasm --enable-decoders --enable-encoders --enable-muxers --enable-demuxers --enable-parsers --enable-protocols --enable-filters --enable-avresample --enable-libfreetype --disable-indevs --enable-indev=lavfi --disable-outdevs --enable-hwaccels --enable-ffmpeg --disable-ffplay --disable-ffprobe --disable-ffserver --disable-network --enable-libx264 --enable-zlib 07-30 14:31:58.391
3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - libavutil 51. 54.100 / 51. 54.100 07-30 14:31:58.391 3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - libavcodec 54. 23.100 / 54. 23.100 07-30 14:31:58.391 3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - libavformat 54. 6.100 / 54. 6.100 07-30 14:31:58.391 3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - libavdevice 54. 0.100 / 54. 0.100 07-30 14:31:58.391 3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - libavfilter 2. 77.100 / 2. 77.100 07-30 14:31:58.391 3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - libswscale 2. 1.100 / 2. 1.100 07-30 14:31:58.391 3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - libswresample 0. 15.100 / 0. 15.100 07-30 14:31:58.391 3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - libpostproc 52. 0.100 / 52. 0.100 07-30 14:31:58.868 3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/storage/emulated/0/DCIM/Camera/VID_20150730_142330563.mp4': 07-30 14:31:58.869 3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - Metadata: 07-30 14:31:58.869
3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - major_brand : mp42 07-30 14:31:58.870
3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - minor_version : 0 07-30 14:31:58.871
3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - compatible_brands: isommp42 07-30 14:31:58.872
3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - creation_time : 2015-07-30 17:23:34 07-30 14:31:58.873 3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - Duration: 00:00:01.89, start: 0.000000, bitrate: 17571 kb/s 07-30 14:31:58.874
3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080, 15874 kb/s, SAR 65536:65536 DAR 16:9, 23.90 fps, 23.92 tbr, 90k tbn, 180k tbc 07-30 14:31:58.875 3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - Metadata: 07-30 14:31:58.876
3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - rotate : 270 07-30 14:31:58.877
3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - creation_time : 2015-07-30 17:23:34 07-30 14:31:58.878 3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - handler_name : VideoHandle 07-30 14:31:58.878 3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, s16, 127 kb/s 07-30 14:31:58.878
3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - Metadata: 07-30 14:31:58.878
3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - creation_time : 2015-07-30 17:23:34 07-30 14:31:58.878 3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - handler_name : SoundHandle 07-30 14:31:58.882 3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - [buffer @ 0xb5cce0a0] w:1920 h:1080 pixfmt:yuv420p tb:1/90000 sar:65536/65536 sws_param:flags=2 07-30 14:31:58.882 3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - [buffersink @ 0xb5cce0d0] No opaque field provided 07-30 14:31:58.891
3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - [mpeg @ 0xb5c3df00] VBV buffer size not set, muxing may fail 07-30 14:31:58.892
3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - Output #0, mpeg, to '/storage/emulated/0/DCIM/Camera/output.mp4': 07-30 14:31:58.894
3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - Metadata: 07-30 14:31:58.895
3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - major_brand : mp42 07-30 14:31:58.896
3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - minor_version : 0 07-30 14:31:58.896
3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - compatible_brands: isommp42 07-30 14:31:58.897
3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - creation_time : 2015-07-30 17:23:34 07-30 14:31:58.898 3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - encoder : Lavf54.6.100 07-30 14:31:58.898 3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - Stream #0:0(eng): Video: mpeg1video, yuv420p, 1920x1080 [SAR 65536:65536 DAR 16:9], q=2-31, 200 kb/s, 90k tbn, 23.98 tbc 07-30 14:31:58.899
3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - Metadata: 07-30 14:31:58.899
3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - rotate : 270 07-30 14:31:58.900
3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - creation_time : 2015-07-30 17:23:34 07-30 14:31:58.901 3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - handler_name : VideoHandle 07-30 14:31:58.906 3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - Stream #0:1(eng): Audio: mp2, 48000 Hz, stereo, s16, 128 kb/s 07-30 14:31:58.906
3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - Metadata: 07-30 14:31:58.906
3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - creation_time : 2015-07-30 17:23:34 07-30 14:31:58.906 3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - handler_name : SoundHandle 07-30 14:31:58.906 3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - Stream mapping: 07-30 14:31:58.906
3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - Stream #0:0 -> #0:0 (h264 -> mpeg1video) 07-30 14:31:58.906 3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - Stream #0:1 -> #0:1 (aac -> mp2) 07-30 14:31:58.906 3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - Press [q] to stop, [?] for help 07-30 14:31:59.824 3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - frame= 4 fps=0.0 q=2.0 size= 0kB time=00:00:00.08 bitrate= 0.0kbits/s 07-30 14:32:02.029
3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - frame= 8 fps=2.7 q=10.5 size= 4kB time=00:00:00.25 bitrate= 130.9kbits/s 07-30 14:32:02.536
3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - frame= 13 fps=3.7 q=25.2 size= 696kB time=00:00:00.45 bitrate=12427.3kbits/s 07-30 14:32:03.045
3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - frame= 18 fps=4.4 q=31.0 size= 750kB time=00:00:00.66 bitrate=9206.8kbits/s 07-30 14:32:03.582
3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - frame= 23 fps=5.0 q=31.0 size= 786kB time=00:00:00.87 bitrate=7351.4kbits/s 07-30 14:32:04.140
3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - frame= 28 fps=5.5 q=31.0 size= 862kB time=00:00:01.08 bitrate=6511.8kbits/s 07-30 14:32:05.239
3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - frame= 30 fps=4.8 q=31.0 size= 876kB time=00:00:01.16 bitrate=6144.9kbits/s 07-30 14:32:05.746
3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - frame= 35 fps=5.2 q=31.0 size= 910kB time=00:00:01.37 bitrate=5416.2kbits/s 07-30 14:32:06.317
3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - frame= 41 fps=5.6 q=31.0 size= 972kB time=00:00:01.62 bitrate=4895.2kbits/s 07-30 14:32:06.832
3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - frame= 45 fps=5.7 q=31.0 Lsize= 1022kB time=00:00:01.83 bitrate=4562.1kbits/s 07-30 14:32:06.832
3096-3182/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ shellOut - video:984kB audio:30kB global headers:0kB muxing overhead 0.756932% 07-30 14:32:06.858 3096-3096/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ proccess complete - 0 07-30 14:32:06.858
3096-3096/douglasanunciacao.androidffmpegjavateste E/TESTE FFMPEG﹕ terminou o ffmpeg ---> video output file exist



有谁知道如何解决这个问题?提前致谢。

最佳答案

我通过替换以下代码成功解决了这个问题:

    Clip mediaIn = new Clip();

mediaIn.path = videoInputFile.getAbsolutePath();

mediaIn.videoFps = "30";

mediaIn.videoCodec = "mpeg4";

mediaIn.width = 640;

mediaIn.height = 352;

mediaIn.videoBitrate = 1000;

// "ffmpeg -y -i /sdcard/DCIM/Camera/VID_20150728_150045662.mp4 " +
// "-strict experimental -s 640x352 -r 30 -vcodec mpeg4 -ab 48000 " +
// "-ac 2 -ar 22050 -b 1000k /sdcard/DCIM/Camera/output2.mp4";

ffmpegController.convertToMPEG(mediaIn, videoOutputFile.getAbsolutePath(), new ShellUtils.ShellCallback() {

@Override
public void shellOut(String shellLine) {
Log.e("TEST FFMPEG", "shellOut - " + shellLine);
}

@Override
public void processComplete(int exitValue) {
Log.e("TEST FFMPEG", "proccess complete - " + exitValue);
}
});

通过此代码:
Clip clipIn = new Clip(videoInputFile.getAbsolutePath());
Clip clipOut = new Clip(videoOutputFile.getAbsolutePath());
clipOut.videoCodec = "mpeg4";
clipOut.videoFps = "30"; // tailor this to your needs
clipOut.videoBitrate = 512; // 512 kbps - tailor this to your needs
clipOut.audioChannels = 1;
clipOut.width = 640;
clipOut.height = 352;
clipOut.duration = 2;
ffmpegController.processVideo(clipIn, clipOut, true, new ShellUtils.ShellCallback() {
@Override
public void shellOut(String shellLine) {
Log.e("TEST FFMPEG", "shellOut - " + shellLine);
}

@Override
public void processComplete(int exitValue) {
Log.e("TEST FFMPEG", "proccess complete - " + exitValue);
}
});

关于android - 压缩视频FFMPEG不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31730588/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com