How is this JMH microbenchmark skewed, if it is? - java

The benchmark is quite simple:
#State(Scope.Benchmark)
public class MathPowVsRawMultiplyTest
{
private static final double VICTIM;
static {
VICTIM = new Random(System.currentTimeMillis()).nextDouble();
}
double result;
#Benchmark
public void mathPow()
{
result = Math.pow(VICTIM, 2.0);
}
#Benchmark
public void rawMultiply()
{
result = VICTIM * VICTIM;
}
public static void main(final String... args)
throws RunnerException
{
final Options options = new OptionsBuilder()
.include(MathPowVsRawMultiplyTest.class.getCanonicalName())
.forks(1)
.warmupMode(WarmupMode.BULK)
.warmupIterations(1)
.measurementIterations(1)
.build();
new Runner(options).run();
}
}
Of course, the environment matters, a lot, so here goes:
this main() is run through IDEA 15.0.1;
Ubuntu 15.10, x86_64;
Oracle JDK 1.8u65;
machine is a Dell M3800, 16 GiB RAM, 8 CPU cores and the first paragraph from /proc/cpuinfo follows.
The cpuinfo:
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 60
model name : Intel(R) Core(TM) i7-4712HQ CPU # 2.30GHz
stepping : 3
microcode : 0x1c
cpu MHz : 3235.722
cache size : 6144 KB
physical id : 0
siblings : 8
core id : 0
cpu cores : 4
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm ida arat epb pln pts dtherm tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt
bugs :
bogomips : 4589.60
clflush size : 64
cache_alignment : 64
address sizes : 39 bits physical, 48 bits virtual
power management:
And the result of the benchmark:
Benchmark Mode Cnt Score Error Units
MathPowVsRawMultiplyTest.mathPow thrpt 2342955236.832 ops/s
MathPowVsRawMultiplyTest.rawMultiply thrpt 2375082332.164 ops/s
What I haven't done is try and see what optimizations the JVM could do for Math.pow(); but the result seems pretty close.
The problem is that I don't know JMH that much, therefore I wonder: is my benchmark completely flawed, or is the CPU/JIT combination that good?

