Javacv: Q: How to add watermark to a video?

Created on 26 Apr 2018  ยท  32Comments  ยท  Source: bytedeco/javacv

Hi @saudet

Using javacv-platform-1.4.2-SNAPSHOT as of 26/04/2018 (dd/MM/yyyy).
Using MacOS X 10.13.4 (High Sierra)

Here is what I have written so far:

            FFmpegFrameGrabber frameGrabber = new FFmpegFrameGrabber(inputFile);
            frameGrabber.start();
            // Skips to the startTime (frame) [fast-forward]
            frameGrabber.setTimestamp(startTime);

            // The length in time of a video should always be more than zero
            if (frameGrabber.getLengthInTime() > 0) {
                // Input details
                int width = frameGrabber.getImageWidth();
                int height = frameGrabber.getImageHeight();
                int channels = frameGrabber.getAudioChannels();
                // Output with same Input details
                FFmpegFrameRecorder frameRecorder = new FFmpegFrameRecorder(outputFile, width, height, channels);
                // Round down the FrameRate as passing a floating point does not work
                int frameRate = (int)frameGrabber.getFrameRate();
                frameRecorder.setFrameRate(frameRate);
                // Matching input with output
                frameRecorder.setSampleRate(frameGrabber.getSampleRate());
                frameRecorder.setAudioBitrate(frameGrabber.getAudioBitrate());
                frameRecorder.setVideoBitrate(frameGrabber.getVideoBitrate());
                // Compress with YUV420P / H264 / AAC generating a MP4
                frameRecorder.setPixelFormat(avutil.AV_PIX_FMT_YUV420P);
                frameRecorder.setVideoCodec(avcodec.AV_CODEC_ID_H264);
                frameRecorder.setAudioCodec(avcodec.AV_CODEC_ID_AAC);

                // Using a Filter to add a WaterMark
                FFmpegFrameFilter frameFilter = new FFmpegFrameFilter(waterMark(), width, height);
                frameFilter.setPixelFormat(avutil.AV_PIX_FMT_YUV420P);
                frameFilter.start();

                // Does de read / write
                frameRecorder.start();
                while (true) {
                    Frame frame = frameGrabber.grab();
                    if (frame != null) {
                        Long timestamp = frameGrabber.getTimestamp();
                        // Adding the WaterMark
                        frameFilter.push(frame);
                        // Records
                        Frame filteredFrame;
                        while ((filteredFrame = frameFilter.pull()) != null) {
                            frameRecorder.record(filteredFrame, avutil.AV_PIX_FMT_YUV420P);
                        }
                        if (timestamp > endTime) {
                            break;
                        }
                    } else {
                        break;
                    }
                }

                // Stops the recorder
                frameRecorder.stop();
                frameRecorder.release();
                // Stops the filter
                frameFilter.stop();
                frameFilter.release();
                // Stops the reader (grabber)
                frameGrabber.stop();
                frameGrabber.release();

Here is what the waterMark() function returns:

movie=/Users/guikeller/dev/workspace/my-videoapp/target/classes/WaterMark.png [logo];[in][logo]overlay=0:0:format=yuv420 [out]

Here is the exception:

org.bytedeco.javacv.FrameFilter$Exception: av_buffersink_get_frame(): Error occurred: Resource temporarily unavailable
    at org.bytedeco.javacv.FFmpegFrameFilter.pullImage(FFmpegFrameFilter.java:574) ~[javacv-1.4.2-20180424.010031-7.jar:1.4.2-SNAPSHOT]
    at org.bytedeco.javacv.FFmpegFrameFilter.pull(FFmpegFrameFilter.java:553) ~[javacv-1.4.2-20180424.010031-7.jar:1.4.2-SNAPSHOT]
    at com.videoapp.editor.VideoCropper.cropVideo(VideoCropper.java:81) [classes/:?]
    at com.videoapp.editor.VideoCropper.lambda$processAsync$0(VideoCropper.java:122) [classes/:?]
    at com.videoapp.editor.VideoCropper$$Lambda$34/519310978.call(Unknown Source) [classes/:?]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_45]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_45]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_45]
    at java.lang.Thread.run(Thread.java:745) [?:1.8.0_45]

Can you please point out what I am doing wrong?

Let me know if you need any further info!
Thank you very much in advance for your help.

bug

Most helpful comment

Thanks for the hint @saudet - I finally got it to work!

