answered
2016-06-06 00:55:53 +0200
Extending the previous (working) answer with all-in-one solution in Docker :)
Dockerfile
FROM ubuntu:xenial
ENV TERM xterm
ENV UNTRUNC /opt/video-recovery
WORKDIR $UNTRUNC
RUN apt-get update && \
apt-get -y install build-essential curl unzip libavformat-dev libavcodec-dev libavutil-dev && \
apt-get -y autoremove && apt-get clean
RUN curl -SLO https://github.com/ponchio/untrunc/archive/master.zip && \
unzip *.zip -d $UNTRUNC && \
rm *.zip && \
mv untrunc-master/* ./ && \
rm -R untrunc-master
COPY track.cpp.patch ./
RUN patch track.cpp track.cpp.patch
RUN g++ -o untrunc file.cpp main.cpp track.cpp atom.cpp mp4.cpp -L/usr/local/lib -lavformat -lavcodec -lavutil
CMD ["./untrunc"]
track.cpp.patch
219,236c219,236
< /* THIS DOES NOT SEEM TO WORK FOR SOME UNKNOWN REASON. IT JUST CONSUMES ALL BYTES.
< * AVFrame *frame = avcodec_alloc_frame();
< if(!frame)
< throw string("Could not create AVFrame");
< AVPacket avp;
< av_init_packet(&avp);
<
< int got_frame;
< avp.data=(uint8_t *)(start);
< avp.size = maxlength;
< int consumed = avcodec_decode_video2(context, frame, &got_frame, &avp);
< av_freep(&frame);
< return consumed; */
<
< //found no way to guess size, probably the only way is to use some functions in ffmpeg
< //to decode the stream
< cout << "Unfortunately I found no way to guess size of mp4v packets. Sorry\n";
< return -1;
---
> AVFrame *frame = avcodec_alloc_frame();
> if(!frame)
> throw string("Could not create AVFrame");
> AVPacket avp;
> av_init_packet(&avp);
>
> int got_frame;
> avp.data=(uint8_t *)(start);
> avp.size = maxlength;
> int consumed = avcodec_decode_video2(context, frame, &got_frame, &avp);
> av_freep(&frame);
>
> if (consumed <= 0 || consumed >= maxlength) return consumed;
>
> if (start[consumed] == 0x7f)
> consumed++; // hack
>
> return consumed;
387a388
> codec.context->thread_type = 0; // if you're using ffmpeg's libavcodec
Usage:
docker build -t video-recovery .
docker run --rm -it -v /your/path/to/broken_and_template/videos:/untrunc --name video-recovery video-recovery bash
(or adjust that command to your needs)
however, you are in the container now, you may run
./untrunc /untrunc/functionalSample.mp4 /untrunc/brokenVideo.mp4
you should see the result at the following path:
/your/path/to/broken_and_template/videos/brokenVideo.mp4_fixed.mp4
the following error (with different numbers) is somehow ok:
[aac @ 0x1a07da0] decode_band_types: Input buffer exhausted before END element found
Invalid length. -1094995529. Wrong match in track: 1
Found 2814 packets
What's the file extension on that file? Is it already .mp4?
Sandoz ( 2015-04-19 23:52:26 +0200 )edityes it is .mp4 in hex it has header like file which is actualy recording until finish capture,
header of file from .recording:
file missing also xml "footer" and who knows what else..
normaly stored file from galery:
pan tau ( 2015-04-20 01:33:39 +0200 )edit@pan tau: With normal mp4 files the needed muxer data (moov index table) is written at the end of the file if the recording is stopped correctly. As in your case the last part and maybe small header update is missing.
You could try to play with ffmpeg to recover the file. Treat it like a raw h.264 data stream. You need to set some parameters (width, height, framerate, ..) to read it correctly with ffmpeg and than you should be able to store it as a normal mp4 file and play it back with any player.
axaq ( 2015-04-23 03:11:27 +0200 )editPLS remove spammer jenengbingung posts. He is just providing useless comments with a link. And remove this when its done.
miqu ( 2016-03-23 09:37:06 +0200 )editI am experiencing this problem when phone has only 2Gb of space free. I suppose the fixes should be to make recording show max video time or / and just gracefully stop video when space is becoming scarce.
miqu ( 2016-03-23 09:41:42 +0200 )edit