{"id":113,"date":"2019-04-25T20:08:49","date_gmt":"2019-04-25T11:08:49","guid":{"rendered":"https:\/\/junkbulk.robots.jp\/wp\/?p=113"},"modified":"2019-04-25T20:08:49","modified_gmt":"2019-04-25T11:08:49","slug":"jcodec%e3%81%a7h-264%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%81%8b%e3%82%89android%e3%81%aebitmap%e3%82%92%e5%8f%96%e5%be%97%ef%bc%88%e6%9c%80%e5%88%9d%e3%81%ae%e3%83%95%e3%83%ac%e3%83%bc%e3%83%a0","status":"publish","type":"post","link":"https:\/\/junkbulk.com\/wp\/?p=113","title":{"rendered":"JCodec\u3067h.264\u30d5\u30a1\u30a4\u30eb\u304b\u3089Android\u306eBitmap\u3092\u53d6\u5f97\uff08\u6700\u521d\u306e\u30d5\u30ec\u30fc\u30e0\uff09"},"content":{"rendered":"\n<p> <br><a href=\"https:\/\/play.google.com\/store\/apps\/details?id=com.junkbulk.dsgviewer\">DSGViewer<\/a> \u3092\u4f5c\u308b\u305f\u3081\u306bh.264\u3092\u6271\u3046\u5fc5\u8981\u304c\u3042\u308a\u307e\u3057\u305f\u3002h.264\u306a\u3093\u3066MediaCodec\u3067\u7c21\u5358\uff01\u3068\u601d\u3063\u3066\u3044\u305f\u3089\u5168\u7136\u3046\u307e\u304f\u3044\u304b\u305a\u632b\u6298\u3057\u307e\u3057\u305f\u3002h.264\u3067\u3082mp4\u306a\u3089\u7c21\u5358\u306b\u3067\u304d\u305f\u306e\u3067\u3059\u304c\u3001h264\u306eraw\u30c7\u30fc\u30bf\uff08\u3068\u3044\u3046\u306e\u304b\uff1f\u6700\u521d\u304c00 00 00 01\u3067\u59cb\u307e\u308b\u3084\u3064\uff09\u304c\u3046\u307e\u304f\u3044\u304b\u306a\u3044\u3002<\/p>\n\n\n\n<p>\u60a9\u3093\u3067\u3044\u3066\u3082\u4ed5\u65b9\u304c\u306a\u3044\u306e\u3067\u3001java\u3060\u3051\u3067\u30c7\u30b3\u30fc\u30c9\u3067\u304d\u308b\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u63a2\u3057\u305f\u3068\u3053\u308d\u3001<a href=\"http:\/\/jcodec.org\/\">JCodec<\/a>\u3092\u898b\u3064\u3051\u3066\u8a66\u884c\u932f\u8aa4\u3057\u306a\u304c\u3089\u4f7f\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u3002\u4f7f\u3063\u3066\u5206\u304b\u3063\u305f\u3053\u3068\u3092\u8a18\u9332\u3057\u307e\u3059\u3002JCodec\u306fjava\u3067\u3059\u304c\u3001kotlin\u3067\u3044\u304d\u307e\u3059\u3002\u30a8\u30e9\u30fc\u51e6\u7406\u3084null\u30c1\u30a7\u30c3\u30af\u306f\u629c\u304b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u307e\u305a\u3001\u4f7f\u3046\u305f\u3081\u306b<a href=\"http:\/\/jcodec.org\/\">\u3053\u3053<\/a>\u306eGetting started\u3092\u53c2\u7167\u3057\u3001build.gradle\u3092\u7de8\u96c6\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">dependencies {\n    implementation fileTree(dir: 'libs', include: ['*.jar'])\n    implementation\"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version\"\n    implementation 'com.android.support:appcompat-v7:28.0.0'\n    implementation 'com.android.support.constraint:constraint-layout:1.1.3'\n    testImplementation 'junit:junit:4.12'\n    androidTestImplementation 'com.android.support.test:runner:1.0.2'\n    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'\n    \/\/\u8ffd\u52a0 compile\u3092implementation\u306b\u7f6e\u304d\u63db\u3048\n    implementation 'org.jcodec:jcodec:0.2.3'\n    implementation 'org.jcodec:jcodec-android:0.2.3'\n}\n<\/pre>\n\n\n\n<p>\u8ffd\u52a0\u306e\u90e8\u5206\u306f\u3001\u305d\u306e\u307e\u307e\u30b3\u30d4\u30fc\u3059\u308b\u3068compile\u306e\u90e8\u5206\u3067\u8b66\u544a\u304c\u51fa\u308b\u306e\u3067 implementation \u306b\u7f6e\u304d\u63db\u3048\u307e\u3057\u305f\u3002<br>\u3042\u3068\u3001Bitmap\u306e\u78ba\u8a8d\u7528\u306bMainActivity\u306b\u306fImageView\u3092\u7f6e\u3044\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"xml\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?>\n&lt;android.support.constraint.ConstraintLayout\n        xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\n        xmlns:tools=\"http:\/\/schemas.android.com\/tools\"\n        xmlns:app=\"http:\/\/schemas.android.com\/apk\/res-auto\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"match_parent\"\n        tools:context=\".MainActivity\">\n\n    &lt;ImageView\n            android:layout_width=\"0dp\"\n            android:layout_height=\"0dp\"\n            app:srcCompat=\"@android:color\/holo_blue_dark\"\n            android:id=\"@+id\/imageView\"\n            app:layout_constraintBottom_toBottomOf=\"parent\"\n            app:layout_constraintRight_toRightOf=\"parent\"\n            app:layout_constraintLeft_toLeftOf=\"parent\"\n            app:layout_constraintTop_toTopOf=\"parent\"\/>\n    \n&lt;\/android.support.constraint.ConstraintLayout><\/pre>\n\n\n\n<p>h264\u304b\u3089\u6700\u521d\u306e\u30d5\u30ec\u30fc\u30e0\u3092\u53d6\u308a\u51fa\u3057\u3066\u8868\u793a\u3057\u3066\u307f\u307e\u3059\u3002<br><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"kotlin\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">class MainActivity : AppCompatActivity() {\n\n    override fun onCreate(savedInstanceState: Bundle?) {\n        super.onCreate(savedInstanceState)\n        setContentView(R.layout.activity_main)\n        imageView.setImageBitmap(getFirstFrame())\n    }\n    fun getFirstFrame() : Bitmap{\n        val file = File(\"\/sdcard\/000.h264\")\n        val buf = NIOUtils.fetchFromFile(file)\n        val es = BufferH264ES(buf)\n        val nextFrame  =  es!!.nextFrame()\n        val decoder = H264Decoder()\n        val pic = Picture.create(1280, 1024, ColorSpace.YUV420)\n        val op = decoder.decodeFrame(nextFrame.data, pic.data).cropped()\n        return AndroidUtil.toBitmap(op)\n    }\n}<\/pre>\n\n\n\n<p>    pic = Picture.create(1280, 1024, ColorSpace.YUV420)\u306f\u3001\u30c7\u30b3\u30fc\u30c9\u3059\u308b\u753b\u50cf\u306e\u30d0\u30c3\u30d5\u30a1\u30fc\u304c\u5fc5\u8981\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u753b\u9762\u30b5\u30a4\u30ba\u3068\u304b\u306f\u4eee\u3067\u3059\u3002 ColorSpace.YUV420 \u306f\u3001RGB\u306b\u3057\u305f\u3089\u30c0\u30e1\u3067\u3057\u305f\u3002\u30c7\u30b3\u30fc\u30c9\u3057\u305f\u5f8c\u306bcropped()\u3068\u3084\u308b\u3068\u753b\u50cf\u30b5\u30a4\u30ba\u3092\u3061\u3083\u3093\u3068\u5408\u308f\u305b\u3066\u304f\u308c\u308b\u307f\u305f\u3044\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u3072\u3068\u307e\u305a\u3053\u3093\u306a\u611f\u3058\u3002\u30c7\u30a3\u30b9\u30af\u304b\u3089\u8aad\u3080\u306e\u3067Manifest\u306e\u30d1\u30fc\u30df\u30c3\u30b7\u30e7\u30f3\u306e\u8a2d\u5b9a\u306f\u5fd8\u308c\u305a\u306b\u3002\u6b21\u306f\u4efb\u610f\u306e\u30d5\u30ec\u30fc\u30e0\u53d6\u5f97\u3078\u7d9a\u304f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>DSGViewer \u3092\u4f5c\u308b\u305f\u3081\u306bh.264\u3092\u6271\u3046\u5fc5\u8981\u304c\u3042\u308a\u307e\u3057\u305f\u3002h.264\u306a\u3093\u3066MediaCodec\u3067\u7c21\u5358\uff01\u3068\u601d\u3063\u3066\u3044\u305f\u3089\u5168\u7136\u3046\u307e\u304f\u3044\u304b\u305a\u632b\u6298\u3057\u307e\u3057\u305f\u3002h.264\u3067\u3082mp4\u306a\u3089\u7c21\u5358\u306b\u3067\u304d\u305f\u306e\u3067\u3059\u304c\u3001h264\u306eraw\u30c7\u30fc &hellip; <a href=\"https:\/\/junkbulk.com\/wp\/?p=113\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;JCodec\u3067h.264\u30d5\u30a1\u30a4\u30eb\u304b\u3089Android\u306eBitmap\u3092\u53d6\u5f97\uff08\u6700\u521d\u306e\u30d5\u30ec\u30fc\u30e0\uff09&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/junkbulk.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/113"}],"collection":[{"href":"https:\/\/junkbulk.com\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/junkbulk.com\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/junkbulk.com\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/junkbulk.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=113"}],"version-history":[{"count":3,"href":"https:\/\/junkbulk.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/113\/revisions"}],"predecessor-version":[{"id":120,"href":"https:\/\/junkbulk.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/113\/revisions\/120"}],"wp:attachment":[{"href":"https:\/\/junkbulk.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=113"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/junkbulk.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=113"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/junkbulk.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=113"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}