getting error in CODEC_ID_MPEG1VIDEO and PIX_FMT_YUV420P - java

I am trying to create a code which will convert images into video. I have surfed a lot and find some method to do it using javacv. now i am getting variable not found error in these lines.
recorder.setCodecID( CODEC_ID_MPEG1VIDEO);
recorder.setPixelFormat( PIX_FMT_YUV420P);
I have imported all the jar files into my library as well but still getting this error. Some quick help would be appreciated. I have gone through the below link for the importing the javacv into my workspace.
How to Import JavaCV libraries to Android Project
package com.example.photoaday;
import static com.googlecode.javacv.cpp.opencv_core.cvReleaseImage;
import static com.googlecode.javacv.cpp.opencv_highgui.cvLoadImage;
import static com.googlecode.javacv.cpp.opencv_highgui.cvShowImage;
import static com.googlecode.javacv.cpp.opencv_highgui.cvWaitKey;
import static com.googlecode.javacv.cpp.opencv_imgproc.CV_GAUSSIAN;
import static com.googlecode.javacv.cpp.opencv_imgproc.cvSmooth;
import com.googlecode.javacv.FFmpegFrameRecorder;
import com.googlecode.javacv.cpp.opencv_core;
import com.googlecode.javacv.cpp.opencv_core.IplImage;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class Recordvideo extends Activity {
// #Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.create);
opencv_core.IplImage img = cvLoadImage("/sdcard/folder/img1.jpg");
FFmpegFrameRecorder recorder = new FFmpegFrameRecorder("/sdcard/folder/test.mpeg",200,150);
try {
recorder.setCodecID( CODEC_ID_MPEG1VIDEO);
recorder.setFrameRate(30);
recorder.setPixelFormat( PIX_FMT_YUV420P);
recorder.start();
for (int i=0;i<100;i++)
{
recorder.record(img);
}
recorder.stop();
}
catch (Exception e){
e.printStackTrace();
}
}
}

I assume that your compiler gives error as follows
error: ‘CODEC_ID_MPEG1VIDEO’ was not declared in this scope
error: ‘PIX_FMT_YUV420P’ was not declared in this scope
then solution for error is
change : ‘CODEC_ID_MPEG1VIDEO’ to 'AV_CODEC_ID_MPEG1VIDEO'
change : ‘PIX_FMT_YUV420P’ to 'AV_PIX_FMT_YUV420P'

Related

error: class, interface, or enum expected on MainActivity.java

I'm trying to compile an app that utilizes Expo on Android Studio, however, every time I try I get the following error message:
\android\app\src\main\java\com\profileid\MainActivity.java:2: error: class, interface, or enum expected
package com.projectname;
I just upgraded to Expo SDK 43 and migrated from react-native-unimodules.
My MainActivity.java looks like this:
import expo.modules.ReactActivityDelegateWrapper;
package com.projectname;
import android.os.Bundle;
import com.facebook.react.ReactActivity;
import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.ReactRootView;
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;
import expo.modules.splashscreen.singletons.SplashScreen;
import expo.modules.splashscreen.SplashScreenImageResizeMode;
public class MainActivity extends ReactActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// SplashScreen.show(...) has to be called after super.onCreate(...)
// Below line is handled by '#expo/configure-splash-screen' command and it's discouraged to modify it manually
SplashScreen.show(this, SplashScreenImageResizeMode.CONTAIN, ReactRootView.class, false);
}
/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
*/
#Override
protected String getMainComponentName() {
return "main";
}
#Override
protected ReactActivityDelegate createReactActivityDelegate() {
return new ReactActivityDelegateWrapper(this, new ReactActivityDelegate(this, getMainComponentName()) {
#Override
protected ReactRootView createRootView() {
return new RNGestureHandlerEnabledRootView(MainActivity.this);
}
});
}
}
Your first import statement and the package statement are out of order. The package statement must be the very first line of your file:
package com.projectname;
import android.os.Bundle;
import com.facebook.react.ReactActivity;
import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.ReactRootView;
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;
import expo.modules.ReactActivityDelegateWrapper;
import expo.modules.splashscreen.singletons.SplashScreen;
import expo.modules.splashscreen.SplashScreenImageResizeMode;

Error :- Activity Main can't be resolved or is not a field

I searched this error and tried all available solutions but still getting this error. I am new to android so please help to rectify and remove this error.
I am fully aware that this error is somewhat associated with .R file of android.
I am using eclipse and getting 2 error
1- "activity_main cannot be resolved or is not a field"
2- List is a raw type. Reference to generic type.
Following is MainActivity code. This code is written to calculate nearest located Latlong distance..
package com.example.latlong;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;
import android.R;
import android.app.Activity;
import android.location.Location;
import android.os.Bundle;
import android.os.Environment;
import com.opencsv.CSVReader;
import com.opencsv.CSVWriter;
public class MainActivity extends Activity {
Double latToCompare=0.0, longToCompare=0.0;
float shortestDistance = 0.0f;
Boolean isDistanceComparedFirstTime = true;
Boolean isFirstRowInCSV1 = true, isFirstRowInCSV2 = true;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); /////// Error1 Line
createDirIfNotExists("/windows/Pictures/LatLongFiles");
String csvFilename1 = Environment.getExternalStorageDirectory()+"/windows/Pictures/LatLongFiles/Data.csv";
String csvFilename2 = Environment.getExternalStorageDirectory()+"/windows/Pictures/LatLongFiles/SourceFile.csv";
String csvFilename3 = Environment.getExternalStorageDirectory()+"/windows/Pictures/LatLongFiles/OutputFile.csv";
CSVReader csvReader1 = null;
CSVReader csvReader2 = null;
CSVWriter csvWriter3 = null;
List csvFile2List = null; ///////////// Error2 Line
I know this error is not new to you android guys but i tried everything and still stuck on this error.. Thanks in advance..
Removed import android.R; And clean and rebuild your project
import your_application_package_name.R;
Error 1 indicates that the build system cannot find a layout file called "activity_main.xml". Verify that you have such a layout file.
Error 2 is simply a warning that informs you that you are using a raw type rather than a generic type. Add a type parameter that indicates the type of objects that are to reside in your list, e.g.:
List<YourTypeHere> csvFile2List = null;
Delete import.android.R; and in place of it, add import com.example.latlong.R; if com.example.latlong is your package name.
Or if this is not your package name, see your manifest file for the package name. And add import YourPackageName.R; instead of import.android.R; where YourPackageName is the name of your package.