Leaving it here for the rest of the community:

            // Without starting we cannot access any metadata / info
            FFmpegFrameGrabber frameGrabber = new FFmpegFrameGrabber(inputFile);
            frameGrabber.start();

            // Skips to the startTime (frame) [fast-forward]
            frameGrabber.setTimestamp(startTime);

            // The length in time of a video is always more than zero
            if (frameGrabber.getLengthInTime() > 0) {
                // Input details
                int width = frameGrabber.getImageWidth();
                int height = frameGrabber.getImageHeight();
                int channels = frameGrabber.getAudioChannels();

                // Output with same Input details
                FFmpegFrameRecorder frameRecorder = new FFmpegFrameRecorder(outputFile, width, height, channels);
                // Round down the FrameRate as passing a floating point does not work
                int frameRate = (int)frameGrabber.getFrameRate();
                frameRecorder.setFrameRate(frameRate);
                // Matching input with output
                frameRecorder.setSampleRate(frameGrabber.getSampleRate());
                frameRecorder.setAudioBitrate(frameGrabber.getAudioBitrate());
                frameRecorder.setVideoBitrate(frameGrabber.getVideoBitrate());
                // Compress with YUV420P / H264 / AAC generating a MP4
                frameRecorder.setPixelFormat(avutil.AV_PIX_FMT_YUV420P);
                frameRecorder.setVideoCodec(avcodec.AV_CODEC_ID_H264);
                frameRecorder.setAudioCodec(avcodec.AV_CODEC_ID_AAC);

                // Filter adds WaterMark
                String watermark = "movie=/path/to/MyWaterMark.png[watermark];[in][watermark]overlay=W-w-15:15:format=rgb[out]";
                FFmpegFrameFilter frameFilter = new FFmpegFrameFilter(watermark, width, height);
                frameFilter.setPixelFormat(avutil.AV_PIX_FMT_BGR24);
                frameFilter.start();

                // Does the read / write
                frameRecorder.start();
                while (true) {
                    Frame frame = frameGrabber.grab();
                    if (frame != null) {
                        Long timestamp = frameGrabber.getTimestamp();
                        // Adding the WaterMark
                        frameFilter.push(frame);
                        Frame filteredFrame = frameFilter.pull();
                        frameRecorder.record(filteredFrame);
                        if (timestamp > endTime) {
                            break;
                        }
                    } else {
                        break;
                    }
                }
                frameRecorder.setMetadata(frameGrabber.getMetadata());
                // Stops the recorder
                frameRecorder.stop();
                frameRecorder.release();
                // Stops the filter
                frameFilter.stop();
                frameFilter.release();
                // Stops the reader (grabber)
                frameGrabber.stop();
                frameGrabber.release();

Once again, thank you very much for the project and all support!
You can close the ticket now if you want.

Cheers! ๐Ÿ˜„ ๐Ÿ‘

PS: Can confirm that works on 1.4.2-SNAPSHOT (01/05/2018) [dd/MM/yyyy].
Also, tried on 1.4.1 just to see what would happen; had no luck / did not work.

All 32 comments

More logs - FFmpegLogCallback.set();

Below the output:

22:10:23.184 [pool-4-thread-1] INFO  com..videoapp.editor.VideoCropper - VideoCropper :: processAsync
22:10:23.190 [pool-5-thread-1] INFO  com..videoapp.editor.VideoCropper - VideoCropper :: cropVideo :: started at 2018-04-26T12:10:23.190Z
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/guikeller/Downloads/VideoAppTest/GOPR1288.MP4':

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/guikeller/Downloads/VideoAppTest/GOPR1288.MP4':

  Metadata:

  Metadata:

    major_brand     : 
    major_brand     : 
mp42
mp42




    minor_version   : 
    minor_version   : 
0
0




    compatible_brands: 
    compatible_brands: 
avc1isom
avc1isom




    creation_time   : 
    creation_time   : 
2018-04-18T11:22:05.000000Z
2018-04-18T11:22:05.000000Z




    firmware        : 
    firmware        : 
HD3.02.03.00
HD3.02.03.00




  Duration: 
  Duration: 
00:03:39.20
00:03:39.20
, start: 
, start: 
0.000000
0.000000
, bitrate: 
, bitrate: 
15159 kb/s
15159 kb/s




    Stream #0:0
    Stream #0:0
(eng)
(eng)
: Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 14986 kb/s
: Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 14986 kb/s
, 
, 
59.94 fps, 
59.94 fps, 
59.94 tbr, 
59.94 tbr, 
90k tbn, 
90k tbn, 
119.88 tbc
119.88 tbc
 (default)
 (default)




    Metadata:

    Metadata:

      creation_time   : 
      creation_time   : 
2018-04-18T11:22:05.000000Z
2018-04-18T11:22:05.000000Z




      handler_name    : 
      handler_name    : 




GoProa AVC
GoProa AVC




      encoder         : 
      encoder         : 
GoPro AVC encoder
GoPro AVC encoder




    Stream #0:1
    Stream #0:1
(eng)
(eng)
: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s
: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s
 (default)
 (default)




    Metadata:

    Metadata:

      creation_time   : 
      creation_time   : 
2018-04-18T11:22:05.000000Z
2018-04-18T11:22:05.000000Z




      handler_name    : 
      handler_name    : 




GoPro AAC
GoPro AAC




22:10:24.057 [pool-5-thread-1] INFO  com..videoapp.editor.VideoCropper - VideoCropper :: waterMark
22:10:24.057 [pool-5-thread-1] INFO  com..videoapp.editor.VideoCropper - VideoCropper :: waterMark :: command: movie=/Users/guikeller/dev/workspace/videoapp/target/classes/WaterMark.png[logo];[in][logo]overlay=0:0:format=yuv420[out]
[libx264 @ 0x7f82f724aa00] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2

[libx264 @ 0x7f82f724aa00] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2

[libx264 @ 0x7f82f724aa00] profile High, level 4.1

[libx264 @ 0x7f82f724aa00] profile High, level 4.1

[libx264 @ 0x7f82f724aa00] 264 - core 152 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=1 ref=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_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=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=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=abr mbtree=1 bitrate=14986 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00

[libx264 @ 0x7f82f724aa00] 264 - core 152 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=1 ref=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_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=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=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=abr mbtree=1 bitrate=14986 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00

Output #0, mp4, to '/Users/guikeller//Video_1.MP4':

Output #0, mp4, to '/Users/guikeller//Video_1.MP4':

  Metadata:

  Metadata:

    encoder         : 
    encoder         : 
Lavf58.12.100
Lavf58.12.100




    Stream #0:0
    Stream #0:0
: Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1280x720, q=2-31, 14986 kb/s
: Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1280x720, q=2-31, 14986 kb/s
, 
, 
15104 tbn
15104 tbn




    Stream #0:1
    Stream #0:1
: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s
: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s




22:10:24.500 [pool-5-thread-1] ERROR com..videoapp.editor.VideoCropper - VideoCropper :: cropVideo :: could not crop video: CroppingDetails(number=1, inputFile=/Users/guikeller/Downloads/VideoAppTest/GOPR1288.MP4, outputFile=/Users/guikeller//Video_1.MP4, startTime=8000000, endTime=51000000)
org.bytedeco.javacv.FrameFilter$Exception: av_buffersink_get_frame(): Error occurred: Resource temporarily unavailable
    at org.bytedeco.javacv.FFmpegFrameFilter.pullImage(FFmpegFrameFilter.java:574) ~[javacv-1.4.2-20180424.010031-7.jar:1.4.2-SNAPSHOT]
    at org.bytedeco.javacv.FFmpegFrameFilter.pull(FFmpegFrameFilter.java:553) ~[javacv-1.4.2-20180424.010031-7.jar:1.4.2-SNAPSHOT]
    at com..videoapp.editor.VideoCropper.cropVideo(VideoCropper.java:77) [classes/:?]
    at com..videoapp.editor.VideoCropper.lambda$processAsync$0(VideoCropper.java:117) [classes/:?]
    at com..videoapp.editor.VideoCropper$$Lambda$34/459132730.call(Unknown Source) [classes/:?]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_45]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_45]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_45]
    at java.lang.Thread.run(Thread.java:745) [?:1.8.0_45]
