{"action":"created","issue":{"url":"https://api.github.com/repos/bytedeco/javacv/issues/1244","repository_url":"https://api.github.com/repos/bytedeco/javacv","labels_url":"https://api.github.com/repos/bytedeco/javacv/issues/1244/labels{/name}","comments_url":"https://api.github.com/repos/bytedeco/javacv/issues/1244/comments","events_url":"https://api.github.com/repos/bytedeco/javacv/issues/1244/events","html_url":"https://github.com/bytedeco/javacv/issues/1244","id":465616704,"node_id":"MDU6SXNzdWU0NjU2MTY3MDQ=","number":1244,"title":"FFmpegFrameRecorder and FFmpegFrameGrabber may lead to memory leak","user":{"login":"z384647062","id":36412883,"node_id":"MDQ6VXNlcjM2NDEyODgz","avatar_url":"https://avatars1.githubusercontent.com/u/36412883?v=4","gravatar_id":"","url":"https://api.github.com/users/z384647062","html_url":"https://github.com/z384647062","followers_url":"https://api.github.com/users/z384647062/followers","following_url":"https://api.github.com/users/z384647062/following{/other_user}","gists_url":"https://api.github.com/users/z384647062/gists{/gist_id}","starred_url":"https://api.github.com/users/z384647062/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/z384647062/subscriptions","organizations_url":"https://api.github.com/users/z384647062/orgs","repos_url":"https://api.github.com/users/z384647062/repos","events_url":"https://api.github.com/users/z384647062/events{/privacy}","received_events_url":"https://api.github.com/users/z384647062/received_events","type":"User","site_admin":false},"labels":[{"id":93998514,"node_id":"MDU6TGFiZWw5Mzk5ODUxNA==","url":"https://api.github.com/repos/bytedeco/javacv/labels/bug","name":"bug","color":"fc2929","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":14,"created_at":"2019-07-09T07:27:38Z","updated_at":"2019-07-11T10:22:01Z","closed_at":null,"author_association":"NONE","body":"I used FFmpegFrameRecorder and FFmpegFrameGrabber to convert audio data in mp3 format to PCM format. The following is my code and it has done well.\r\n\r\n`\r\n\r\n        public static void convert(String inputFile, String outputFile, int audioCodec, int sampleRate, int audioBitrate,\r\n                               int audioChannels) {\r\n        Frame audioSamples = null;\r\n        \r\n        FFmpegFrameRecorder recorder = null;\r\n        \r\n        FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(inputFile);\r\n\r\n        \r\n        if (start(grabber)) {\r\n            recorder = new FFmpegFrameRecorder(outputFile, audioChannels);\r\n            recorder.setAudioOption(\"crf\", \"0\");\r\n            recorder.setAudioCodec(audioCodec);\r\n            recorder.setAudioBitrate(audioBitrate);\r\n            recorder.setAudioChannels(audioChannels);\r\n            recorder.setSampleRate(sampleRate);\r\n            recorder.setAudioQuality(0);\r\n            recorder.setAudioOption(\"aq\", \"10\");\r\n\r\n            if (start(recorder)) {\r\n                try {\r\n                    while ((audioSamples = grabber.grab()) != null) {\r\n                        recorder.setTimestamp(grabber.getTimestamp());\r\n                        recorder.record(audioSamples);\r\n                    }\r\n\r\n                } catch (FrameGrabber.Exception e1) {\r\n                } catch (Exception e) {\r\n                }\r\n                stop(grabber);\r\n                stop(recorder);\r\n            }\r\n        }\r\n\r\n    }\r\n\r\n    public static boolean start(FrameGrabber grabber) {\r\n        try {\r\n            grabber.start();\r\n            return true;\r\n        } catch (FrameGrabber.Exception e2) {\r\n            try {\r\n                grabber.restart();\r\n                return true;\r\n            } catch (FrameGrabber.Exception e) {\r\n                try {\r\n                    grabber.stop();\r\n                } catch (FrameGrabber.Exception e1) {\r\n                }\r\n            }\r\n\r\n        }\r\n        return false;\r\n    }\r\n\r\n    public static boolean start(FrameRecorder recorder) {\r\n        try {\r\n            recorder.start();\r\n            return true;\r\n        } catch (Exception e2) {\r\n            try {\r\n                recorder.stop();\r\n                recorder.start();\r\n                return true;\r\n            } catch (Exception e) {\r\n                try {\r\n                    recorder.stop();\r\n                } catch (Exception e1) {\r\n                }\r\n            }\r\n        }\r\n        return false;\r\n    }\r\n\r\n    public static boolean stop(FrameGrabber grabber) {\r\n        try {\r\n            grabber.flush();\r\n            grabber.stop();\r\n            return true;\r\n        } catch (FrameGrabber.Exception e) {\r\n            return false;\r\n        } finally {\r\n            try {\r\n                grabber.stop();\r\n            } catch (FrameGrabber.Exception e) {\r\n            }\r\n        }\r\n    }\r\n\r\n    public static boolean stop(FrameRecorder recorder) {\r\n        try {\r\n            recorder.stop();\r\n            recorder.release();\r\n            return true;\r\n        } catch (Exception e) {\r\n            return false;\r\n        } finally {\r\n            try {\r\n                recorder.stop();\r\n            } catch (Exception e) {\r\n            }\r\n        }\r\n    }\r\n`\r\n\r\nFor example, it can be used by \r\n\r\n`convert(\"test.mp3\",\"test.pcm\", avcodec.AV_CODEC_ID_PCM_S16LE, 16000, 16, 1);`\r\n\r\nBut when I run these code(server) for a long time, the memory usage has reached to 9GB and keep increasing unless I restart the server."},"comment":{"url":"https://api.github.com/repos/bytedeco/javacv/issues/comments/510427041","html_url":"https://github.com/bytedeco/javacv/issues/1244#issuecomment-510427041","issue_url":"https://api.github.com/repos/bytedeco/javacv/issues/1244","id":510427041,"node_id":"MDEyOklzc3VlQ29tbWVudDUxMDQyNzA0MQ==","user":{"login":"duck123456","id":16396030,"node_id":"MDQ6VXNlcjE2Mzk2MDMw","avatar_url":"https://avatars1.githubusercontent.com/u/16396030?v=4","gravatar_id":"","url":"https://api.github.com/users/duck123456","html_url":"https://github.com/duck123456","followers_url":"https://api.github.com/users/duck123456/followers","following_url":"https://api.github.com/users/duck123456/following{/other_user}","gists_url":"https://api.github.com/users/duck123456/gists{/gist_id}","starred_url":"https://api.github.com/users/duck123456/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/duck123456/subscriptions","organizations_url":"https://api.github.com/users/duck123456/orgs","repos_url":"https://api.github.com/users/duck123456/repos","events_url":"https://api.github.com/users/duck123456/events{/privacy}","received_events_url":"https://api.github.com/users/duck123456/received_events","type":"User","site_admin":false},"created_at":"2019-07-11T10:22:01Z","updated_at":"2019-07-11T10:22:01Z","author_association":"NONE","body":"> No, just isolating where the problem occurs is probably enough. Does it happen even without `grabPacket()`? Does it happen with `grab()`?\r\n\r\njust do gabber->start->grabPacket->stop ,no use grab() method"}}
{"actor":{"display_login":"duck123456"}}