Qt Android notification, Cannot set image

I am making an Android testapp in Qt using Java libraries for the notifications. Following the Qt Notifier example im trying recreate the same notification for starters but for some reason this line does not work:
m_builder.setSmallIcon(R.drawable.icon);
it says:
java:77: error: error: package R does not exist
I have tried adding:
import java.lang.Object;
import android.R.drawable;
I have also tried:
m_builder.setSmallIcon(android.R.drawable.icon);
but this gives me the error:
java:77: error: error: cannot find symbol
So I have checked the Qt Notifier app and I dont think i have made any mistakes but for some reason it won't work.
My question is: How do I set this icon correctly?
Here is the full piece of code:
package org.qtproject.qt5.example;
import android.app.Notification;
import android.app.NotificationManager;
import android.content.Context;
import java.lang.Object;
import java.lang.Throwable;
import java.io.Writer;
import java.io.StringWriter;
import java.io.PrintWriter;
import android.R.drawable;
public class NotificationClient extends org.qtproject.qt5.android.bindings.QtActivity
{
private static NotificationManager m_notificationManager;
private static Notification.Builder m_builder;
private static NotificationClient m_instance;
public NotificationClient()
{
try {
m_instance = this;
} catch(Throwable t) {
t.printStackTrace();
}
}
public static void notify(String s)
{
try {
if (m_notificationManager == null) {
m_notificationManager = (NotificationManager)m_instance.getSystemService(Context.NOTIFICATION_SERVICE);
m_builder = new Notification.Builder(m_instance);
m_builder.setContentTitle("A message from Qt!");
//m_builder.setSmallIcon(android.R.drawable.icon);
}
m_builder.setContentText(s);
m_notificationManager.notify(1, m_builder.build());
} catch(Throwable e) {
e.printStackTrace();
}
}
}
To fix this error make sure that package name in your java class and your AndroidManifest.xml are the same.
NotificationClient.java:
package com.mypackage;
...
AndroidManifest.xml:
<manifest package="com.mypackage"...
...
The problem for me was because of a wrong configuration in AndroidManifest.xml.
After editing the AndroidManifest correctly and cleaning and rebuilding the project, the problem was solved.

Cordova cannot find symbol error when build android project with self-built plugin (call for native java code)

I tried to run an android project in Cordova with self-build plugin,
Heres the code in JS and java for the plugin
var cordova = require('cordova');
var Carrier = function() {};
Carrier.prototype.getCarrierCode = function(success, error) {
cordova.exec(success, error, 'CarrierPlugin', 'getCarrierCode', []);
};
var carrier = new Carrier();
module.exports = carrier;
this is the java code:
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CallbackContext;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Date;
import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.CallLog;
import android.content.ContentResolver;
public class CarrierPlugin extends CordovaPlugin{
public static final String TAG = "CarrierPlugin";
public static final String ACTION_GET_CARRIER_CODE = "getCarrierCode";
//public TelephonyManager tm;
#Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
// TODO Auto-generated method stub
super.initialize(cordova, webView);
}
#Override
public boolean execute(String action, CordovaArgs args,
CallbackContext callbackContext) throws JSONException{
callbackContext.success("run it");
return true;
}
}
the error I got is "cannot find symbol :"
the strange thing is that, even if I change the code in the CarrierPlugin.java(delete the JSONException in line 16), it reported the same error.
My Eclipse says, you should import CordovaInterface, CordovaWebView and CordovaArgs.
And you might be missing package declaration as well, depending wherever you want to put your plugin's java files, such as:
package com.yourdomain.etc in the very first line of your Java file.

xuggler error - "cannot find symbol : class VideoImage" - what am i missing?

I am using xuggler to play video files from my code and the following is a snippet from the main code:
This snippet produces an error :
//The window we'll draw the video on.
private static VideoImage mScreen = null;
private static void updateJavaWindow(BufferedImage javaImage)
{
mScreen.setImage(javaImage);
}
// Opens a Swing window on screen.
private static void openJavaWindow()
{
mScreen = new VideoImage();
}
The error that i get is : cannot find symbol : class VideoImage
The header files used are :
import java.awt.image.BufferedImage;
import com.xuggle.xuggler.Global;
import com.xuggle.xuggler.IContainer;
import com.xuggle.xuggler.IPacket;
import com.xuggle.xuggler.IPixelFormat;
import com.xuggle.xuggler.IStream;
import com.xuggle.xuggler.IStreamCoder;
import com.xuggle.xuggler.ICodec;
import com.xuggle.xuggler.IVideoPicture;
import com.xuggle.xuggler.IVideoResampler;
import com.xuggle.xuggler.Utils;
Am i missing in some import statement ? If not , here are the libraries i am using apart from JDK :
What is the reason i am getting that error ?
VideoImage Javadoc
You are not importing the right class.
com.xuggle.xuggler.demos.VideoImage
It seems like you are already using an IDE. It should automatically tell you what import you are missing if the correct library is in the build path.
You need to import the VideoImage class.

Categories

Resources