<div dir="ltr">Hello,<div><br></div><div>I am attempting to write a java application that uses FFmpeg to record the screen of a Macbook. </div><div><br></div><div>If this is the incorrect place to be asking this question, are there any examples of accomplishing the screen recording with libav? </div><div><br></div><div>My approach was<span style="color:rgb(36,41,47)"><font face="arial, sans-serif"> to use a while loop to continuously capture the frames. </font></span></div><div><span style="color:rgb(36,41,47)"><font face="arial, sans-serif"><br></font></span></div><div><span style="color:rgb(36,41,47)"><font face="arial, sans-serif">However, only one frame gets captured and the recording stops. Do you have any ideas on what is going wrong?</font></span></div><div><span style="color:rgb(36,41,47)"><font face="arial, sans-serif"><br></font></span></div><div><span style="color:rgb(36,41,47);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji"">I am getting the following warnings but could not figure out how to resolve them:</span><br style="box-sizing:border-box;color:rgb(36,41,47);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji";font-size:14px"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><code style="box-sizing:border-box;font-family:ui-monospace,SFMono-Regular,"SF Mono",Menlo,Consolas,"Liberation Mono",monospace;font-size:11.9px;padding:0.2em 0.4em;margin:0px;border-radius:6px;color:rgb(36,41,47)">[AVFoundation indev @ 0x12de64c00] Configuration of video device failed, falling back to default.<br></code><code style="box-sizing:border-box;font-family:ui-monospace,SFMono-Regular,"SF Mono",Menlo,Consolas,"Liberation Mono",monospace;font-size:11.9px;padding:0.2em 0.4em;margin:0px;border-radius:6px;color:rgb(36,41,47)">[avfoundation @ 0x12de64980] Stream #0: not enough frames to estimate rate; consider increasing probesize<br></code><code style="box-sizing:border-box;font-family:ui-monospace,SFMono-Regular,"SF Mono",Menlo,Consolas,"Liberation Mono",monospace;font-size:11.9px;padding:0.2em 0.4em;margin:0px;border-radius:6px;color:rgb(36,41,47)">[aac @ 0x103506660] 1 frames left in the queue on closing</code></blockquote></div><div><span style="color:rgb(36,41,47)"><font face="arial, sans-serif"><br></font></span></div><div><span style="color:rgb(36,41,47)"><font face="arial, sans-serif">Here is the code I have: </font></span></div><div><span style="color:rgb(36,41,47)"><font face="arial, sans-serif"><br></font></span></div><div><pre style="color:rgb(8,8,8);font-family:"JetBrains Mono",monospace;font-size:9.8pt"><span style="color:rgb(0,51,179)">import </span><span style="color:rgb(0,0,0)">org.bytedeco.ffmpeg.global.avutil</span>;<br><span style="color:rgb(0,51,179)">import </span><span style="color:rgb(0,0,0)">org.bytedeco.javacpp.Loader</span>;<br><span style="color:rgb(0,51,179)">import </span><span style="color:rgb(0,0,0)">org.bytedeco.javacv.Frame</span>;<br><span style="color:rgb(0,51,179)">import </span><span style="color:rgb(0,0,0)">org.bytedeco.javacv.</span>*;<br><span style="color:rgb(0,51,179)">import </span><span style="color:rgb(0,0,0)">org.bytedeco.opencv.opencv_java</span>;<br><br><span style="color:rgb(0,51,179)">import </span><span style="color:rgb(0,0,0)">java.awt.</span>*;<br><span style="color:rgb(0,51,179)">import </span><span style="color:rgb(0,0,0)">java.io.IOException</span>;<br><br><span style="color:rgb(0,51,179)">public class </span><span style="color:rgb(0,0,0)">ScreenCaptureTrial </span>{<br>    <span style="color:rgb(0,51,179)">private static final </span><span style="color:rgb(0,0,0)">String </span><span style="color:rgb(135,16,148);font-style:italic">DEVICE_INDEX </span>= <span style="color:rgb(6,125,23)">"1:0"</span>; <span style="color:rgb(140,140,140);font-style:italic">//1 for mac's screen<br></span><span style="color:rgb(140,140,140);font-style:italic">    </span><span style="color:rgb(0,51,179)">private static final int </span><span style="color:rgb(135,16,148);font-style:italic">FRAME_RATE </span>= <span style="color:rgb(23,80,235)">60</span>;<br><br>    <span style="color:rgb(0,51,179)">public static void </span><span style="color:rgb(0,98,122)">main</span>(<span style="color:rgb(0,0,0)">String</span>[] args) <span style="color:rgb(0,51,179)">throws </span><span style="color:rgb(0,0,0)">IOException </span>{<br><br>        <span style="color:rgb(0,0,0)">Loader</span>.<span style="font-style:italic">load</span>(<span style="color:rgb(0,0,0)">opencv_java</span>.<span style="color:rgb(0,51,179)">class</span>);<br><br>        <span style="color:rgb(0,0,0)">Dimension size </span>= <span style="color:rgb(0,0,0)">Toolkit</span>.<span style="font-style:italic">getDefaultToolkit</span>().getScreenSize();<br>        <span style="color:rgb(0,51,179)">final int </span><span style="color:rgb(0,0,0)">captureWidth </span>= (<span style="color:rgb(0,51,179)">int</span>) <span style="color:rgb(0,0,0)">size</span>.getWidth();<br>        <span style="color:rgb(0,51,179)">final int </span><span style="color:rgb(0,0,0)">captureHeight </span>= (<span style="color:rgb(0,51,179)">int</span>) <span style="color:rgb(0,0,0)">size</span>.getHeight();<br><br>        <span style="color:rgb(0,0,0)">FFmpegLogCallback</span>.<span style="font-style:italic">set</span>();<br>        <span style="color:rgb(0,0,0)">FFmpegFrameGrabber</span>.<span style="font-style:italic">tryLoad</span>();<br>        <span style="color:rgb(0,0,0)">FrameGrabber grabber </span>= <span style="color:rgb(0,51,179)">new </span>FFmpegFrameGrabber(<span style="color:rgb(135,16,148);font-style:italic">DEVICE_INDEX</span>);<br>        <span style="color:rgb(0,0,0)">grabber</span>.setFormat(<span style="color:rgb(6,125,23)">"avfoundation"</span>);<br>        <span style="color:rgb(0,0,0)">grabber</span>.setPixelFormat(<span style="color:rgb(0,0,0)">avutil</span>.<span style="color:rgb(135,16,148);font-style:italic">AV_PIX_FMT_0RGB</span>);<br><br><br>        <span style="color:rgb(0,0,0)">grabber</span>.setFrameRate(<span style="color:rgb(135,16,148);font-style:italic">FRAME_RATE</span>);<br>        <span style="color:rgb(0,0,0)">grabber</span>.start();<br><br>        <span style="color:rgb(0,51,179)">final </span><span style="color:rgb(0,0,0)">FFmpegFrameRecorder recorder </span>= <span style="color:rgb(0,51,179)">new </span>FFmpegFrameRecorder(<br>                <span style="color:rgb(6,125,23)">"screen_recording_trial.mp4"</span>,<br>                <span style="color:rgb(0,0,0)">captureWidth</span>, <span style="color:rgb(0,0,0)">captureHeight</span>, <span style="color:rgb(23,80,235)">2</span>);<br><br>        <span style="color:rgb(140,140,140);font-style:italic">//Start recording<br></span><span style="color:rgb(140,140,140);font-style:italic">        </span><span style="color:rgb(0,0,0)">recorder</span>.start();<br><br><br>        <span style="color:rgb(0,0,0)">Frame </span>frame;<br>        <span style="color:rgb(0,51,179)">while </span>((frame = <span style="color:rgb(0,0,0)">grabber</span>.grab()) != <span style="color:rgb(0,51,179)">null</span>) {<br>            <span style="color:rgb(0,0,0)">recorder</span>.record(frame);<br>        }<br><br>        <span style="color:rgb(0,0,0)">recorder</span>.stop();<br>        <span style="color:rgb(0,0,0)">grabber</span>.stop();<br>    }<br>}</pre><pre style="color:rgb(8,8,8);font-family:"JetBrains Mono",monospace;font-size:9.8pt"><br></pre><pre style="color:rgb(8,8,8)"><font face="arial, sans-serif">Thank you </font></pre></div></div>