22:10:24.517 [pool-4-thread-1] INFO  com..videoapp.editor.VideoCropper - VideoCropper :: processAsync
22:10:24.517 [pool-7-thread-1] INFO  com..videoapp.editor.VideoCropper - VideoCropper :: cropVideo :: started at 2018-04-26T12:10:24.517Z
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/guikeller/Downloads/VideoAppTest/GOPR1288.MP4':

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/guikeller/Downloads/VideoAppTest/GOPR1288.MP4':

  Metadata:

  Metadata:

    major_brand     : 
    major_brand     : 
mp42
mp42




    minor_version   : 
    minor_version   : 
0
0




    compatible_brands: 
    compatible_brands: 
avc1isom
avc1isom




    creation_time   : 
    creation_time   : 
2018-04-18T11:22:05.000000Z
2018-04-18T11:22:05.000000Z




    firmware        : 
    firmware        : 
HD3.02.03.00
HD3.02.03.00




  Duration: 
  Duration: 
00:03:39.20
00:03:39.20
, start: 
, start: 
0.000000
0.000000
, bitrate: 
, bitrate: 
15159 kb/s
15159 kb/s




    Stream #0:0
    Stream #0:0
(eng)
(eng)
: Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 14986 kb/s
: Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 14986 kb/s
, 
, 
59.94 fps, 
59.94 fps, 
59.94 tbr, 
59.94 tbr, 
90k tbn, 
90k tbn, 
119.88 tbc
119.88 tbc
 (default)
 (default)




    Metadata:

    Metadata:

      creation_time   : 
      creation_time   : 
2018-04-18T11:22:05.000000Z
2018-04-18T11:22:05.000000Z




      handler_name    : 
      handler_name    : 




GoProa AVC
GoProa AVC




      encoder         : 
      encoder         : 
GoPro AVC encoder
GoPro AVC encoder




    Stream #0:1
    Stream #0:1
(eng)
(eng)
: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s
: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s
 (default)
 (default)




    Metadata:

    Metadata:

      creation_time   : 
      creation_time   : 
2018-04-18T11:22:05.000000Z
2018-04-18T11:22:05.000000Z




      handler_name    : 
      handler_name    : 




GoPro AAC
GoPro AAC




22:10:25.053 [pool-7-thread-1] INFO  com..videoapp.editor.VideoCropper - VideoCropper :: waterMark
22:10:25.053 [pool-7-thread-1] INFO  com..videoapp.editor.VideoCropper - VideoCropper :: waterMark :: command: movie=/Users/guikeller/dev/workspace/videoapp/target/classes/WaterMark.png[logo];[in][logo]overlay=0:0:format=yuv420[out]
[libx264 @ 0x7f82fd002800] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2

[libx264 @ 0x7f82fd002800] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2

[libx264 @ 0x7f82fd002800] profile High, level 4.1

[libx264 @ 0x7f82fd002800] profile High, level 4.1

[libx264 @ 0x7f82fd002800] 264 - core 152 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=1 ref=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_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=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=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=abr mbtree=1 bitrate=14986 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00

[libx264 @ 0x7f82fd002800] 264 - core 152 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=1 ref=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_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=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=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=abr mbtree=1 bitrate=14986 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00

Output #0, mp4, to '/Users/guikeller//Video_2.MP4':

Output #0, mp4, to '/Users/guikeller//Video_2.MP4':

  Metadata:

  Metadata:

    encoder         : 
    encoder         : 
Lavf58.12.100
Lavf58.12.100




    Stream #0:0
    Stream #0:0
: Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1280x720, q=2-31, 14986 kb/s
: Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1280x720, q=2-31, 14986 kb/s
, 
, 
15104 tbn
15104 tbn




    Stream #0:1
    Stream #0:1
: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s
: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s




22:10:25.060 [pool-7-thread-1] ERROR com..videoapp.editor.VideoCropper - VideoCropper :: cropVideo :: could not crop video: CroppingDetails(number=2, inputFile=/Users/guikeller/Downloads/VideoAppTest/GOPR1288.MP4, outputFile=/Users/guikeller//Video_2.MP4, startTime=88000000, endTime=132000000)
org.bytedeco.javacv.FrameFilter$Exception: av_buffersink_get_frame(): Error occurred: Resource temporarily unavailable
    at org.bytedeco.javacv.FFmpegFrameFilter.pullImage(FFmpegFrameFilter.java:574) ~[javacv-1.4.2-20180424.010031-7.jar:1.4.2-SNAPSHOT]
    at org.bytedeco.javacv.FFmpegFrameFilter.pull(FFmpegFrameFilter.java:553) ~[javacv-1.4.2-20180424.010031-7.jar:1.4.2-SNAPSHOT]
    at com..videoapp.editor.VideoCropper.cropVideo(VideoCropper.java:77) [classes/:?]
    at com..videoapp.editor.VideoCropper.lambda$processAsync$0(VideoCropper.java:117) [classes/:?]
    at com..videoapp.editor.VideoCropper$$Lambda$34/459132730.call(Unknown Source) [classes/:?]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_45]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_45]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_45]
    at java.lang.Thread.run(Thread.java:745) [?:1.8.0_45]

Does it happen with JavaCV 1.4.1?

Hi @saudet ,

Can confirm that also happens on JavaCV-1.4.1

