anthwlock / untrunc

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

HOWTO workaround untrunc failure with subtitle track #120

Open clort81 opened 1 year ago

clort81 commented 1 year ago

Hi! AWESOME TOOL! On devuan aarch64, I had to build with make FF_VER=3.3.9 because apparently my libavcodec include is too new (?)
Package: libavcodec-dev Version: 7:5.1.2-1 Here's the build error in case it's interesting:

pr/Video/untrunc$ make
untrunc: v308-d72ec32
ffmpeg: shared

g++ -O2 -ffast-math -ftree-vectorize -fno-strict-overflow -funsafe-math-optimizations -march=armv8-a+crypto+crc+aes+sha2 -MMD -MP -DUNTR_VERSION=\"v308-d72ec32\" -O2 -ffast-math -ftree-vectorize -fno-strict-overflow -funsafe-math-optimizations -march=armv8-a+crypto+crc+aes+sha2 -std=c++11 -D_FILE_OFFSET_BITS=64 -g -o .build_shared/src/codec.o -c src/codec.cpp
In file included from /usr/include/aarch64-linux-gnu/libavcodec/avcodec.h:40,
                 from src/codec.cpp:9:
/usr/include/aarch64-linux-gnu/libavcodec/codec.h:246:11: error: ‘AVChannelLayout’ does not name a type
  246 |     const AVChannelLayout *ch_layouts;
      |           ^~~~~~~~~~~~~~~
In file included from /usr/include/aarch64-linux-gnu/libavcodec/avcodec.h:42,
                 from src/codec.cpp:9:
/usr/include/aarch64-linux-gnu/libavcodec/codec_par.h:212:5: error: ‘AVChannelLayout’ does not name a type
  212 |     AVChannelLayout ch_layout;
      |     ^~~~~~~~~~~~~~~
In file included from src/codec.cpp:9:
/usr/include/aarch64-linux-gnu/libavcodec/avcodec.h:2056:5: error: ‘AVChannelLayout’ does not name a type
 2056 |     AVChannelLayout ch_layout;
      |     ^~~~~~~~~~~~~~~
src/codec.cpp: In function ‘int untr_decode_audio4(AVCodecContext*, AVFrame*, int*, AVPacket*, uint)’:
src/codec.cpp:341:17: error: ‘avcodec_decode_audio4’ was not declared in this scope; did you mean ‘untr_decode_audio4’?
  341 |  int consumed = avcodec_decode_audio4(avctx, frame, got_frame, pkt);
      |                 ^~~~~~~~~~~~~~~~~~~~~
      |                 untr_decode_audio4
src/codec.cpp: In function ‘int untr_decode_video2(AVCodecContext*, AVFrame*, int*, AVPacket*)’:
src/codec.cpp:366:9: error: ‘avcodec_decode_video2’ was not declared in this scope; did you mean ‘untr_decode_video2’?
  366 |  return avcodec_decode_video2(avctx, frame, got_frame, pkt);
      |         ^~~~~~~~~~~~~~~~~~~~~
      |         untr_decode_video2
src/codec.cpp: In lambda function:
src/codec.cpp:389:59: error: ‘struct AVCodecParameters’ has no member named ‘channels’
  389 |   self->was_bad_ = (!got_frame || self->av_codec_params_->channels != frame->channels);
      |                                                           ^~~~~~~~
src/codec.cpp:392:50: error: ‘struct AVCodecParameters’ has no member named ‘channels’
  392 |    logg(V, "channels: ", self->av_codec_params_->channels, ", ", frame->channels, '\n');
      |                                                  ^~~~~~~~
make: *** [Makefile:150: .build_shared/src/codec.o] Error 1

Now my truncated video is from an Autel Nano+, which embeds info into a subtitle 'subtrack'. untrunc can't handle it.

Info: version 'v308-d72ec32' using ffmpeg 'd72ec32'
Info: reading MAX_0107.MP4
Info: parsing healthy moov atom ... 
Info: special track found (text, 'Autel.Subtitle')

Info: unknown track 'text' found -> fallback to dynamic stats
Info: using dynamic stats, use '-is' to see them
Info: reading mdat from truncated file ...
Error: unable to find correct codec -> premature end (~0.05089%)
       try '-s' to skip unknown sequences

Warning: guessed frame durations of 'text' will probably be wrong!
Info: Found 1 packets ( avc1: 1 avc1-keyframes: 1 text: 0 )
Info: Duration of avc1: 33ms  (33 ms)
Info: Duration of text:  (0 ms)
Info: pruned empty 'text' track
Info: saving MAX_0111.MP4_fixed-dyn.MP4

3 warnings were hidden!

However ffmpeg-stripvid.sh by Ivan Boothe created a file that untrunc can handle! ffmpeg-stripvid.sh.gz

I hope this might help someone.