我尝试使用互联网上提供的示例示例中的FFMpeg库解码视频,我用新版本的ffmpeg搞清楚,这是我从我的类文件中调用的代码,
private static native int decodeVideo(String filename);
decodeVideo(getString(R.string._sdcard_abc_3gp));
Run Code Online (Sandbox Code Playgroud)
现在位于JNI目录的.c文件中,我写了这段代码,
jint Java_ru_dzakhov_ffmpeg_test_MainActivity_decodeVideo(JNIEnv* env, jobject
javaThis,jstring filename) {
AVFormatContext *pFormatCtx;
int i, videoStream;
AVCodecContext *pCodecCtx;
AVCodec *pCodec;
AVFrame *pFrame;
AVFrame *pFrameRGB;
AVPacket packet;
int frameFinished;
int numBytes;
uint8_t *buffer;
// Register all formats and codecs
av_register_all();
// Open video file
const jbyte *str;
str = (*env)->GetStringUTFChars(env, filename, NULL);
if(av_open_input_file(&pFormatCtx, str, NULL, 0, NULL)!=0)
{
LOGI("Can't open file '%s'\n", str);
return 1;
}
else
{
LOGI("File is opened\n");
LOGI("File '%s', Codec %s",pFormatCtx->filename,pFormatCtx->iformat->name);
} …Run Code Online (Sandbox Code Playgroud) 我想从视频中获取帧数...我使用以下代码:
package com.vidualtest;
import java.io.File;
import java.io.FileDescriptor;
import android.app.Activity;
import android.graphics.Bitmap;
import android.media.MediaMetadataRetriever;
import android.os.Bundle;
import android.os.Environment;
import android.widget.ImageView;
public class VidualTestActivity extends Activity {
/** Called when the activity is first created. */
File file;
ImageView img;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
img = (ImageView) findViewById(R.id.img);
File sdcard = Environment.getExternalStorageDirectory();
file = new File(sdcard, "myvid.mp4");
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
try {
retriever.setDataSource(file.getAbsolutePath());
img.setImageBitmap(retriever.getFrameAtTime(10000,MediaMetadataRetriever.OPTION_CLOSEST));
} catch (IllegalArgumentException ex) {
ex.printStackTrace();
} catch (RuntimeException ex) {
ex.printStackTrace(); …Run Code Online (Sandbox Code Playgroud) 我想在 ViewPager 中使用从一个 Fragment 到另一个 Fragment 的 SharedElement 转换为视图设置动画。
我在 ViewPager 中有 3 个片段,每个片段在 XML 文件中都有一个具有相同转换名称的 TextView。
现在,当 ViewPager 滑动另一个 Fragment 时,我想看到 SharedElement 的运行情况。
animation android shared-element-transition android-design-library
我在活动A然后从A开始活动B.现在我在活动B并从B开始活动C.在开始活动C时,我想删除活动A和B.我试过这种方式,
Intent intent = new Intent(B.this, C.class); //I'm on Activity B, moving to C
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); //this should remove the Activity A
startActivity(intent);
finish(); //Finishes activity B
Run Code Online (Sandbox Code Playgroud)
我担心这样做,当我的活动C开始时,我按回来,应该退出应用程序.目前它向我展示了活动A.