22:56:45.076 [pool-7-thread-1] INFO  com..videoapp.editor.VideoCropper - VideoCropper :: cropVideo :: started at 2018-04-26T12:56:45.076Z
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/guikeller/Downloads/VideoAppTest/GOPR1288.MP4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: avc1isom
    creation_time   : 2018-04-18T11:22:05.000000Z
    firmware        : HD3.02.03.00
  Duration: 00:03:39.20, start: 0.000000, bitrate: 15159 kb/s
    Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 14986 kb/s, 59.94 fps, 59.94 tbr, 90k tbn, 119.88 tbc (default)
    Metadata:
      creation_time   : 2018-04-18T11:22:05.000000Z
      handler_name    :  GoProa AVC
      encoder         : GoPro AVC encoder
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      creation_time   : 2018-04-18T11:22:05.000000Z
      handler_name    :  GoPro AAC
22:56:45.622 [pool-7-thread-1] INFO  com..videoapp.editor.VideoCropper - VideoCropper :: waterMark
22:56:45.622 [pool-7-thread-1] INFO  com..videoapp.editor.VideoCropper - VideoCropper :: waterMark :: command: movie=/Users/guikeller/dev/workspace/videoapp/target/classes/WaterMark.png[logo];[in][logo]overlay=0:0:format=yuv420[out]
[libx264 @ 0x7fb2b725e400] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x7fb2b725e400] profile High, level 4.1
[libx264 @ 0x7fb2b725e400] 264 - core 152 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=1 ref=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_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=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=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=abr mbtree=1 bitrate=14986 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to '/Users/guikeller/VideoApp/Video_2.MP4':
  Metadata:
    encoder         : Lavf57.83.100
    Stream #0:0: Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1280x720, q=2-31, 14986 kb/s, 15104 tbn
    Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s
22:56:45.630 [pool-7-thread-1] ERROR com..videoapp.editor.VideoCropper - VideoCropper :: cropVideo :: could not crop video: CroppingDetails(number=2, inputFile=/Users/guikeller/Downloads/VideoAppTest/GOPR1288.MP4, outputFile=/Users/guikeller/VideoApp/Video_2.MP4, startTime=88000000, endTime=132000000)
org.bytedeco.javacv.FrameFilter$Exception: av_buffersink_get_frame(): Error occurred: Resource temporarily unavailable
    at org.bytedeco.javacv.FFmpegFrameFilter.pull(FFmpegFrameFilter.java:346) ~[javacv-1.4.1.jar:1.4.1]
    at com..videoapp.editor.VideoCropper.cropVideo(VideoCropper.java:77) [classes/:?]
    at com..videoapp.editor.VideoCropper.lambda$processAsync$1(VideoCropper.java:117) [classes/:?]
    at com..videoapp.editor.VideoCropper$$Lambda$34/647370872.call(Unknown Source) [classes/:?]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_45]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_45]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_45]
    at java.lang.Thread.run(Thread.java:745) [?:1.8.0_45]

Please let me know if you have any other questions or need any further info.
Thank you very much in advance for your help. Cheers!

Ah, I see what's going on. The value of EAGAIN is different on Mac...

Hi @saudet ,

Is this issue specific to Mac? Or, does it also happens on Linux / Win?
If you set up a Paypal for monetary donations I would be willing to contribute.

Thanks once again! ๐Ÿ˜„

Yes, it's pretty much an issue specific to Mac, but I've fixed it with the latest commit.
Thanks for reporting and please give it try with the snapshots: http://bytedeco.org/builds/

As for money, that is very generous of you, but what we need more is time. If you're not able to contribute time yourself, please consider hiring a freelancer from https://www.upwork.com/ or some other place to work on features you need from JavaCV. That would be awesome!

Hi @saudet

Latest javacv-platform / 1.4.2-SNAPSHOT [29/04/2018] is reporting:

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: Could not initialize class org.bytedeco.javacpp.avutil
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:348)
    at org.bytedeco.javacpp.Loader.load(Loader.java:938)
    at org.bytedeco.javacpp.Loader.load(Loader.java:879)
    at org.bytedeco.javacpp.avformat$Read_packet_Pointer_BytePointer_int.<clinit>(avformat.java:632)
    at org.bytedeco.javacv.FFmpegFrameGrabber.<clinit>(FFmpegFrameGrabber.java:296)

Thanks for your work! ๐Ÿ‘

That just means files like jniavutil.dylib are missing from your class path.

Hi @saudet,

Tried to remove the whole project deps from my local m2 repo:
$rm -rf ~/.m2/repository/org/bytedeco

Resolved it back again, but no luck, same exception / error occurs.
Should not it all be automatically resolved and added to the classpath?

Cheers!

Yeah, what does mvn dependency:tree returns?

Follows below what it has been resolved:

[INFO] com.myproject:videoapp:jar:0.0.2b
[INFO] +- com.jgoodies:jgoodies-looks:jar:2.7.0:compile
[INFO] |  \- com.jgoodies:jgoodies-common:jar:1.8.1:compile
[INFO] +- com.intellij:forms_rt:jar:7.0.3:compile
[INFO] |  +- asm:asm-commons:jar:3.0:compile
[INFO] |  |  \- asm:asm-tree:jar:3.0:compile
[INFO] |  |     \- asm:asm:jar:3.0:compile
[INFO] |  +- com.jgoodies:forms:jar:1.1-preview:compile
[INFO] |  \- jdom:jdom:jar:1.0:compile
[INFO] +- org.projectlombok:lombok:jar:1.16.18:compile
[INFO] +- org.bytedeco:javacv-platform:jar:1.4.2-SNAPSHOT:compile
[INFO] |  +- org.bytedeco:javacv:jar:1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco:javacpp:jar:1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:opencv:jar:3.4.1-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:ffmpeg:jar:4.0-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:flycapture:jar:2.11.3.121-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:libdc1394:jar:2.2.5-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:libfreenect:jar:0.5.3-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:libfreenect2:jar:0.2.0-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:librealsense:jar:1.12.1-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:videoinput:jar:0.200-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:artoolkitplus:jar:2.3.1-1.4.2-SNAPSHOT:compile
[INFO] |  |  \- org.bytedeco.javacpp-presets:flandmark:jar:1.07-1.4.2-SNAPSHOT:compile
[INFO] |  +- org.bytedeco.javacpp-presets:opencv-platform:jar:3.4.1-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:opencv:jar:android-arm:3.4.1-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:opencv:jar:android-arm64:3.4.1-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:opencv:jar:android-x86:3.4.1-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:opencv:jar:android-x86_64:3.4.1-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:opencv:jar:ios-arm64:3.4.1-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:opencv:jar:ios-x86_64:3.4.1-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:opencv:jar:linux-x86:3.4.1-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:opencv:jar:linux-x86_64:3.4.1-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:opencv:jar:linux-armhf:3.4.1-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:opencv:jar:linux-ppc64le:3.4.1-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:opencv:jar:macosx-x86_64:3.4.1-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:opencv:jar:windows-x86:3.4.1-1.4.2-SNAPSHOT:compile
[INFO] |  |  \- org.bytedeco.javacpp-presets:opencv:jar:windows-x86_64:3.4.1-1.4.2-SNAPSHOT:compile
[INFO] |  +- org.bytedeco.javacpp-presets:ffmpeg-platform:jar:4.0-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:ffmpeg:jar:android-arm:4.0-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:ffmpeg:jar:android-arm64:4.0-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:ffmpeg:jar:android-x86:4.0-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:ffmpeg:jar:android-x86_64:4.0-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:ffmpeg:jar:linux-x86:4.0-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:ffmpeg:jar:linux-x86_64:4.0-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:ffmpeg:jar:linux-armhf:4.0-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:ffmpeg:jar:linux-ppc64le:4.0-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:ffmpeg:jar:macosx-x86_64:4.0-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:ffmpeg:jar:windows-x86:4.0-1.4.2-SNAPSHOT:compile
[INFO] |  |  \- org.bytedeco.javacpp-presets:ffmpeg:jar:windows-x86_64:4.0-1.4.2-SNAPSHOT:compile
[INFO] |  +- org.bytedeco.javacpp-presets:flycapture-platform:jar:2.11.3.121-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:flycapture:jar:linux-x86:2.11.3.121-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:flycapture:jar:linux-x86_64:2.11.3.121-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:flycapture:jar:linux-armhf:2.11.3.121-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:flycapture:jar:windows-x86:2.11.3.121-1.4.2-SNAPSHOT:compile
[INFO] |  |  \- org.bytedeco.javacpp-presets:flycapture:jar:windows-x86_64:2.11.3.121-1.4.2-SNAPSHOT:compile
[INFO] |  +- org.bytedeco.javacpp-presets:libdc1394-platform:jar:2.2.5-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:libdc1394:jar:linux-x86:2.2.5-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:libdc1394:jar:linux-x86_64:2.2.5-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:libdc1394:jar:linux-armhf:2.2.5-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:libdc1394:jar:linux-ppc64le:2.2.5-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:libdc1394:jar:macosx-x86_64:2.2.5-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:libdc1394:jar:windows-x86:2.2.5-1.4.2-SNAPSHOT:compile
[INFO] |  |  \- org.bytedeco.javacpp-presets:libdc1394:jar:windows-x86_64:2.2.5-1.4.2-SNAPSHOT:compile
[INFO] |  +- org.bytedeco.javacpp-presets:libfreenect-platform:jar:0.5.3-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:libfreenect:jar:linux-x86:0.5.3-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:libfreenect:jar:linux-x86_64:0.5.3-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:libfreenect:jar:linux-armhf:0.5.3-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:libfreenect:jar:linux-ppc64le:0.5.3-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:libfreenect:jar:macosx-x86_64:0.5.3-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:libfreenect:jar:windows-x86:0.5.3-1.4.2-SNAPSHOT:compile
[INFO] |  |  \- org.bytedeco.javacpp-presets:libfreenect:jar:windows-x86_64:0.5.3-1.4.2-SNAPSHOT:compile
[INFO] |  +- org.bytedeco.javacpp-presets:libfreenect2-platform:jar:0.2.0-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:libfreenect2:jar:linux-x86:0.2.0-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:libfreenect2:jar:linux-x86_64:0.2.0-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:libfreenect2:jar:macosx-x86_64:0.2.0-1.4.2-SNAPSHOT:compile
[INFO] |  |  \- org.bytedeco.javacpp-presets:libfreenect2:jar:windows-x86_64:0.2.0-1.4.2-SNAPSHOT:compile
[INFO] |  +- org.bytedeco.javacpp-presets:librealsense-platform:jar:1.12.1-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:librealsense:jar:linux-x86:1.12.1-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:librealsense:jar:linux-x86_64:1.12.1-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:librealsense:jar:macosx-x86_64:1.12.1-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:librealsense:jar:windows-x86:1.12.1-1.4.2-SNAPSHOT:compile
[INFO] |  |  \- org.bytedeco.javacpp-presets:librealsense:jar:windows-x86_64:1.12.1-1.4.2-SNAPSHOT:compile
[INFO] |  +- org.bytedeco.javacpp-presets:videoinput-platform:jar:0.200-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:videoinput:jar:windows-x86:0.200-1.4.2-SNAPSHOT:compile
[INFO] |  |  \- org.bytedeco.javacpp-presets:videoinput:jar:windows-x86_64:0.200-1.4.2-SNAPSHOT:compile
[INFO] |  +- org.bytedeco.javacpp-presets:artoolkitplus-platform:jar:2.3.1-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:artoolkitplus:jar:android-arm:2.3.1-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:artoolkitplus:jar:android-arm64:2.3.1-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:artoolkitplus:jar:android-x86:2.3.1-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:artoolkitplus:jar:android-x86_64:2.3.1-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:artoolkitplus:jar:linux-x86:2.3.1-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:artoolkitplus:jar:linux-x86_64:2.3.1-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:artoolkitplus:jar:linux-armhf:2.3.1-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:artoolkitplus:jar:linux-ppc64le:2.3.1-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:artoolkitplus:jar:macosx-x86_64:2.3.1-1.4.2-SNAPSHOT:compile
[INFO] |  |  +- org.bytedeco.javacpp-presets:artoolkitplus:jar:windows-x86:2.3.1-1.4.2-SNAPSHOT:compile
[INFO] |  |  \- org.bytedeco.javacpp-presets:artoolkitplus:jar:windows-x86_64:2.3.1-1.4.2-SNAPSHOT:compile
[INFO] |  \- org.bytedeco.javacpp-presets:flandmark-platform:jar:1.07-1.4.2-SNAPSHOT:compile
[INFO] |     +- org.bytedeco.javacpp-presets:flandmark:jar:android-arm:1.07-1.4.2-SNAPSHOT:compile
[INFO] |     +- org.bytedeco.javacpp-presets:flandmark:jar:android-arm64:1.07-1.4.2-SNAPSHOT:compile
[INFO] |     +- org.bytedeco.javacpp-presets:flandmark:jar:android-x86:1.07-1.4.2-SNAPSHOT:compile
[INFO] |     +- org.bytedeco.javacpp-presets:flandmark:jar:android-x86_64:1.07-1.4.2-SNAPSHOT:compile
[INFO] |     +- org.bytedeco.javacpp-presets:flandmark:jar:linux-x86:1.07-1.4.2-SNAPSHOT:compile
[INFO] |     +- org.bytedeco.javacpp-presets:flandmark:jar:linux-x86_64:1.07-1.4.2-SNAPSHOT:compile
[INFO] |     +- org.bytedeco.javacpp-presets:flandmark:jar:linux-armhf:1.07-1.4.2-SNAPSHOT:compile
[INFO] |     +- org.bytedeco.javacpp-presets:flandmark:jar:linux-ppc64le:1.07-1.4.2-SNAPSHOT:compile
[INFO] |     +- org.bytedeco.javacpp-presets:flandmark:jar:macosx-x86_64:1.07-1.4.2-SNAPSHOT:compile
[INFO] |     +- org.bytedeco.javacpp-presets:flandmark:jar:windows-x86:1.07-1.4.2-SNAPSHOT:compile
[INFO] |     \- org.bytedeco.javacpp-presets:flandmark:jar:windows-x86_64:1.07-1.4.2-SNAPSHOT:compile
[INFO] +- com.google.code.gson:gson:jar:2.8.2:compile
[INFO] +- org.apache.logging.log4j:log4j-core:jar:2.10.0:compile
[INFO] |  \- org.apache.logging.log4j:log4j-api:jar:2.10.0:compile
[INFO] +- junit:junit:jar:4.12:test
[INFO] |  \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- org.mockito:mockito-all:jar:1.10.19:test
[INFO] +- org.powermock:powermock-api-mockito:jar:1.7.3:test
[INFO] |  +- org.powermock:powermock-api-mockito-common:jar:1.7.3:test
[INFO] |  |  \- org.powermock:powermock-api-support:jar:1.7.3:test
[INFO] |  |     +- org.powermock:powermock-reflect:jar:1.7.3:test
[INFO] |  |     \- org.powermock:powermock-core:jar:1.7.3:test
[INFO] |  |        \- org.javassist:javassist:jar:3.21.0-GA:test
[INFO] |  \- org.mockito:mockito-core:jar:1.10.19:test
[INFO] |     \- org.objenesis:objenesis:jar:2.1:test
[INFO] \- com.badlogicgames.packr:packr:jar:2.0-SNAPSHOT:test
[INFO]    +- org.zeroturnaround:zt-zip:jar:1.7:test
[INFO]    |  +- commons-io:commons-io:jar:1.4:test
[INFO]    |  \- org.slf4j:slf4j-api:jar:1.6.6:test
[INFO]    +- com.eclipsesource.minimal-json:minimal-json:jar:0.9.1:test
[INFO]    \- com.lexicalscope.jewelcli:jewelcli:jar:0.8.9:test