Your benchmark is completely flawed, because compiler is able to constant-fold loads from static final fields. Have you read at least the first few samples, notably JMHSample_10_ConstantFold and JMHSample_08_DeadCode? This is how it is done better (but not actually verified, caveat emptor):
#State(Scope.Benchmark)
public class MathPowVsRawMultiplyTest {
private double v;
#Setup
public void setup {
v = new Random(System.currentTimeMillis()).nextDouble();
}
#Benchmark
public double mathPow() {
return Math.pow(v, 2.0);
}
#Benchmark
public void rawMultiply() {
return v * v;
}
}
You are also advised to set the timeunit to nanoseconds (see #OutputTimeUnit or -tu), and switch to average time measurement instead of throughput (see #BenchmarkMode or -bm). Also, for the nanobenchmarks like these, you need to verify the difference in the compiled code, available with -prof perfasm, for example.

Related

ffmpeg not converting entire video in java application

My code converts a video into different formats (160p to 2160p). The codec of video with rotate tag 90 needs to be changed. below id the code for the same which works fine for all videos till date.
log_wfm.debug("Changing the codec video for file [" + orgFileName + "] and name of source file ["
+ srcFileName + "]");
String codecFlipCommand = "ffmpeg -i " + orgFileName + " -c:v libx264 -preset ultrafast " + srcFileName;
log_wfm.info("Executing command to change the codec of video!");
fp = Runtime.getRuntime().exec(codecFlipCommand);
inputStream = new BufferedReader(new InputStreamReader(fp.getInputStream()));
outputStream = new BufferedReader(new InputStreamReader(fp.getErrorStream()));
StringBuffer output = new StringBuffer();
String line;
while ((line = inputStream.readLine()) != null) {
output.append(line).append('\n');
}
log_wfm.debug("stdInputForCodecChange: " + output);
output = new StringBuffer();
while ((line = outputStream.readLine()) != null) {
output.append(line).append('\n');
}
log_wfm.debug("stdErrorForCodecChange: " + output);
now have a file of size 1.5Gb. The video does not create the file with changed codec. The file till size 848.5 MB is created and then the program hangs (with no exception or error logs)
Please suggest some way to finish this codec change process.The ffmpeg command converts the video, but via java application, the process hangs Logs While converting via commandLine :
ffmpeg version N-83433-ge87a4a8 Copyright (c) 2000-2017 the FFmpeg developers built with gcc 6.3.1 (GCC) 20161221 (Red Hat 6.3.1-1)
configuration: --prefix=/root/ffmpeg_build --extra-cflags=-I/root/ffmpeg_build/include --extra-ldflags='-L/root/ffmpeg_build/lib -ldl' --bindir=/root/bin --pkg-config-flags=--static --enable-gpl --enable-nonfree --enable-libfdk_aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265
libavutil 55. 46.100 / 55. 46.100
libavcodec 57. 75.100 / 57. 75.100
libavformat 57. 66.101 / 57. 66.101
libavdevice 57. 2.100 / 57. 2.100
libavfilter 6. 73.100 / 6. 73.100
libswscale 4. 3.101 / 4. 3.101
libswresample 2. 4.100 / 2. 4.100
libpostproc 54. 2.100 / 54. 2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/home/urvashi/test/SachinSagaGameLaunchEvent.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
creation_time : 2017-12-07T06:26:23.000000Z
com.android.version: 7.1.1
Duration: 00:14:16.02, start: 0.000000, bitrate: 14231 kb/s
Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080, 13971 kb/s, SAR 1:1 DAR 16:9, 29.94 fps, 29.92 tbr, 90k tbn, 180k tbc (default)
Metadata:
rotate : 90
creation_time : 2017-12-07T06:26:23.000000Z
handler_name : VideoHandle
Side data:
displaymatrix: rotation of -90.00 degrees
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 256 kb/s (default)
Metadata:
creation_time : 2017-12-07T06:26:23.000000Z
handler_name : SoundHandle
[libx264 # 0x4601a20] using SAR=1/1
[libx264 # 0x4601a20] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 # 0x4601a20] profile Constrained Baseline, level 4.0
[libx264 # 0x4601a20] 264 - core 148 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=250 keyint_min=25 scenecut=0 intra_refresh=0 rc=crf mbtree=0 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=0
Output #0, mp4, to '/home/urvashi/test/Manual_SachinSagaGameLaunchEvent.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
com.android.version: 7.1.1
encoder : Lavf57.66.101
Stream #0:0(eng): Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 1080x1920 [SAR 1:1 DAR 9:16], q=-1--1, 29.92 fps, 11488 tbn, 29.92 tbc (default)
Metadata:
handler_name : VideoHandle
creation_time : 2017-12-07T06:26:23.000000Z
encoder : Lavc57.75.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
Stream #0:1(eng): Audio: aac (LC) ([64][0][0][0] / 0x0040), 48000 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
creation_time : 2017-12-07T06:26:23.000000Z
handler_name : SoundHandle
encoder : Lavc57.75.100 aac
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help Past duration 0.600212 too large 48193kB time=00:00:27.26 bitrate=14479.2kbits/s speed=2.07x
Past duration 0.998863 too large
frame=25611 fps= 55 q=-1.0 Lsize= 1721466kB time=00:14:16.04 bitrate=16473.7kbits/s dup=0 drop=17 speed=1.85x
video:1707295kB audio:13453kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.041757%
[libx264 # 0x4601a20] frame I:103 Avg QP:22.16 size:242916
[libx264 # 0x4601a20] frame P:25508 Avg QP:25.17 size: 67557
Thanks in Advance.

Implement a java UDF and call it from pyspark

I need to create a UDF to be used in pyspark python which uses a java object for its internal calculations.
If it were a simple python I would do something like:
def f(x):
return 7
fudf = pyspark.sql.functions.udf(f,pyspark.sql.types.IntegerType())
and call it using:
df = sqlContext.range(0,5)
df2 = df.withColumn("a",fudf(df.id)).show()
However, the implementation of the function I need is in java and not in python. I need to wrap it somehow so I can call it in a similar way from python.
My first try was to do implement the java object, then wrap it in python in pyspark and convert that to UDF. That failed with serialization error.
Java code:
package com.test1.test2;
public class TestClass1 {
Integer internalVal;
public TestClass1(Integer val1) {
internalVal = val1;
}
public Integer do_something(Integer val) {
return internalVal;
}
}
pyspark code:
from py4j.java_gateway import java_import
from pyspark.sql.functions import udf
from pyspark.sql.types import IntegerType
java_import(sc._gateway.jvm, "com.test1.test2.TestClass1")
a = sc._gateway.jvm.com.test1.test2.TestClass1(7)
audf = udf(a,IntegerType())
error:
---------------------------------------------------------------------------
Py4JError Traceback (most recent call last)
<ipython-input-2-9756772ab14f> in <module>()
4 java_import(sc._gateway.jvm, "com.test1.test2.TestClass1")
5 a = sc._gateway.jvm.com.test1.test2.TestClass1(7)
----> 6 audf = udf(a,IntegerType())
/usr/local/spark/python/pyspark/sql/functions.py in udf(f, returnType)
1595 [Row(slen=5), Row(slen=3)]
1596 """
-> 1597 return UserDefinedFunction(f, returnType)
1598
1599 blacklist = ['map', 'since', 'ignore_unicode_prefix']
/usr/local/spark/python/pyspark/sql/functions.py in __init__(self, func, returnType, name)
1556 self.returnType = returnType
1557 self._broadcast = None
-> 1558 self._judf = self._create_judf(name)
1559
1560 def _create_judf(self, name):
/usr/local/spark/python/pyspark/sql/functions.py in _create_judf(self, name)
1565 command = (func, None, ser, ser)
1566 sc = SparkContext.getOrCreate()
-> 1567 pickled_command, broadcast_vars, env, includes = _prepare_for_python_RDD(sc, command, self)
1568 ctx = SQLContext.getOrCreate(sc)
1569 jdt = ctx._ssql_ctx.parseDataType(self.returnType.json())
/usr/local/spark/python/pyspark/rdd.py in _prepare_for_python_RDD(sc, command, obj)
2297 # the serialized command will be compressed by broadcast
2298 ser = CloudPickleSerializer()
-> 2299 pickled_command = ser.dumps(command)
2300 if len(pickled_command) > (1 << 20): # 1M
2301 # The broadcast will have same life cycle as created PythonRDD
/usr/local/spark/python/pyspark/serializers.py in dumps(self, obj)
426
427 def dumps(self, obj):
--> 428 return cloudpickle.dumps(obj, 2)
429
430
/usr/local/spark/python/pyspark/cloudpickle.py in dumps(obj, protocol)
644
645 cp = CloudPickler(file,protocol)
--> 646 cp.dump(obj)
647
648 return file.getvalue()
/usr/local/spark/python/pyspark/cloudpickle.py in dump(self, obj)
105 self.inject_addons()
106 try:
--> 107 return Pickler.dump(self, obj)
108 except RuntimeError as e:
109 if 'recursion' in e.args[0]:
/home/mendea3/anaconda2/lib/python2.7/pickle.pyc in dump(self, obj)
222 if self.proto >= 2:
223 self.write(PROTO + chr(self.proto))
--> 224 self.save(obj)
225 self.write(STOP)
226
/home/mendea3/anaconda2/lib/python2.7/pickle.pyc in save(self, obj)
284 f = self.dispatch.get(t)
285 if f:
--> 286 f(self, obj) # Call unbound method with explicit self
287 return
288
/home/mendea3/anaconda2/lib/python2.7/pickle.pyc in save_tuple(self, obj)
566 write(MARK)
567 for element in obj:
--> 568 save(element)
569
570 if id(obj) in memo:
/home/mendea3/anaconda2/lib/python2.7/pickle.pyc in save(self, obj)
284 f = self.dispatch.get(t)
285 if f:
--> 286 f(self, obj) # Call unbound method with explicit self
287 return
288
/usr/local/spark/python/pyspark/cloudpickle.py in save_function(self, obj, name)
191 if islambda(obj) or obj.__code__.co_filename == '<stdin>' or themodule is None:
192 #print("save global", islambda(obj), obj.__code__.co_filename, modname, themodule)
--> 193 self.save_function_tuple(obj)
194 return
195 else:
/usr/local/spark/python/pyspark/cloudpickle.py in save_function_tuple(self, func)
234 # create a skeleton function object and memoize it
235 save(_make_skel_func)
--> 236 save((code, closure, base_globals))
237 write(pickle.REDUCE)
238 self.memoize(func)
/home/mendea3/anaconda2/lib/python2.7/pickle.pyc in save(self, obj)
284 f = self.dispatch.get(t)
285 if f:
--> 286 f(self, obj) # Call unbound method with explicit self
287 return
288
/home/mendea3/anaconda2/lib/python2.7/pickle.pyc in save_tuple(self, obj)
552 if n <= 3 and proto >= 2:
553 for element in obj:
--> 554 save(element)
555 # Subtle. Same as in the big comment below.
556 if id(obj) in memo:
/home/mendea3/anaconda2/lib/python2.7/pickle.pyc in save(self, obj)
284 f = self.dispatch.get(t)
285 if f:
--> 286 f(self, obj) # Call unbound method with explicit self
287 return
288
/home/mendea3/anaconda2/lib/python2.7/pickle.pyc in save_list(self, obj)
604
605 self.memoize(obj)
--> 606 self._batch_appends(iter(obj))
607
608 dispatch[ListType] = save_list
/home/mendea3/anaconda2/lib/python2.7/pickle.pyc in _batch_appends(self, items)
637 write(MARK)
638 for x in tmp:
--> 639 save(x)
640 write(APPENDS)
641 elif n:
/home/mendea3/anaconda2/lib/python2.7/pickle.pyc in save(self, obj)
304 reduce = getattr(obj, "__reduce_ex__", None)
305 if reduce:
--> 306 rv = reduce(self.proto)
307 else:
308 reduce = getattr(obj, "__reduce__", None)
/usr/local/spark/python/lib/py4j-0.9-src.zip/py4j/java_gateway.py in __call__(self, *args)
811 answer = self.gateway_client.send_command(command)
812 return_value = get_return_value(
--> 813 answer, self.gateway_client, self.target_id, self.name)
814
815 for temp_arg in temp_args:
/usr/local/spark/python/pyspark/sql/utils.py in deco(*a, **kw)
43 def deco(*a, **kw):
44 try:
---> 45 return f(*a, **kw)
46 except py4j.protocol.Py4JJavaError as e:
47 s = e.java_exception.toString()
/usr/local/spark/python/lib/py4j-0.9-src.zip/py4j/protocol.py in get_return_value(answer, gateway_client, target_id, name)
310 raise Py4JError(
311 "An error occurred while calling {0}{1}{2}. Trace:\n{3}\n".
--> 312 format(target_id, ".", name, value))
313 else:
314 raise Py4JError(
Py4JError: An error occurred while calling o18.__getnewargs__. Trace:
py4j.Py4JException: Method __getnewargs__([]) does not exist
at py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:335)
at py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:344)
at py4j.Gateway.invoke(Gateway.java:252)
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:133)
at py4j.commands.CallCommand.execute(CallCommand.java:79)
at py4j.GatewayConnection.run(GatewayConnection.java:209)
at java.lang.Thread.run(Thread.java:745)
EDIT: I also tried to make the java class serializable but to no avail.
My second attempt was to define the UDF in java to begin with but that failed as I am not sure how to correctly wrap it:
java code:
package com.test1.test2;
import org.apache.spark.sql.api.java.UDF1;
public class TestClassUdf implements UDF1<Integer, Integer> {
Integer retval;
public TestClassUdf(Integer val) {
retval = val;
}
#Override
public Integer call(Integer arg0) throws Exception {
return retval;
}
}
but how would I use it?
I tried:
from py4j.java_gateway import java_import
java_import(sc._gateway.jvm, "com.test1.test2.TestClassUdf")
a = sc._gateway.jvm.com.test1.test2.TestClassUdf(7)
dfint = sqlContext.range(0,15)
df = dfint.withColumn("a",a(dfint.id))
but I get:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-5-514811090b5f> in <module>()
3 a = sc._gateway.jvm.com.test1.test2.TestClassUdf(7)
4 dfint = sqlContext.range(0,15)
----> 5 df = dfint.withColumn("a",a(dfint.id))
TypeError: 'JavaObject' object is not callable
and I tried to use a.call instead of a:
df = dfint.withColumn("a",a.call(dfint.id))
but got:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
in ()
3 a = sc._gateway.jvm.com.test1.test2.TestClassUdf(7)
4 dfint = sqlContext.range(0,15)
----> 5 df = dfint.withColumn("a",a.call(dfint.id))
/usr/local/spark/python/lib/py4j-0.9-src.zip/py4j/java_gateway.py in __call__(self, *args)
796 def __call__(self, *args):
797 if self.converters is not None and len(self.converters) > 0:
--> 798 (new_args, temp_args) = self._get_args(args)
799 else:
800 new_args = args
/usr/local/spark/python/lib/py4j-0.9-src.zip/py4j/java_gateway.py in _get_args(self, args)
783 for converter in self.gateway_client.converters:
784 if converter.can_convert(arg):
--> 785 temp_arg = converter.convert(arg, self.gateway_client)
786 temp_args.append(temp_arg)
787 new_args.append(temp_arg)
/usr/local/spark/python/lib/py4j-0.9-src.zip/py4j/java_collections.py in convert(self, object, gateway_client)
510 HashMap = JavaClass("java.util.HashMap", gateway_client)
511 java_map = HashMap()
--> 512 for key in object.keys():
513 java_map[key] = object[key]
514 return java_map
TypeError: 'Column' object is not callable
Any help would be appriciated.
I got this working with the help of another question (and answer) of your own about UDAFs.
Spark provides a udf() method for wrapping Scala FunctionN, so we can wrap the Java function in Scala and use that. Your Java method needs to be static or on a class that implements Serializable.
package com.example
import org.apache.spark.sql.UserDefinedFunction
import org.apache.spark.sql.functions.udf
class MyUdf extends Serializable {
def getUdf: UserDefinedFunction = udf(() => MyJavaClass.MyJavaMethod())
}
Usage in PySpark:
def my_udf():
from pyspark.sql.column import Column, _to_java_column, _to_seq
pcls = "com.example.MyUdf"
jc = sc._jvm.java.lang.Thread.currentThread() \
.getContextClassLoader().loadClass(pcls).newInstance().getUdf().apply
return Column(jc(_to_seq(sc, [], _to_java_column)))
rdd1 = sc.parallelize([{'c1': 'a'}, {'c1': 'b'}, {'c1': 'c'}])
df1 = rdd1.toDF()
df2 = df1.withColumn('mycol', my_udf())
As with the UDAF in your other question and answer, we can pass columns into it with return Column(jc(_to_seq(sc, ["col1", "col2"], _to_java_column)))
In lines with https://dzone.com/articles/pyspark-java-udf-integration-1 you could define UDF1 with in Java using
public class AddNumber implements UDF1<Long, Long> {
#Override
public Long call(Long num) throws Exception {
return (num + 5);
}
}
And then after adding the jar to your pyspark with --package <your-jar>
you can use it in pyspark as:
from pyspark.sql import functions as F
from pyspark.sql.types import LongType
>>> df = spark.createDataFrame([float(i) for i in range(100)], FloatType()).toDF("a")
>>> spark.udf.registerJavaFunction("addNumber", "com.example.spark.AddNumber", LongType())
>>> df.withColumn("b", F.expr("addNumber(a)")).show(5)
+---+---+
| a| b|
+---+---+
|0.0| 5|
|1.0| 6|
|2.0| 7|
|3.0| 8|
|4.0| 8|
+---+---+
only showing top 5 rows

Final Rendered Video is Sped Up Compared to Animation Played in Processing

Recently I made an Audio Visualizer in Processing. From there I wanted to render the animation created in Processing into a mp4 file. I am on a windows computer, and am using ffmpeg to convert my TIF files produced in Processing into mp4.
When I do this I am able to render the images into an mp4 file, but when I playback this file the animation is sped up compared to the animation when I play it on Processing. Because of this the animation does not sync with the audio when I combine the mp4 file and audio on a video editing program.
When I set my frame rate to 25 and have the limit on the number of frames to be 250 and render it into a mp4 file it is 10 seconds long like it should be, but it contains more than 10 seconds of the animation when compared to the animation played directly in Processing.
I have no idea why this is so any help will be much appreciated.
My Processing code:
import ddf.minim.*;
import ddf.minim.analysis.*;
Minim minim;
AudioPlayer player;
PImage img;
FFT fft;
void setup() {
size(728, 546);
minim = new Minim(this);
// this loads mysong.wav from the data folder as a stream with a internal buffer of size 1024
player = minim.loadFile("new_years_good.mp3");
fft = new FFT(player.bufferSize(), player.sampleRate());
player.play();
img= loadImage("cat-in-shades-.jpg");
frameRate(25);
}
void draw() {
image(img, 0, 0);
//tint(0, 100, 150);
stroke(255);
strokeWeight(4);
float a = 0;
float angle = (2*PI) / 200;
fft.forward(player.mix);
for(int i=0; i < player.bufferSize() - 1; i++) {
//player.mix.get(i) is a value between [-1,1]
float x = 250 + cos(a) * (20 * player.mix.get(i) + 100);
float x2 = 540 + cos(a) * (20 * player.mix.get(i) + 100);
float y = 230 + sin(a) * (20 * player.mix.get(i) + 100);
float y2 = 240 + sin(a) * (20 * player.mix.get(i) + 100);
float xFinal = 250 + cos(a+angle) * (20 * player.mix.get(i+1) + 100);
float x2Final = 540 + cos(a+angle) * (20 * player.mix.get(i+1) + 100);
float yFinal = 230 + sin(a+angle) * (20 * player.mix.get(i+1) + 100);
float y2Final = 240 + sin(a+angle) * (20 * player.mix.get(i+1) + 100);
line(x,y,xFinal,yFinal);
line(x2,y2,x2Final,y2Final);
a += angle;
}
noStroke();
fill(255, 0, 0, 128);
for(int i = 0; i < 250; i++)
{
float b = fft.getBand(i);
float yAxis = random(-b, b) + 480;
float xAxis = i*3;
ellipse(xAxis, yAxis, b, b);
}
saveFrame("frame-####.tif");
if(frameCount>250)
{
noLoop();
stop();
}
}
void stop() {
player.close();
minim.stop();
super.stop();
}
What I input into the command line (as one line) on the cmd:
C:\Users\Robert\Documents\Processing\AudioVisulizer>ffmpeg -i C:\Users\Robert\Do
cuments\Processing\AudioVisulizer\frame-%04d.tif -r 25 -pix_fmt yuv420p smallVid
.mp4
What it outputted:
ffmpeg version N-77836-g62dfe1d Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 5.2.0 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-av
isynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab
le-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --
enable-libdcadec --enable-libfreetype --enable-libgme --enable-libgsm --enable-l
ibilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enab
le-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --en
able-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --ena
ble-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc
--enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enabl
e-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --
enable-lzma --enable-decklink --enable-zlib
libavutil 55. 13.100 / 55. 13.100
libavcodec 57. 22.100 / 57. 22.100
libavformat 57. 21.101 / 57. 21.101
libavdevice 57. 0.100 / 57. 0.100
libavfilter 6. 23.100 / 6. 23.100
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.101 / 2. 0.101
libpostproc 54. 0.100 / 54. 0.100
Input #0, image2, from 'C:\Users\Robert\Documents\Processing\AudioVisulizer\fram
e-%04d.tif':
Duration: 00:00:10.04, start: 0.000000, bitrate: N/A
Stream #0:0: Video: tiff, rgb24, 728x546, 25 fps, 25 tbr, 25 tbn, 25 tbc
[libx264 # 00000092cd5e3700] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2
AVX FMA3 AVX2 LZCNT BMI2
[libx264 # 00000092cd5e3700] profile High, level 3.0
[libx264 # 00000092cd5e3700] 264 - core 148 r2638 7599210 - H.264/MPEG-4 AVC cod
ec - Copyleft 2003-2015 - http://www.videolan.org/x264.html - options: cabac=1 r
ef=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed
_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pski
p=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 deci
mate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_
adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=2
5 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.6
0 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'smallVid.mp4':
Metadata:
encoder : Lavf57.21.101
Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 728x54
6, q=-1--1, 25 fps, 12800 tbn, 25 tbc
Metadata:
encoder : Lavc57.22.100 libx264
Side data:
unknown side data type 10 (24 bytes)
Stream mapping:
Stream #0:0 -> #0:0 (tiff (native) -> h264 (libx264))
Press [q] to stop, [?] for help
frame= 52 fps=0.0 q=28.0 size= 77kB time=00:00:00.00 bitrate=N/A speed=
frame= 74 fps= 65 q=28.0 size= 127kB time=00:00:00.88 bitrate=1178.0kbits/
frame= 93 fps= 57 q=28.0 size= 164kB time=00:00:01.64 bitrate= 820.0kbits/
frame= 113 fps= 52 q=28.0 size= 201kB time=00:00:02.44 bitrate= 676.3kbits/
frame= 136 fps= 51 q=28.0 size= 245kB time=00:00:03.36 bitrate= 596.3kbits/
frame= 157 fps= 49 q=28.0 size= 282kB time=00:00:04.20 bitrate= 550.2kbits/
frame= 178 fps= 48 q=28.0 size= 324kB time=00:00:05.04 bitrate= 527.2kbits/
frame= 199 fps= 47 q=28.0 size= 362kB time=00:00:05.88 bitrate= 504.1kbits/
frame= 219 fps= 46 q=28.0 size= 403kB time=00:00:06.68 bitrate= 494.2kbits/
frame= 242 fps= 46 q=28.0 size= 452kB time=00:00:07.60 bitrate= 486.8kbits/
frame= 251 fps= 38 q=-1.0 Lsize= 623kB time=00:00:09.96 bitrate= 512.3kbits
/s speed=1.52x
video:619kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing o
verhead: 0.607807%
[libx264 # 00000092cd5e3700] frame I:2 Avg QP:21.74 size: 56596
[libx264 # 00000092cd5e3700] frame P:66 Avg QP:23.36 size: 2523
[libx264 # 00000092cd5e3700] frame B:183 Avg QP:31.50 size: 1932
[libx264 # 00000092cd5e3700] consecutive B-frames: 0.8% 4.0% 6.0% 89.2%
[libx264 # 00000092cd5e3700] mb I I16..4: 10.9% 72.6% 16.5%
[libx264 # 00000092cd5e3700] mb P I16..4: 0.0% 0.0% 0.2% P16..4: 4.4% 2.3
% 3.3% 0.0% 0.0% skip:89.7%
[libx264 # 00000092cd5e3700] mb B I16..4: 0.0% 0.0% 0.5% B16..8: 3.2% 2.0
% 2.3% direct: 1.3% skip:90.7% L0:50.9% L1:42.2% BI: 7.0%
[libx264 # 00000092cd5e3700] 8x8 transform intra:50.2% inter:10.1%
[libx264 # 00000092cd5e3700] coded y,uvDC,uvAC intra: 83.4% 32.6% 14.2% inter: 3
.5% 0.2% 0.0%
[libx264 # 00000092cd5e3700] i16 v,h,dc,p: 22% 8% 8% 62%
[libx264 # 00000092cd5e3700] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 19% 12% 19% 6% 9%
9% 9% 9% 9%
[libx264 # 00000092cd5e3700] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 22% 14% 22% 6% 9%
8% 8% 5% 6%
[libx264 # 00000092cd5e3700] i8c dc,h,v,p: 74% 12% 12% 2%
[libx264 # 00000092cd5e3700] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 # 00000092cd5e3700] ref P L0: 41.8% 3.9% 24.3% 30.0%
[libx264 # 00000092cd5e3700] ref B L0: 64.5% 25.0% 10.5%
[libx264 # 00000092cd5e3700] ref B L1: 82.2% 17.8%
[libx264 # 00000092cd5e3700] kb/s:504.56
The fact that you managed to get the sound and the video synchronized in the running program probably means you run it on a free CPU
If music and video are two separate threads (as I understand it) its not guaranteed that the CPU will run them always so.
So if you want to have your final video .mp4 synchronized you have to work outside the program: take them together to a video editing software and synchronize them.
But if you want them synchronized in the program you are fine.

different output while running a command from java

I have following script:
#!/bin/bash
ID=$PPID
read PID < <(exec ps -o ppid= "$ID")
top -cbn 1 -p $PID
grep -f <(pstree -cp $PID | grep -Po '\(\K\d+'| sed -re 's/$/ /g' | sed -re 's/^/^\\s\*/g' ) <(top -cbn 1)
When I am running this script from command prompt the output is
top - 16:43:17 up 6:40, 6 users, load average: 0.04, 0.02, 0.00
Tasks: 1 total, 0 running, 1 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.9%us, 0.6%sy, 0.0%ni, 98.1%id, 0.4%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 4152800k total, 1908108k used, 2244692k free, 92984k buffers
Swap: 1048568k total, 0k used, 1048568k free, 1104756k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
16866 root 40 0 7792 3188 2088 S 0.0 0.1 0:00.01 su
16750 builder 40 0 1213m 262m 15m S 0.0 6.5 0:55.43 /opt/ibm/java-i386-60/jre/bin/java -Dosgi.requiredJavaVersion=1.6 -XX:MaxPermSize=256m -Xms40m -Xmx1024m -jar /home/builder/eclipse//plugins/org.eclipse.equinox.launcher_1.3.0.
Notice the output of COMMAND and it is displaying the complete command. But if I run the same program from java, the output truncate the COMMAND name and I am not able to figure out why ?
Truncation occur after 19 character.
Or in different words
Every line truncate after 80 character.
Here is the output if I run the same program using Java
top - 16:13:52 up 6:10, 6 users, load average: 0.16, 0.16, 0.06
Tasks: 1 total, 0 running, 1 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.9%us, 0.6%sy, 0.0%ni, 98.0%id, 0.4%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 4152800k total, 1913364k used, 2239436k free, 91560k buffers
Swap: 1048568k total, 0k used, 1048568k free, 1103952k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
16750 builder 40 0 1206m 257m 15m S 0.0 6.3 0:26.32 /opt/ibm/java-i386-
16750 builder 40 0 1206m 257m 15m S 1.9 6.3 0:26.33 /opt/ibm/java-i386-
16943 builder 20 0 2608 1008 748 R 1.9 0.0 0:00.02 top -cbn 1
16918 builder 20 0 554m 14m 6060 S 0.0 0.4 0:00.10 /opt/ibm/java-i386-
16934 builder 20 0 4976 1120 992 S 0.0 0.0 0:00.00 /bin/bash /home/bui
16941 builder 20 0 4976 508 376 S 0.0 0.0 0:00.00 /bin/bash /home/bui
16942 builder 20 0 4388 888 608 S 0.0 0.0 0:00.00 grep -f /dev/fd/63
My java file to run the command is
public class InformationFetcher {
public static void main(String[] args) {
InformationFetcher informationFetcher = new InformationFetcher();
try {
Process process = Runtime.getRuntime().exec(
informationFetcher.getFilePath());
InputStream in = process.getInputStream();
printInputStream(in);
} catch (IOException e) {
e.printStackTrace();
}
}
private void processInformation(InputStream in) {
topProcessor.process(in);
}
private static void printInputStream(InputStream in) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuffer outBuffer = new StringBuffer();
String newLine = System.getProperty("line.separator");
String line;
while ((line = reader.readLine()) != null) {
outBuffer.append(line);
outBuffer.append(newLine);
}
System.out.println(outBuffer.toString());
}
public String getFilePath() {
return this.getClass().getResource("/idFetcher.sh").getPath();
}
}

Error in JNI method returning ArrayList of Points

I'm trying to use JNI to import a c++ library that I will use in my java project. I have successfully gotten the library method to be called and am trying to return an ArrayList of Point objects from the JNI function. However, I'm getting an error with a rather vague description ('Problematic frame:
V [libjvm.dylib+0x30bab5] JNI_ArgumentPusherVaArg::JNI_ArgumentPusherVaArg(_jmethodID*, __va_list_tag*)+0xd
'). I have no clue what's going on, does anyone know what's going on or how I should interpret this console output? I can attach the log file if anyone wants it.
Console output:
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x000000010550bab5, pid=4633, tid=6403
#
# JRE version: Java(TM) SE Runtime Environment (7.0_51-b13) (build 1.7.0_51-b13)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (24.51-b03 mixed mode bsd-amd64 compressed oops)
# Problematic frame:
# V [libjvm.dylib+0x30bab5] JNI_ArgumentPusherVaArg::JNI_ArgumentPusherVaArg(_jmethodID*, __va_list_tag*)+0xd
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /Users/zalbhathena/Documents/workspace/Thesis-Test-Application/HPA* Program/hs_err_pid4633.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.sun.com/bugreport/crash.jsp
#
Hello World!
ASDFse_dcdt.cpp 284 : Starting init()...
SeDcdt::initfoo.512se_dcdt.cpp 303 : Calculating External Polygon for domain with 4 points...
se_dcdt.cpp 317 : Creating External Polygon...
SeDcdt::initse_dcdt.cpp 326 : Backface v1: -14 -14
se_dcdt.cpp 329 : Backface v2: -14 14
se_dcdt.cpp 332 : Backface v3: 14 14
se_dcdt.cpp 335 : Backface v4: 14 -14
se_triangulator.cpp 417 : insert_point_in_edge...
se_triangulator.cpp 473 : propagate_delaunay...
se_triangulator.cpp 480 : optimizing in constrained mode...4
se_triangulator.cpp 538 : Ok.
se_triangulator.cpp 387 : insert_point_in_face...
se_triangulator.cpp 473 : propagate_delaunay...
se_triangulator.cpp 480 : optimizing in constrained mode...3
se_triangulator.cpp 538 : Ok.
se_triangulator.cpp 417 : insert_point_in_edge...
se_triangulator.cpp 473 : propagate_delaunay...
se_triangulator.cpp 480 : optimizing in constrained mode...4
se_triangulator.cpp 538 : Ok.
se_triangulator.cpp 387 : insert_point_in_face...
se_triangulator.cpp 473 : propagate_delaunay...
se_triangulator.cpp 480 : optimizing in constrained mode...3
se_triangulator.cpp 538 : Ok.
se_triangulator.cpp 417 : insert_point_in_edge...
se_triangulator.cpp 473 : propagate_delaunay...
se_triangulator.cpp 480 : optimizing in constrained mode...4
se_triangulator.cpp 538 : Ok.
se_triangulator.cpp 387 : insert_point_in_face...
se_triangulator.cpp 473 : propagate_delaunay...
se_triangulator.cpp 480 : optimizing in constrained mode...3
se_triangulator.cpp 538 : Ok.
se_triangulator.cpp 387 : insert_point_in_face...
se_triangulator.cpp 473 : propagate_delaunay...
se_triangulator.cpp 480 : optimizing in constrained mode...3
se_triangulator.cpp 538 : Ok.
1
2
3
4
HPAProgram.cpp
/*
* HPAProgram.c++
*
* Created on: Feb 4, 2014
* Author: zalbhathena
*/
//=#include <jni.h>
#include <stdio.h>
#include "HPAProgram.h"
#include "DCDTWrapper.h"
JNIEXPORT jobject JNICALL Java_HPAProgram_sayHello (JNIEnv *env, jobject obj) {
printf("Hello World!\n");
GsArray<GsPnt2> edges;
create_dcdt(&edges);
printf("1\n");
jclass arraylist_class = (*env).FindClass("java/util/ArrayList");
jclass point_class = (*env).FindClass("java/awt/Point");
jmethodID init_arraylist = (*env).GetMethodID(arraylist_class, "<init>", "()V");
jmethodID init_point = (*env).GetMethodID(point_class, "<init>", "(II)V");
jmethodID add_arraylist = (*env).GetMethodID(arraylist_class, "add", "(java/lang/Object)V");
jobject return_obj = (*env).NewObject(arraylist_class, init_arraylist);
printf("2\n");
for (int n=0;n<edges.size();n++)
{
jfloat x = 1;
jfloat y = 1;
printf("3\n");
jobject point_obj = (*env).NewObject(point_class, init_point,x,y);
printf("4\n");
(*env).CallVoidMethod(return_obj, add_arraylist, point_obj);
printf("5\n");
}
return nullptr;
}
DCDTWrapper.cpp
# define END 12345.6
# define FIRST_EXAMPLE Example1
//# include "DCDTsrc/se_dcdt.h"
//# include "DCDTsrc/gs_polygon.h"
//# include <stdlib.h>
# include "DCDTWrapper.h"
static double Example1[] =
{ -10, -10, 10, -10, 10, 10, -10, 10, END,
1, 1, 7, 3, 3, 8, END,
END };
static const double* CurExample = FIRST_EXAMPLE;
static SeDcdt TheDcdt;
static GsPolygon CurPath;
static GsPolygon CurChannel;
static float CurX1=0, CurY1=0, CurX2=0, CurY2=0;
static int CurSelection=0; // -2,-1: moving point, >0: moving polygon
void create_dcdt (GsArray<GsPnt2>* edges)
{
printf("ASDF");
const double* data = CurExample;
GsPolygon pol;
// domain:
while ( *data!=END ) { pol.push().set((float)data[0],(float)data[1]); data+=2; }
TheDcdt.init ( pol, 0.00001f );
while ( *++data!=END )
{ pol.size(0);
while ( *data!=END ) { pol.push().set((float)data[0],(float)data[1]); data+=2; }
TheDcdt.insert_polygon ( pol );
}
GsArray<GsPnt2> unconstr;
TheDcdt.get_mesh_edges(edges, &unconstr);
for(int i = 0; i < unconstr.size(); i++) {
edges -> push(unconstr.get(i));
}
}
HPAProgram.java
import java.util.ArrayList;
public class HPAProgram {
/* static {
//System.out.println(new File(".").getAbsolutePath());
System.loadLibrary("libhpaprogram"); // hello.dll (Windows) or libhello.so (Unixes)
}
//private native void sayHello();
*/
public native ArrayList<String> sayHello();
public static void main(String[] args) {
System.loadLibrary("HPAProgram");
HPAProgram s = new HPAProgram();
s.sayHello();
MapWindowController map = new MapWindowController();
}
}
Function addfrom class ArrayList has return type boolean not void so in c code you have to call CallBooleanMethod from env instead of CallVoidMethod.
Edit: And you need to correct the signature of the add method as well.
You need to change the method signature for "add" element in arrayList as below:
jmethodID add_arraylist = (*env).GetMethodID(arraylist_class, "add", "(java/lang/Object)Z");
instead of
jmethodID add_arraylist = (*env).GetMethodID(arraylist_class, "add", "(java/lang/Object)V");

Categories