ffmpeg not converting entire video in java application - java

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.

Related

couldn't render an audio after extracting the audio from the video

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?

double precision no truncation when typecast to int

The following:
double x = .43;
BigDecimal bd = new BigDecimal(z);
System.out.println(bd);
outputs:
.4299999.....
why does
double u = z*100;
bd = new BigDecimal(u);
System.out.println(u);
output:
43?
more generally I'm trying to find a case where the double representation causes a truncation problem. Consider the following:
double d;
int j;
BigDecimal bd;
for(int i = 0; i<10000;i++){
d= (double)(i/100.);
j = (int)(d*100.);
bd = new BigDecimal(j);
System.out.println(bd);
}
In not a single case is truncating occurring
In not a single case is truncating occurring
That is incorrect. Truncation occurs many times, you just didn't look close enough.
E.g. for i = 29:
int i = 29;
double d= i / 100.;
int j = (int)(d * 100.);
BigDecimal bd = new BigDecimal(j);
System.out.println(bd);
Output
28
OOPS!!!
Though I don't know what the point of converting j to bd is, since new BigDecimal(int) is always exact.
If you want to see all the truncation errors, try this:
for (int i = 0; i < 10000; i++){
double d = i / 100.;
int j = (int)(d * 100.);
if (i != j)
System.out.println(i + ": " + j);
}
Output
29: 28
57: 56
58: 57
113: 112
114: 113
115: 114
116: 115
201: 200
203: 202
205: 204
207: 206
226: 225
228: 227
230: 229
232: 231
251: 250
253: 252
255: 254
402: 401
406: 405
410: 409
414: 413
427: 426
431: 430
435: 434
439: 438
452: 451
456: 455
460: 459
464: 463
477: 476
481: 480
485: 484
489: 488
502: 501
506: 505
510: 509
803: 802
804: 803
812: 811
820: 819
828: 827
829: 828
837: 836
845: 844
853: 852
854: 853
862: 861
870: 869
878: 877
879: 878
887: 886
895: 894
903: 902
904: 903
912: 911
920: 919
928: 927
929: 928
937: 936
945: 944
953: 952
954: 953
962: 961
970: 969
978: 977
979: 978
987: 986
995: 994
1003: 1002
1004: 1003
1012: 1011
1020: 1019
1606: 1605
1608: 1607
1615: 1614
1624: 1623
1631: 1630
1633: 1632
1640: 1639
1649: 1648
1656: 1655
1658: 1657
1665: 1664
1674: 1673
1681: 1680
1683: 1682
1690: 1689
1699: 1698
1706: 1705
1708: 1707
1715: 1714
1724: 1723
1731: 1730
1733: 1732
1740: 1739
1749: 1748
1756: 1755
1758: 1757
1765: 1764
1774: 1773
1781: 1780
1783: 1782
1790: 1789
1799: 1798
1806: 1805
1808: 1807
1815: 1814
1824: 1823
1831: 1830
1833: 1832
1840: 1839
1849: 1848
1856: 1855
1858: 1857
1865: 1864
1874: 1873
1881: 1880
1883: 1882
1890: 1889
1899: 1898
1906: 1905
1908: 1907
1915: 1914
1924: 1923
1931: 1930
1933: 1932
1940: 1939
1949: 1948
1956: 1955
1958: 1957
1965: 1964
1974: 1973
1981: 1980
1983: 1982
1990: 1989
1999: 1998
2006: 2005
2008: 2007
2015: 2014
2024: 2023
2031: 2030
2033: 2032
2040: 2039
3205: 3204
3212: 3211
3216: 3215
3223: 3222
3230: 3229
3237: 3236
3241: 3240
3248: 3247
3255: 3254
3262: 3261
3266: 3265
3273: 3272
3280: 3279
3287: 3286
3291: 3290
3298: 3297
3305: 3304
3312: 3311
3316: 3315
3323: 3322
3330: 3329
3337: 3336
3341: 3340
3348: 3347
3355: 3354
3362: 3361
3366: 3365
3373: 3372
3380: 3379
3387: 3386
3391: 3390
3398: 3397
3405: 3404
3412: 3411
3416: 3415
3423: 3422
3430: 3429
3437: 3436
3441: 3440
3448: 3447
3455: 3454
3462: 3461
3466: 3465
3473: 3472
3480: 3479
3487: 3486
3491: 3490
3498: 3497
3505: 3504
3512: 3511
3516: 3515
3523: 3522
3530: 3529
3537: 3536
3541: 3540
3548: 3547
3555: 3554
3562: 3561
3566: 3565
3573: 3572
3580: 3579
3587: 3586
3591: 3590
3598: 3597
3605: 3604
3612: 3611
3616: 3615
3623: 3622
3630: 3629
3637: 3636
3641: 3640
3648: 3647
3655: 3654
3662: 3661
3666: 3665
3673: 3672
3680: 3679
3687: 3686
3691: 3690
3698: 3697
3705: 3704
3712: 3711
3716: 3715
3723: 3722
3730: 3729
3737: 3736
3741: 3740
3748: 3747
3755: 3754
3762: 3761
3766: 3765
3773: 3772
3780: 3779
3787: 3786
3791: 3790
3798: 3797
3805: 3804
3812: 3811
3816: 3815
3823: 3822
3830: 3829
3837: 3836
3841: 3840
3848: 3847
3855: 3854
3862: 3861
3866: 3865
3873: 3872
3880: 3879
3887: 3886
3891: 3890
3898: 3897
3905: 3904
3912: 3911
3916: 3915
3923: 3922
3930: 3929
3937: 3936
3941: 3940
3948: 3947
3955: 3954
3962: 3961
3966: 3965
3973: 3972
3980: 3979
3987: 3986
3991: 3990
3998: 3997
4005: 4004
4012: 4011
4016: 4015
4023: 4022
4030: 4029
4037: 4036
4041: 4040
4048: 4047
4055: 4054
4062: 4061
4066: 4065
4073: 4072
4080: 4079
4087: 4086
4091: 4090
6407: 6406
6410: 6409
6421: 6420
6424: 6423
6432: 6431
6435: 6434
6446: 6445
6449: 6448
6457: 6456
6460: 6459
6471: 6470
6474: 6473
6482: 6481
6485: 6484
6496: 6495
6499: 6498
6507: 6506
6510: 6509
6521: 6520
6524: 6523
6532: 6531
6535: 6534
6546: 6545
6549: 6548
6557: 6556
6560: 6559
6571: 6570
6574: 6573
6582: 6581
6585: 6584
6596: 6595
6599: 6598
6607: 6606
6610: 6609
6621: 6620
6624: 6623
6632: 6631
6635: 6634
6646: 6645
6649: 6648
6657: 6656
6660: 6659
6671: 6670
6674: 6673
6682: 6681
6685: 6684
6696: 6695
6699: 6698
6707: 6706
6710: 6709
6721: 6720
6724: 6723
6732: 6731
6735: 6734
6746: 6745
6749: 6748
6757: 6756
6760: 6759
6771: 6770
6774: 6773
6782: 6781
6785: 6784
6796: 6795
6799: 6798
6807: 6806
6810: 6809
6821: 6820
6824: 6823
6832: 6831
6835: 6834
6846: 6845
6849: 6848
6857: 6856
6860: 6859
6871: 6870
6874: 6873
6882: 6881
6885: 6884
6896: 6895
6899: 6898
6907: 6906
6910: 6909
6921: 6920
6924: 6923
6932: 6931
6935: 6934
6946: 6945
6949: 6948
6957: 6956
6960: 6959
6971: 6970
6974: 6973
6982: 6981
6985: 6984
6996: 6995
6999: 6998
7007: 7006
7010: 7009
7021: 7020
7024: 7023
7032: 7031
7035: 7034
7046: 7045
7049: 7048
7057: 7056
7060: 7059
7071: 7070
7074: 7073
7082: 7081
7085: 7084
7096: 7095
7099: 7098
7107: 7106
7110: 7109
7121: 7120
7124: 7123
7132: 7131
7135: 7134
7146: 7145
7149: 7148
7157: 7156
7160: 7159
7171: 7170
7174: 7173
7182: 7181
7185: 7184
7196: 7195
7199: 7198
7207: 7206
7210: 7209
7221: 7220
7224: 7223
7232: 7231
7235: 7234
7246: 7245
7249: 7248
7257: 7256
7260: 7259
7271: 7270
7274: 7273
7282: 7281
7285: 7284
7296: 7295
7299: 7298
7307: 7306
7310: 7309
7321: 7320
7324: 7323
7332: 7331
7335: 7334
7346: 7345
7349: 7348
7357: 7356
7360: 7359
7371: 7370
7374: 7373
7382: 7381
7385: 7384
7396: 7395
7399: 7398
7407: 7406
7410: 7409
7421: 7420
7424: 7423
7432: 7431
7435: 7434
7446: 7445
7449: 7448
7457: 7456
7460: 7459
7471: 7470
7474: 7473
7482: 7481
7485: 7484
7496: 7495
7499: 7498
7507: 7506
7510: 7509
7521: 7520
7524: 7523
7532: 7531
7535: 7534
7546: 7545
7549: 7548
7557: 7556
7560: 7559
7571: 7570
7574: 7573
7582: 7581
7585: 7584
7596: 7595
7599: 7598
7607: 7606
7610: 7609
7621: 7620
7624: 7623
7632: 7631
7635: 7634
7646: 7645
7649: 7648
7657: 7656
7660: 7659
7671: 7670
7674: 7673
7682: 7681
7685: 7684
7696: 7695
7699: 7698
7707: 7706
7710: 7709
7721: 7720
7724: 7723
7732: 7731
7735: 7734
7746: 7745
7749: 7748
7757: 7756
7760: 7759
7771: 7770
7774: 7773
7782: 7781
7785: 7784
7796: 7795
7799: 7798
7807: 7806
7810: 7809
7821: 7820
7824: 7823
7832: 7831
7835: 7834
7846: 7845
7849: 7848
7857: 7856
7860: 7859
7871: 7870
7874: 7873
7882: 7881
7885: 7884
7896: 7895
7899: 7898
7907: 7906
7910: 7909
7921: 7920
7924: 7923
7932: 7931
7935: 7934
7946: 7945
7949: 7948
7957: 7956
7960: 7959
7971: 7970
7974: 7973
7982: 7981
7985: 7984
7996: 7995
7999: 7998
8007: 8006
8010: 8009
8021: 8020
8024: 8023
8032: 8031
8035: 8034
8046: 8045
8049: 8048
8057: 8056
8060: 8059
8071: 8070
8074: 8073
8082: 8081
8085: 8084
8096: 8095
8099: 8098
8107: 8106
8110: 8109
8121: 8120
8124: 8123
8132: 8131
8135: 8134
8146: 8145
8149: 8148
8157: 8156
8160: 8159
8171: 8170
8174: 8173
8182: 8181
8185: 8184
That is 573 times, i.e. 5.73% of the time.