Thanks! ๐Ÿ‘

Seems to be alright. Does removing ~/.javacpp/cache changes anything?

I have tried the following:

rm -rf ~/.m2/repository/org/bytedeco
rm -rf ~/.javacpp

Resolved dependencies with Maven, then run project; same exception though:

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: Could not initialize class org.bytedeco.javacpp.avutil
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:348)
    at org.bytedeco.javacpp.Loader.load(Loader.java:938)
    at org.bytedeco.javacpp.Loader.load(Loader.java:879)
    at org.bytedeco.javacpp.avformat$Read_packet_Pointer_BytePointer_int.<clinit>(avformat.java:632)
    at org.bytedeco.javacv.FFmpegFrameGrabber.<clinit>(FFmpegFrameGrabber.java:296)

Let me know if you need any further info.
Thank you very much in advance.

I know some codecs are flaky on Mac. Could you try to reproduce this crash with only FFmpegFrameRecorder? It'll be easier to pinpoint what is the issue exactly.

Ah, no, that looks like broken snapshots: https://travis-ci.org/bytedeco/javacv/builds/372956434

Should be fixed by tomorrow...

Great! Thanks

On Mon, 30 Apr. 2018, 21:31 Samuel Audet, notifications@github.com wrote:

Ah, no, that looks like broken snapshots:
https://travis-ci.org/bytedeco/javacv/builds/372956434

Should be fixed by tomorrow...

โ€”
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/bytedeco/javacv/issues/974#issuecomment-385372700,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AH1TPhyhrpRGwlY8hNkgEsq9NwtujgGzks5ttvYRgaJpZM4Tk5jP
.

Hello @saudet

Tried again, unfortunately still no luck:

15:17:30.499 [pool-4-thread-1] INFO  com.my-videoapp.videoapp.editor.VideoCropper - VideoCropper :: processAsync
15:17:30.510 [pool-5-thread-1] INFO  com.my-videoapp.videoapp.editor.VideoCropper - VideoCropper :: cropVideo :: started at 2018-05-01T05:17:30.510Z
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/guikeller/Downloads/VideoAppTest/GOPR1288.MP4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: avc1isom
    creation_time   : 2018-04-18T11:22:05.000000Z
    firmware        : HD3.02.03.00
  Duration: 00:03:39.20, start: 0.000000, bitrate: 15159 kb/s
    Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 14986 kb/s, 59.94 fps, 59.94 tbr, 90k tbn, 119.88 tbc (default)
    Metadata:
      creation_time   : 2018-04-18T11:22:05.000000Z
      handler_name    :  GoProa AVC
      encoder         : GoPro AVC encoder
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      creation_time   : 2018-04-18T11:22:05.000000Z
      handler_name    :  GoPro AAC
15:17:31.527 [pool-5-thread-1] INFO  com.my-videoapp.videoapp.editor.VideoCropper - VideoCropper :: waterMark
15:17:31.527 [pool-5-thread-1] INFO  com.my-videoapp.videoapp.editor.VideoCropper - VideoCropper :: waterMark :: command: movie=/Users/guikeller/dev/workspace/my-videoapp/target/classes/WaterMark.png[logo];[in][logo]overlay=0:0:format=yuv420[out]
[libx264 @ 0x7fc0a74ab000] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x7fc0a74ab000] profile High, level 4.1
[libx264 @ 0x7fc0a74ab000] 264 - core 152 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=1 ref=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_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=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=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=abr mbtree=1 bitrate=14986 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to '/Users/guikeller/my-videoapp/Wave_1.MP4':
  Metadata:
    encoder         : Lavf58.12.100
    Stream #0:0: Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1280x720, q=2-31, 14986 kb/s, 15104 tbn
    Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s
[in @ 0x7fc0ab099780] Changing frame properties on the fly is not supported by all filters.
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x000000012de8e606, pid=40780, tid=34843
#
# JRE version: Java(TM) SE Runtime Environment (8.0_45-b14) (build 1.8.0_45-b14)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.45-b02 mixed mode bsd-amd64 compressed oops)
# Problematic frame:
# C  [libavfilter.7.dylib+0x117606]  avfilter_transform+0x862c6
#
# 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/guikeller/dev/workspace/my-videoapp/hs_err_pid40780.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

If I remove the FrameFilter that tries to add the WaterMark it all goes well.
Please let me know if you need any further information.

Cheers!

Like I said Mac support for FFmpeg is flaky. Does this happen only on Mac?
You'll need to figure out what works and what doesn't on Mac, and report
any such Mac-only issues upstream...

Okay, thanks for the support and help; much appreciated.

BTW, I think it has something to do with threading support being weird.
Disabling multithreaded processing might help.

Worth a shot, how do I set the number of threads though?

Tried the following:

Parallel.setNumThreads(1);
frameRecorder.setOption("threads","1");

It produced:

options: cabac=1 ref=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_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=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=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=abr mbtree=1 bitrate=14986 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00

I do know that is not a filter (-vf) thing.
Thanks a lot! ๐Ÿ‘

I don't think there is a global parameter like that. I think we'd have to
do it for each module that supports that kind of option.

Managed to get it through!

                frameRecorder.setOption("threads","1");
                frameRecorder.setVideoOption("threads", "1");
                frameRecorder.setAudioOption("threads", "1");

Still no luck though.

[libx264 @ 0x7fde31c83000] 264 - core 152 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=1 ref=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_pskip=1 chroma_qp_offset=-2 threads=1 lookahead_threads=1 sliced_threads=0 nr=0 decimate=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=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=abr mbtree=1 bitrate=14986 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00

Output #0, mp4, to '/Users/guikeller/MyVideoApp/Video_1.MP4':

Output #0, mp4, to '/Users/guikeller/MyVideoApp/Video_1.MP4':

  Metadata:

  Metadata:

    encoder         : 
    encoder         : 
Lavf58.12.100
Lavf58.12.100




    Stream #0:0
    Stream #0:0
: Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1280x720, q=2-31, 14986 kb/s
: Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1280x720, q=2-31, 14986 kb/s
, 
, 
15104 tbn
15104 tbn




    Stream #0:1
    Stream #0:1
: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s
: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s




[in @ 0x7fde35951c40] Changing frame properties on the fly is not supported by all filters.

[in @ 0x7fde35951c40] Changing frame properties on the fly is not supported by all filters.

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x0000000132414606, pid=41012, tid=57455
#
# JRE version: Java(TM) SE Runtime Environment (8.0_45-b14) (build 1.8.0_45-b14)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.45-b02 mixed mode bsd-amd64 compressed oops)
# Problematic frame:
# C  [libavfilter.7.dylib+0x117606]  avfilter_transform+0x862c6
#
# 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/guikeller/dev/workspace/mt-videoapp/hs_err_pid41012.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

Once again thanks for your input and help.

That doesn't change the filter...

Ah, here's the problem:

[in @ 0x7fde35951c40] Changing frame properties on the fly is not supported by all filters.
[in @ 0x7fde35951c40] Changing frame properties on the fly is not supported by all filters.

You're not setting the pixel format on the input filter. That's not supported by FFmpeg.

Here is the command passed through to the -vf (input filter) :

The pixel format is yuv420, or at least it should have been set to it in the filter.
movie=/Users/guikeller/dev/workspace/videoapp/target/classes/WaterMark.png[logo];[in][logo]overlay=0:0:format=yuv420[out]

FFmpegFrameGrabber converts to BGR24 by default. You're not calling either
getPixelFormat() or setPixelFormat().

I must say I am a bit lost now;

