{"action":"closed","issue":{"url":"https://api.github.com/repos/bytedeco/javacv/issues/295","labels_url":"https://api.github.com/repos/bytedeco/javacv/issues/295/labels{/name}","comments_url":"https://api.github.com/repos/bytedeco/javacv/issues/295/comments","events_url":"https://api.github.com/repos/bytedeco/javacv/issues/295/events","html_url":"https://github.com/bytedeco/javacv/issues/295","id":124238855,"number":295,"title":"The setTimestamp() in FFmpegFrameRecorder doesn't work properly.","user":{"login":"mastep20","id":16455562,"avatar_url":"https://avatars.githubusercontent.com/u/16455562?v=3","gravatar_id":"","url":"https://api.github.com/users/mastep20","html_url":"https://github.com/mastep20","followers_url":"https://api.github.com/users/mastep20/followers","following_url":"https://api.github.com/users/mastep20/following{/other_user}","gists_url":"https://api.github.com/users/mastep20/gists{/gist_id}","starred_url":"https://api.github.com/users/mastep20/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mastep20/subscriptions","organizations_url":"https://api.github.com/users/mastep20/orgs","repos_url":"https://api.github.com/users/mastep20/repos","events_url":"https://api.github.com/users/mastep20/events{/privacy}","received_events_url":"https://api.github.com/users/mastep20/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/bytedeco/javacv/labels/question","name":"question","color":"cc317c"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2015-12-29T17:02:39Z","updated_at":"2016-01-11T03:52:56Z","closed_at":"2016-01-11T03:52:56Z","body":"Hello. I have a little problem with my app. When I try to set image duration (50 sec) in my video by calling setTimestamp() method in my FFmpegFrameRecorder, my app doesn't work and I get following error:\r\n\r\n    12-29 17:16:51.628 17504-17599/com.example.mateusz.javacv1 E/problem: problem\r\n                                                             org.bytedeco.javacv.FrameRecorder$Exception: avcodec_encode_video2() error -1: Could not encode video packet.\r\n                                                                 at org.bytedeco.javacv.FFmpegFrameRecorder.recordImage(FFmpegFrameRecorder.java:774)\r\n                                                                 at org.bytedeco.javacv.FFmpegFrameRecorder.record(FFmpegFrameRecorder.java:686)\r\n                                                                 at org.bytedeco.javacv.FFmpegFrameRecorder.record(FFmpegFrameRecorder.java:679)\r\n                                                                 at com.example.mateusz.javacv1.MovieCreator.createMovie(MovieCreator.java:122)\r\n                                                                 at com.example.mateusz.javacv1.MovieCreator.doInBackground(MovieCreator.java:46)\r\n                                                                 at com.example.mateusz.javacv1.MovieCreator.doInBackground(MovieCreator.java:28)\r\n                                                                 at android.os.AsyncTask$2.call(AsyncTask.java:288)\r\n                                                                 at java.util.concurrent.FutureTask.run(FutureTask.java:237)\r\n                                                                 at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)\r\n                                                                 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)\r\n                                                                 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)\r\n                                                                 at java.lang.Thread.run(Thread.java:841)\r\n\r\nI try looking in the internet how to resolve this problem but I couldn't find something useful. Below I paste method which create video:\r\n\r\n    private String createMovie() {\r\n\r\n        File folder = Environment\r\n                .getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);\r\n        String path = folder.getAbsolutePath();\r\n        String videoFilePath = path + \"/movie6.mp4\";\r\n        String audioFilePath = path + \"/music.mp3\";\r\n        String finalVideoPath = path + \"/film.mp4\";\r\n\r\n        //File file_folder = new File(path + \"/Camera\");\r\n        //File[] files = file_folder.listFiles();\r\n\r\n        try {\r\n\r\n            FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(videoFilePath, 1280, 720);\r\n            OpenCVFrameConverter converter = new OpenCVFrameConverter() {\r\n                @Override\r\n                public Frame convert(Object o) {\r\n                    return null;\r\n                }\r\n\r\n                @Override\r\n                public Object convert(Frame frame) {\r\n                    return null;\r\n                }\r\n            };\r\n\r\n            //recorder.setAudioCodec(avcodec.AV_CODEC_ID_AMR_NB);\r\n            recorder.setVideoCodec(avcodec.AV_CODEC_ID_MPEG4);\r\n\r\n            recorder.setVideoBitrate(10 * 1024 * 1024);\r\n            recorder.setFrameRate(1);\r\n            recorder.setVideoQuality(0);\r\n            //recorder.setPixelFormat(avutil.AV_PIX_FMT_YUV420P);\r\n            recorder.setFormat(\"mp4\");\r\n\r\n            recorder.start();\r\n            publishProgress(0);\r\n            int number_images = 3;\r\n            long time = 50000000;\r\n            for (int i = 0; i < number_images; i++) {\r\n                opencv_core.IplImage image = cvLoadImage(path + \"/Camera/image\" + i + \".jpg\");\r\n                Frame frame = converter.convert(image);\r\n                recorder.setTimestamp(time);\r\n                recorder.record(frame);\r\n                publishProgress(25*(i+1));\r\n            }\r\n\r\n            recorder.stop();\r\n            publishProgress(76);\r\n            mergeAudioAndVideo(videoFilePath, audioFilePath, finalVideoPath);\r\n            publishProgress(100);\r\n\r\n        } catch (Exception e) {\r\n            Log.e(\"problem\", \"problem\", e);\r\n        }\r\n        return /*videoFilePath;*/finalVideoPath;\r\n    }\r\n\r\n\r\n    private boolean mergeAudioAndVideo(String videoPath, String audioPath, String outPut)\r\n            throws Exception {\r\n        boolean isCreated = true;\r\n        File file = new File(videoPath);\r\n        if (!file.exists()) {\r\n            return false;\r\n        }\r\n        try {\r\n            FrameGrabber grabber1 = new FFmpegFrameGrabber(videoPath);\r\n            FrameGrabber grabber2 = new FFmpegFrameGrabber(audioPath);\r\n\r\n            grabber1.start();\r\n            grabber2.start();\r\n\r\n            //Log.e(\"WIDTH\",grabber2.getSampleRate()+\"\");\r\n\r\n            FrameRecorder recorder = new FFmpegFrameRecorder(outPut,\r\n                    grabber1.getImageWidth(), grabber1.getImageHeight(),\r\n                    grabber2.getAudioChannels());\r\n\r\n            recorder.setFormat(\"mp4\");\r\n            recorder.setFrameRate(grabber1.getFrameRate());\r\n            //recorder.setSampleFormat(grabber2.getSampleFormat());\r\n            recorder.setSampleRate(grabber2.getSampleRate());\r\n            //recorder.setAudioCodec(avcodec.AV_CODEC_ID_MP3);\r\n            //recorder.setVideoCodec(avcodec.AV_CODEC_ID_MPEG4);\r\n            recorder.start();\r\n\r\n            Frame frame1, frame2 = null;\r\n\r\n            while ((frame1 = grabber1.grabFrame()) != null ||\r\n                    (frame2 = grabber2.grabFrame()) != null) {\r\n\r\n                recorder.record(frame1);\r\n                recorder.record(frame2);\r\n\r\n            }\r\n\r\n            recorder.stop();\r\n            grabber1.stop();\r\n            grabber2.stop();\r\n\r\n            //Log.e(LOG_TAG, \"recorder initialize success\");\r\n\r\n        } catch (Exception e) {\r\n            e.printStackTrace();\r\n        }\r\n\r\n        return isCreated;\r\n\r\n    }\r\n\r\nI don't know what am I doing wrong. To build app I use Android Studio 1.5.1 and JavaCV 1.1 . My app I test on Xperia T3. Please, help."}}