Well, I have spent a great deal of time to find a way of combine gif files using ffmpeg library.But none of them seems to work for me.
What I have tried (I have used ffmpeg android java library):
String gif1=Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)+"/gif1.gif";
String gif2=Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)+"/gif2.gif";
String commandStr="-i concat:"+gif1+"|"+gif2+" -c copy "+file.getAbsolutePath()+"/output.gif";
String[]command=commandStr.split(" ");
ffmpeg.execute(command, new ExecuteBinaryResponseHandler() {
#Override
public void onStart() {}
#Override
public void onProgress(String message) {
// Toast.makeText(Main.this,"Progress: "+message,Toast.LENGTH_SHORT).show();
Log.e("Progress TAG: ",message);
}
#Override
public void onFailure(String message) {
Toast.makeText(Main.this,"Failed: "+message,Toast.LENGTH_SHORT).show();
Log.e("Failure TAG: ",message);
}
#Override
public void onSuccess(String message)
{
Toast.makeText(Main.this,"Success: "+message,Toast.LENGTH_SHORT).show();
Log.e("Success TAG: ",message);
}
#Override
public void onFinish() {}
});
} catch (FFmpegCommandAlreadyRunningException e) {
// Handle if FFmpeg is already running
}
But above command gives an error like this.
ffmpeg version n3.0.1 Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 4.8 (GCC)
configuration: --target-os=linux --cross-prefix=/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/bin/arm-linux-androideabi- --arch=arm --cpu=cortex-a8 --enable-runtime-cpudetect --sysroot=/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/sysroot --enable-pic --enable-libx264 --enable-libass --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-fontconfig --enable-pthreads --disable-debug --disable-ffserver --enable-version3 --enable-hardcoded-tables --disable-ffplay --disable-ffprobe --enable-gpl --enable-yasm --disable-doc --disable-shared --enable-static --pkg-config=/home/vagrant/SourceCode/ffmpeg-android/ffmpeg-pkg-config --prefix=/home/vagrant/SourceCode/ffmpeg-android/build/armeabi-v7a --extra-cflags='-I/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/include -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all' --extra-ldflags='-L/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/lib -Wl,-z,relro -Wl,-z,now -pie' --extra-libs='-lpng -lexpat -lm' --extra-cxxflags=
libavutil 55. 17.103 / 55. 17.103
libavcodec 57. 24.102 / 57. 24.102
libavformat 57. 25.100 / 57. 25.100
libavdevice 57. 0.101 / 57. 0.101
libavfilter 6. 31.100 / 6. 31.100
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.101 / 2. 0.101
libpostproc 54. 0.100 / 54. 0.100
Input #0, gif, from 'concat:/storage/emulated/0/Pictures/gif1.gif|/storage/emulated/0/Pictures/gif2.gif':
Duration: N/A, bitrate: N/A
Stream #0:0: Video: gif, bgra, 500x500, 1.70 fps, 10 tbr, 100 tbn, 100 tbc
Assertion video_enc->pix_fmt == AV_PIX_FMT_PAL8 failed at libavformat/gif.c:130
Can anyone please suggest me an efficient command to do this.
P.S: I have a dynamic file list so can't use the demuxing method which uses a text file.
Related
hi … I am trying to use FFmpegFrameRecorder to extract an audio from a video using this code
FFmpegFrameGrabber frameGrabber = new FFmpegFrameGrabber(mp4Path);
frameGrabber.start();
FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(new
File("C:/Users/ASUS/Desktop/audio.aac"),audioChannels);
recorder.setAudioMetadata(frameGrabber.getAudioMetadata());
recorder.setFrameRate(frameGrabber.getFrameRate());
recorder.setTimestamp(frameGrabber.getTimestamp());
recorder.start(frameGrabber.getFormatContext());
Frame f=null;
//get audio sample and record it
while ((f = frameGrabber.grabSamples()) != null) {
recorder.record(f);
}
frameGrabber.stop();
recorder.stop();
recorder.close();
LOGGER.info("C:/Users/ASUS/Desktop/audio.aac");
but when I run it it gives me in terminal:
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'C:/Users/ASUS/Desktop/Lou.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.76.100
Duration: 00:00:39.10, start: 0.000000, bitrate: 116 kb/s
Stream #0:0[0x1](und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709,
progressive), 256x144 [SAR 1:1 DAR 16:9], 63 kb/s, 23.98 fps, 23.98 tbr, 90k tbn (default)
Metadata:
handler_name : VideoHandler
vendor_id : [0][0][0][0]
Stream #0:1[0x2](und): Audio: aac (HE-AAC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 46 kb/s (default)
Metadata:
handler_name : SoundHandler
vendor_id : [0][0][0][0]
[aac # 000000001afd7080] noise_facs_q 31 is invalid
[aac # 000000001afd7080] noise_facs_q 31 is invalid
[aac # 000000001afd7080] noise_facs_q 31 is invalid
[aac # 000000001afd7080] noise_facs_q 31 is invalid
[aac # 000000001afd7080] noise_facs_q 31 is invalid
[aac # 000000001afd7080] noise_facs_q 31 is invalid
[aac # 000000001afd7080] noise_facs_q 31 is invalid
[h264 # 000000001ad8bc40] mmco: unref short failure
[h264 # 000000001ad8bc40] mmco: unref short failure
[h264 # 000000001ad8bc40] mmco: unref short failure
[h264 # 000000001ad8bc40] mmco: unref short failure
[h264 # 000000001ad8bc40] mmco: unref short failure
and so on ...
Output #0, adts, to 'C:\Users\ASUS\Desktop\aud.aac':
Metadata:
encoder : Lavf59.16.100
Stream #0:0: Audio: aac (HE-AAC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 46 kb/s
and when I try to run the audio it is not running
what's the wrong thing I did?
Assume original message size is 500 bytes (before sending it to the Kafka). So what will be the size of the message after sending it to the Kafka? And what if we use any compression?
Additional information: I am putting a ByteBuffer of size 2048 bytes to a topic (with single partition) without any key.
Topic name: ub3
Path: /data/kafka-logs/ub3-0
[hdpusr#hdpdev2 ub3-0]$ $KAFKA_HOME/bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list hdpdev2:8092 --topic ub3 --time -1 --offsets 1 | awk -F ":" '{sum += $3} END {print sum}'
184
[hdpusr#hdpdev2 ub3-0]$ du -sh *
10M 00000000000000000000.index
448K 00000000000000000000.log
10M 00000000000000000000.timeindex
4.0K leader-epoch-checkpoint
[hdpusr#hdpdev2 ub3-0]$
[hdpusr#hdpdev2 ub3-0]$
[hdpusr#hdpdev2 ub3-0]$ $KAFKA_HOME/bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list hdpdev2:8092 --topic ub3 --time -1 --offsets 1 | awk -F ":" '{sum += $3} END {print sum}'
86284
[hdpusr#hdpdev2 ub3-0]$ du -sh *
10M 00000000000000000000.index
256M 00000000000000000000.log
10M 00000000000000000000.timeindex
4.0K leader-epoch-checkpoint
[hdpusr#hdpdev2 ub3-0]$
[hdpusr#hdpdev2 ub3-0]$ $KAFKA_HOME/bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list hdpdev2:8092 --topic ub3 --time -1 --offsets 1 | awk -F ":" '{sum += $3} END {print sum}'
172405
[hdpusr#hdpdev2 ub3-0]$ du -sh *
10M 00000000000000000000.index
512M 00000000000000000000.log
10M 00000000000000000000.timeindex
4.0K leader-epoch-checkpoint
[hdpusr#hdpdev2 ub3-0]$
[hdpusr#hdpdev2 ub3-0]$ $KAFKA_HOME/bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list hdpdev2:8092 --topic ub3 --time -1 --offsets 1 | awk -F ":" '{sum += $3} END {print sum}'
258491
[hdpusr#hdpdev2 ub3-0]$ du -sh *
10M 00000000000000000000.index
596M 00000000000000000000.log
10M 00000000000000000000.timeindex
4.0K leader-epoch-checkpoint
[hdpusr#hdpdev2 ub3-0]$
[hdpusr#hdpdev2 ub3-0]$ $KAFKA_HOME/bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list hdpdev2:8092 --topic ub3 --time -1 --offsets 1 | awk -F ":" '{sum += $3} END {print sum}'
344563
[hdpusr#hdpdev2 ub3-0]$ du -sh *
10M 00000000000000000000.index
1.1G 00000000000000000000.log
10M 00000000000000000000.timeindex
4.0K leader-epoch-checkpoint
[hdpusr#hdpdev2 ub3-0]$
The short answer is: who knows?
But let's try to find out some numbers. I have started a Kafka in Docker using this guide. Then, wrote a simple producer:
public class App {
public static void main(String[] args) throws Exception {
final Producer<String, byte[]> producer = producer();
producer.send(
new ProducerRecord<>(
"test",
key(),
value()
)
).get();
}
private static Producer<String, byte[]> producer() {
final Properties props = new Properties();
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
props.put(ProducerConfig.CLIENT_ID_CONFIG, "so57472830");
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, ByteArraySerializer.class.getName());
return new KafkaProducer<>(props);
}
private static String key() {
return UUID.randomUUID().toString();
}
}
So, will be sending to localhost:9092 with a client id equal to so57472830 into a test topic. The payloads are byte arrays and keys are string UUIDs. As you'll see later all these values (except the host:port) contribute to the "overhead". Here I suppose that overhead is everything except the message payload itself.
Let's start with a "Hello, world!":
private static byte[] value() {
return "Hello, world!".getBytes();
}
Run the app and capture the traffic to localhost:9092. I used WireShark for that.
Here I found the message with the payload. Let's see the whole TCP stream ("Follow TCP stream" in WireShark):
So, the whole stream took 527 bytes of which the client send (highlighted with rose color) 195:
(This also means that Kafka send 527 - 195 == 332 bytes in response):
Our payload was 13 bytes. As you noticed, the outbound traffic contains the client id twice (2 × 10 bytes) and the message key (16 bytes). So, of 195 bytes send 146 are mystery (probably the one that you named as "overhead" in your question).
Let's send 500 random bytes:
private static byte[] value() {
final byte[] result = new byte[500];
new Random().nextBytes(result);
return result;
}
Outbound traffic was 684 bytes (the entire conversation took 1016):
Again, the server send 332 byte in response and the outbound mystery (overhead) made up 684 - (500 + 2 × 10 + 16) = 164 bytes!
All these numbers are not final and may change with producer versions or specific config settings. One of them, you've mentioned, is compression. Let's check it out. Be warned that the compression depends on the data. Random bytes are tougher to compress than the constant ones as they have more entropy. So, let's send 500 repetiting bytes with a GZIP compression. Without the compression, the numbers are the same:
Add props.put(ProducerConfig.COMPRESSION_TYPE_CONFIG, "gzip"); to the producer() method and change the value():
private static byte[] value() {
final byte[] result = new byte[500];
Arrays.fill(result, (byte) 'a');
return result;
}
When the compression is enabled, the message (key and value, not the client id and topic) are compressed, and the outbound traffic is only 208 bytes:
I'd say that the overhead is about the same as in the examples above, the compression impacts the size of the message itself.
That all applies to the traffic, but after your edit I see you were interested in the storage size. Nevertheless, I would say that the answer is the same: "who knows". The numbers definitely depend on your configuration.
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.
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.
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.