Here is the code where I use the grabber / recorder / filter.
Could you please point out what I have been missing?

            FFmpegFrameGrabber frameGrabber = new FFmpegFrameGrabber(inputFile);
            frameGrabber.start();
            // Skips to the startTime (frame) [fast-forward]
            frameGrabber.setTimestamp(startTime);

            // The length in time of a video should always be more than zero
            if (frameGrabber.getLengthInTime() > 0) {
                // Input details
                int width = frameGrabber.getImageWidth();
                int height = frameGrabber.getImageHeight();
                int channels = frameGrabber.getAudioChannels();
                // Output with same Input details
                FFmpegFrameRecorder frameRecorder = new FFmpegFrameRecorder(outputFile, width, height, channels);
                // Round down the FrameRate as passing a floating point does not work
                int frameRate = (int)frameGrabber.getFrameRate();
                frameRecorder.setFrameRate(frameRate);
                // Matching input with output
                frameRecorder.setSampleRate(frameGrabber.getSampleRate());
                frameRecorder.setAudioBitrate(frameGrabber.getAudioBitrate());
                frameRecorder.setVideoBitrate(frameGrabber.getVideoBitrate());
                // Compress with YUV420P / H264 / AAC generating a MP4
                frameRecorder.setPixelFormat(avutil.AV_PIX_FMT_YUV420P);
                frameRecorder.setVideoCodec(avcodec.AV_CODEC_ID_H264);
                frameRecorder.setAudioCodec(avcodec.AV_CODEC_ID_AAC);

                // Using a Filter to add a WaterMark
                FFmpegFrameFilter frameFilter = new FFmpegFrameFilter(waterMark(), width, height);
                frameFilter.setPixelFormat(avutil.AV_PIX_FMT_YUV420P);
                frameFilter.start();

                // Does de read / write
                frameRecorder.start();
                while (true) {
                    Frame frame = frameGrabber.grab();
                    if (frame != null) {
                        Long timestamp = frameGrabber.getTimestamp();
                        // Adding the WaterMark
                        frameFilter.push(frame);
                        // Records
                        Frame filteredFrame;
                        while ((filteredFrame = frameFilter.pull()) != null) {
                            frameRecorder.record(filteredFrame, avutil.AV_PIX_FMT_YUV420P);
                        }
                        if (timestamp > endTime) {
                            break;
                        }
                    } else {
                        break;
                    }
                }

                // Stops the recorder
                frameRecorder.stop();
                frameRecorder.release();
                // Stops the filter
                frameFilter.stop();
                frameFilter.release();
                // Stops the reader (grabber)
                frameGrabber.stop();
                frameGrabber.release();

Thanks! ๐Ÿ˜ƒ

Thanks for the hint @saudet - I finally got it to work!

Leaving it here for the rest of the community:

            // Without starting we cannot access any metadata / info
            FFmpegFrameGrabber frameGrabber = new FFmpegFrameGrabber(inputFile);
            frameGrabber.start();

            // Skips to the startTime (frame) [fast-forward]
            frameGrabber.setTimestamp(startTime);

            // The length in time of a video is always more than zero
            if (frameGrabber.getLengthInTime() > 0) {
                // Input details
                int width = frameGrabber.getImageWidth();
                int height = frameGrabber.getImageHeight();
                int channels = frameGrabber.getAudioChannels();

                // Output with same Input details
                FFmpegFrameRecorder frameRecorder = new FFmpegFrameRecorder(outputFile, width, height, channels);
                // Round down the FrameRate as passing a floating point does not work
                int frameRate = (int)frameGrabber.getFrameRate();
                frameRecorder.setFrameRate(frameRate);
                // Matching input with output
                frameRecorder.setSampleRate(frameGrabber.getSampleRate());
                frameRecorder.setAudioBitrate(frameGrabber.getAudioBitrate());
                frameRecorder.setVideoBitrate(frameGrabber.getVideoBitrate());
                // Compress with YUV420P / H264 / AAC generating a MP4
                frameRecorder.setPixelFormat(avutil.AV_PIX_FMT_YUV420P);
                frameRecorder.setVideoCodec(avcodec.AV_CODEC_ID_H264);
                frameRecorder.setAudioCodec(avcodec.AV_CODEC_ID_AAC);

                // Filter adds WaterMark
                String watermark = "movie=/path/to/MyWaterMark.png[watermark];[in][watermark]overlay=W-w-15:15:format=rgb[out]";
                FFmpegFrameFilter frameFilter = new FFmpegFrameFilter(watermark, width, height);
                frameFilter.setPixelFormat(avutil.AV_PIX_FMT_BGR24);
                frameFilter.start();

                // Does the read / write
                frameRecorder.start();
                while (true) {
                    Frame frame = frameGrabber.grab();
                    if (frame != null) {
                        Long timestamp = frameGrabber.getTimestamp();
                        // Adding the WaterMark
                        frameFilter.push(frame);
                        Frame filteredFrame = frameFilter.pull();
                        frameRecorder.record(filteredFrame);
                        if (timestamp > endTime) {
                            break;
                        }
                    } else {
                        break;
                    }
                }
                frameRecorder.setMetadata(frameGrabber.getMetadata());
                // Stops the recorder
                frameRecorder.stop();
                frameRecorder.release();
                // Stops the filter
                frameFilter.stop();
                frameFilter.release();
                // Stops the reader (grabber)
                frameGrabber.stop();
                frameGrabber.release();

Once again, thank you very much for the project and all support!
You can close the ticket now if you want.

Cheers! ๐Ÿ˜„ ๐Ÿ‘

PS: Can confirm that works on 1.4.2-SNAPSHOT (01/05/2018) [dd/MM/yyyy].
Also, tried on 1.4.1 just to see what would happen; had no luck / did not work.

If you could wrap this up in a file and send a pull request to add it to the samples directory that would be awesome!

Sure thing! I will do that over the next week or the week after though ๐Ÿ˜„

The fix is now included in version 1.4.2. Thanks again for reporting!

BTW, I'm still waiting for your pull request to add the sample code! Would be great to have that in.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

UpAndDownAgain picture UpAndDownAgain  ยท  3Comments

The-Crocop picture The-Crocop  ยท  5Comments

chenhl05 picture chenhl05  ยท  4Comments

RaGreen picture RaGreen  ยท  4Comments

SenudaJayalath picture SenudaJayalath  ยท  3Comments