anthwlock / untrunc

Restore a truncated mp4/mov. Improved version of ponchio/untrunc
GNU General Public License v2.0
1.9k stars 182 forks source link

Any chance for Alpine based docker image? #65

Closed dzek69 closed 3 years ago

dzek69 commented 3 years ago

It looks like I'd find a great use in this software, but I would like to run it on a Alpine Linux based Docker container. My current project is based on Alpine and has some non-usual dependencies. I've tried to build and copy the binary directly from Ubuntu to Alpine, but this of course fails to run.

I've tried the opposite - to move everything to Ubuntu just to have untrunc available, but this is really a hell for me, but I'm still fighting.

Meanwhile I'd like to ask if there is a possibility to add a Alpine based Dockerfile to this project?

I'm really bad at compiling software and embracing all dependencies needed for it, I only once in my life successfully complied something from GitHub, so I cannot really do that myself, not matter how much I'd like to. Alpine has its own gotchas too ( like this: https://wiki.alpinelinux.org/wiki/Running_glibc_programs ).

It is perfectly fine for you to deny my request, I appreciate yours and ponchio's hard work done for this project and don't want to be too demanding.

With regards, Jacek

anthwlock commented 3 years ago

Does this help you?

dzek69 commented 3 years ago

Yes, awesome! Looks like it couldn't be simpler.

I tried to copy the binary produced by this into my current image (with ffmpeg installed with apk add ffmpeg) and I'm getting the same results I've got when I've copied the binary from ubuntu and installed libc6-compat:

Error loading shared library libavformat.so.57: No such file or directory (needed by /bin/untrunc)
Error loading shared library libavcodec.so.57: No such file or directory (needed by /bin/untrunc)
Error loading shared library libavutil.so.55: No such file or directory (needed by /bin/untrunc)
Error relocating /bin/untrunc: av_get_media_type_string: symbol not found
Error relocating /bin/untrunc: avcodec_find_decoder: symbol not found
Error relocating /bin/untrunc: avformat_find_stream_info: symbol not found
Error relocating /bin/untrunc: avformat_alloc_context: symbol not found
Error relocating /bin/untrunc: av_log_set_level: symbol not found
Error relocating /bin/untrunc: avcodec_flush_buffers: symbol not found
Error relocating /bin/untrunc: av_register_all: symbol not found
Error relocating /bin/untrunc: avcodec_parameters_to_context: symbol not found
Error relocating /bin/untrunc: avcodec_open2: symbol not found
Error relocating /bin/untrunc: avcodec_get_name: symbol not found
Error relocating /bin/untrunc: avcodec_decode_audio4: symbol not found
Error relocating /bin/untrunc: av_packet_alloc: symbol not found
Error relocating /bin/untrunc: avcodec_alloc_context3: symbol not found
Error relocating /bin/untrunc: av_dump_format: symbol not found
Error relocating /bin/untrunc: avcodec_decode_video2: symbol not found
Error relocating /bin/untrunc: av_frame_alloc: symbol not found
Error relocating /bin/untrunc: avformat_open_input: symbol not found

but it works perfectly when using directly in image produced by Dockerfile you've prepared, so I guess there is something in jrottenberg/ffmpeg:3.4-alpine image I miss. But I will work that out, at least I know it can be run on Alpine-based image.

Thanks a lot. I really appreciate it.

anthwlock commented 3 years ago

so I guess there is something in jrottenberg/ffmpeg:3.4-alpine image I miss

When using shared libraries, the the compile-version should match the run-version. But in your case:

possible solutions:

dzek69 commented 3 years ago

I'm currently on ffmpeg 4.2 and I'd like to stay on it as it fits my other needs and probably upgrade freely in the future.

So I guess the best way is to compile statically. After changing some stuff here and there I've managed to compile it, there were hundreds of warnings during the build, but I've ignored it, then I've moved it into my current image and it works!

Thanks again, you really helped me a lot!

Instructions for other people looking for the same thing as me: 1) In the Makefile remove --show-progress from line 97 (Alpine/BusyBox wget doesn't support it) 2) Dockerfile needed to build statically compiled untrunc:

# pull base image
FROM jrottenberg/ffmpeg:3.4-alpine
#LABEL stage=intermediate

RUN apk update \
    && apk add make g++

# copy code
ADD . /untrunc-src
WORKDIR /untrunc-src

# add deps needed to compile ffmpeg
RUN apk add --no-cache yasm coreutils

# build untrunc
RUN /usr/bin/make FF_VER=3.3.9 && strip untrunc

# non-root user
RUN adduser -D untrunc
USER untrunc

# execution
ENTRYPOINT ["/untrunc-src/untrunc"]