Concatenate 2 or more gif files with ffmpeg android

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.

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.

'Not in gzip format" error when decompressing gzip inputstream in java

My code is attempting to decompress an input stream read from a gzipped file.
Here is the code snippet:
InputStream is = new GZIPInputStream(new ByteArrayInputStream(fcontents.getBytes()));
The file itself is fine:
$cat storefront3.gz | gunzip
180028796
80026920
180028796
180026921
8002790180
800001
1800002
1800007
800008
800009
The data read in prior to the top code snippet via FileInputStream sure looks like gzip stuff (note the original file was storefront3.tsv):
��[�Rstorefront3.tsvu���0k{)�?�/FBģ��Y'��Q�a���s~���}6���d�{2+���O���D�m~�O��
But get the following:
Caused by: java.io.IOException: Not in GZIP format
at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:141)
at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:56)
at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:65)
Here is a hex dump of the .gz file
23:40:44/storefronts:72 $od -cx storefront3.gz
0000000 037 213 \b \b 201 [ 347 R \0 003 s t o r e f
8b1f 0808 5b81 52e7 0300 7473 726f 6665
0000020 r o n t 3 . t s v \0 u 212 273 025 200 0
6f72 746e 2e33 7374 0076 8a75 15bb 3080
0000040 \f 003 k { 032 ) 200 ? 373 / F B ģ ** 302 131
030c 7b6b 291a 3f80 2ffb 4246 a3c4 cdc2
0000060 Y ' 261 200 Q 331 a 276 276 350 001 s ~ 222 262 175
2759 80b1 d951 be61 e8be 7301 927e dcb2
0000100 } 6 226 231 367 d 200 { 2 + 211 337 342 020 O 022
367d 9996 64f7 7b80 2b32 df89 10e2 f14f
0000120 022 343 035 246 D 211 m ~ 003 326 O 235 030 236 \0 \0
e312 a61d 8944 7e6d d603 9d4f 9e18 0000
0000140 \0
0000
UPDATE
I also tried to use FileInputStream. Following gives same error
GZIPInputStream strm = new GZIPInputStream(new FileInputStream(tmpFileName));
Since fcontents contains your gzipped data it should be a byte[] and not a String?
I recommend using IOUtils for reading the file into a byte array as reading it into a string will most likely corrupt your data.

Categories