termux-packages
termux-packages copied to clipboard
[Package]: bin2c
Why do you want to add this package to Termux?
bin2c can be used to embed binary & text files inside C binaries.
Apache License.
Home page URL
https://github.com/adobe/bin2c
Source code URL
https://github.com/adobe/bin2c
Packaging policy acknowledgement
- [X] The requested package complies with Packaging Policy.
Additional information
No response
How it is different from xxd -i ./path/to/file
?
Could you give examples of distributions using specifically bin2c
from https://github.com/adobe/bin2c?
$ bin2c yuv < /the/path/of/352x288.yuv > yuv.h
$ cat yuv.h
#include <stdlib.h>
const char yuv[] = "\
...
";
const size_t yuv_len = sizeof(yuv) - 1;
It will be convenient and faster for xxd
.
xxd 13.9045 Mb/s bin2c 547.613 Mb/s
Might as well just use the linker:
~ $ ffmpeg -f rawvideo -pix_fmt yuv420p -s 256x256 -i /dev/urandom -t 1 -r 12 -f rawvideo out.yuv
ffmpeg version 6.0 Copyright (c) 2000-2023 the FFmpeg developers
built with Android (9352603, based on r450784d1) clang version 14.0.7 (https://android.googlesource.com/toolchain/llvm-project 4c603efb0cca074e9238af8b4106c30add4418f6)
configuration: --arch=aarch64 --as=aarch64-linux-android-clang --cc=aarch64-linux-android-clang --cxx=aarch64-linux-android-clang++ --nm=llvm-nm --pkg-config=/home/builder/.termux-build/_cache/android-r25c-api-24-v2/bin/pkg-config --strip=llvm-strip --cross-prefix=aarch64-linux-android- --disable-indevs --disable-outdevs --enable-indev=lavfi --disable-static --disable-symver --enable-cross-compile --enable-gnutls --enable-gpl --enable-lcms2 --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libfreetype --enable-libgme --enable-libmp3lame --enable-libopus --enable-librav1e --enable-libsoxr --enable-libsrt --enable-libssh --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg --enable-opencl --enable-shared --prefix=/data/data/com.termux/files/usr --target-os=android --extra-libs=-landroid-glob --disable-vulkan --enable-neon --disable-libfdk-aac
libavutil 58. 2.100 / 58. 2.100
libavcodec 60. 3.100 / 60. 3.100
libavformat 60. 3.100 / 60. 3.100
libavdevice 60. 1.100 / 60. 1.100
libavfilter 9. 3.100 / 9. 3.100
libswscale 7. 1.100 / 7. 1.100
libswresample 4. 10.100 / 4. 10.100
libpostproc 57. 1.100 / 57. 1.100
Input #0, rawvideo, from '/dev/urandom':
Duration: N/A, start: 0.000000, bitrate: 19660 kb/s
Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 256x256, 19660 kb/s, 25 tbr, 25 tbn
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> rawvideo (native))
Press [q] to stop, [?] for help
Output #0, rawvideo, to 'out.yuv':
Metadata:
encoder : Lavf60.3.100
Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p(progressive), 256x256, q=2-31, 9437 kb/s, 12 fps, 12 tbn
Metadata:
encoder : Lavc60.3.100 rawvideo
frame= 12 fps=0.0 q=-0.0 Lsize= 1152kB time=00:00:00.91 bitrate=10295.1kbits/s dup=0 drop=10 speed=3.03x
video:1152kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000000%
~ $ ld -r -b binary out.yuv -o out.o
~ $ nm out.o
0000000000120000 D _binary_out_yuv_end
0000000000120000 A _binary_out_yuv_size
0000000000000000 D _binary_out_yuv_start
Then declare the variable as:
~ $ cat main.c
#include <stdio.h>
#include <stdint.h>
extern uint8_t _binary_out_yuv_start[];
extern uint8_t _binary_out_yuv_end[];
int main(){
uint8_t *s = _binary_out_yuv_start, *e =_binary_out_yuv_end;
fwrite(s, 1, (size_t)(e-s), stdout);
return 0;
}
~ $ gcc main.c out.o
~ $ hexdump -C out.yuv | diff <(./a.out | hexdump -C) -
~ $
Inpressive solution! It uses ld
to generate a *.o
, while bin2c
generate a *.h
. For some cases, such as embedded development, I must use the toolchains provided by the vendor of DSP/MCU/..., which doesn't have ld
. A *.h
will be more convenient. Anyway, thanks for your awesome solution.
@Freed-Wu Off-topic here... but I find it weird you're working on embedded development in Termux. I will assume you use Termux as an alternative development interface (since these toolchains isn't provided by Termux).