anthwlock / untrunc

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

Windows Build error #15

Closed Prakash19921206 closed 5 years ago

Prakash19921206 commented 5 years ago

i downloaded mingw from here [Win-Builds version 1.5] in which mingw was missing but other files were present like gcc, g++ , libav etc so i used mingw from msys installation. then exported the path $ export PATH=$PATH:"/c/mingw-w64_1.5/bin" using mingw64.exeon windows 10 64bit, when i run below command : $ g++ -o untrunc -O3 *.cpp -lavformat -lavcodec -lavutil -std=c++11 i get few error

codec.cpp: In constructor 'Codec::Codec(AVCodecParameters*)': codec.cpp:24:33: error: invalid use of incomplete type 'class AVCodecParameters' codec_ = avcodec_find_decoder(c->codec_id); ^ In file included from codec.cpp:1:0: codec.h:11:7: error: forward declaration of 'class AVCodecParameters' class AVCodecParameters; ^ codec.cpp:27:43: error: 'avcodec_parameters_to_context' was not declared in this scope avcodec_parameters_tocontext(context, c); ^ mp4.cpp: In member function 'void Mp4::parseTracks()': mp4.cpp:326:47: error: 'AVStream' has no member named 'codecpar' Track track(traks[i], context_->streams[i]->codecpar);

i like to build this repository because it fixes corrupt mp4 files in couple of seconds (tested on ubuntu 18.04 LTS) for windows we have this repo, but it takes 5 mins to fix 5 mins length video

i tried to use the libav that i built g++ -o untrunc -I./libav-12.3 *.cpp -L./libav-12.3/libavformat -lavformat -L./libav-12.3/libavcodec -lavcodec -L./libav-12.3/libavresample -lavresample -L./libav-12.3/libavutil -lavutil -lpthread -lz -std=c++11

got same error as above. it looks like libav version that came with mingw installation is different than required. which version of libav is needed to build this repository ?

Thanks & Regards Prakash

anthwlock commented 5 years ago

You need at least ffmpeg/libav 3.1 in order to use codepar.

You can download libav for windows here. I used "shared"+"dev" and extracted them to <mingw-root>/local. You then have to add include to CPATH, lib to LIBRARY_PATH and bin to PATH. I used the pre-built toolchain called "MingW-W64-builds". I hope this was helpful

Prakash19921206 commented 5 years ago

Thanks for detailed answer.

in case if anybody else having any issue building on windows:

I downloaded MingW-W64 from here [be sure to select x86_64 under architecture while installing MingW-W64 rest all default] after installing i didn't get localfolder under <mingw-root>/local so after downloading libavfrom the link you shared, i just copied ffmpeg-20190125-260f196-win64-dev/lib to <mingw-root>/lib
and ffmpeg-20190125-260f196-win64-dev/include to <mingw-root>/include

finally under environment variables i added include to CPATH, lib to LIBRARY_PATHand bin to PATH (CPATH and LIBRARY_PATH didn't exist, do i created and added paths) and executed below line in command prompt g++ -o untrunc -O3 *.cpp -lavformat -lavcodec -lavutil -std=c++11

it built fine.. but when i try to fix corrupt file. i get error and only 4kb mp4 is created. console output is attached : output.txt

on ubuntu 18.04 LTS, same corrupt video (with same code from this repo) was fixed in couple of seconds... i guess some support library is missing on windows?

Update: on ubuntu upon executing below command $ objdump -p untrunc | grep NEEDED i can see the list of lib required by untrunc binary/executable

NEEDED libavformat.so.57 NEEDED libavcodec.so.57 NEEDED libavutil.so.55 NEEDED libstdc++.so.6 NEEDED libm.so.6 NEEDED libgcc_s.so.1 NEEDED libc.so.6

and upon executing below code $ ldd untrunc_executable output is as shown in attachment : ldd output.txt

anthwlock commented 5 years ago

What happens if you do the same to ponchio/untrunc? Does it work? Can you also attach the output of the working one, as a reference? Maybe using a different verison (3.2 or 3.3) of libav ffmpeg works better? Does untrunc terminate normaly? What is it's %errorlevel%?

Prakash19921206 commented 5 years ago

Hi, sorry for delayed reply!

ponchio/untrunc works fine on windows. for ponchio/untrunc i built libav 12.3 from source. but it takes around 30 seconds to fix 5 min video.

ponchio/untrunc_output.txt is the output if i run ponchio/untrunc on windows. note: in attached output above, New access unit since seen picture [probably is standard error] rest all is standard output even thought there was Failure because of NULL header fixed video was working fine

i built with untrunc (libav/ffmpeg 3.4.2, 3.3.4, 3.2.4 - all win64) this repo's untrunc terminates normally with full output as shown in anthwlock/untrunc_output.txt file (all 3 libav versions gave same output). i couldn't get %errorlevel% but i found several Error: searching end, found new 'SPS' and Warning: Different poc lsb in output

in case if you need codec details of the working video, i have attached details from MediaInfo

anthwlock commented 5 years ago

interesting.. can you please provide the verbose log (use -v) from this untrunc on both ubuntu and windows? Additionally does this untrunc work on windows with libav? I think git checkout 361bfa2af should compile with libav. I think you should be able to get the errorlevel by executing echo %errorlevel% after you executed untrunc.

anthwlock commented 5 years ago

Hi, please try the build provided here. I also found a potential stack overflow, maybe it had something to do with your issue!

Prakash19921206 commented 5 years ago

Thanks for the build, i tried both x64 and x86 it partially worked. original video was 176mb (around 5.5 mins), fixed video is 15mb (it shows 2.5mins as video length, and do not play full, it stops playing after 27 seconds)


regarding your build files: i executed below command untrunc.exe -v working.mp4 video.mp4 and this is the log (which partially worked - 15mb)

echo %errorlevel% shows -1

and this has more details, as its the output for more versbose untrunc.exe -vv working.mp4 video.mp4


regarding the untrunc that i built from this repo on windows : this is the output before your latest commit (uploading again as i had missed -vv previously) echo %errorlevel% shows -1073741571


regarding untrunc built on ubuntu (before your latest commit):

this is the output for default

this is the output for verbose

this is the output for more verbose

in ubuntu terminal, executing below command: $ echo ERRORLEVEL: $? shows 0

Thanks

anthwlock commented 5 years ago

Ok, so I think this was the problem, let me know if it works!

Prakash19921206 commented 5 years ago

that worked! Thanks

however there is another issue, after fix the video file. it can be played in vlc (full video length) but if i try to convert the video only 2.5mins gets converted when i run below command ffmpeg -i video.mp4_fixed.mp4 -c copy out.mp4 i get below output

ffmpeg version 4.0.2 Copyright (c) 2000-2018 the FFmpeg developers built with gcc 7.3.1 (GCC) 20180722 configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth libavutil 56. 14.100 / 56. 14.100 libavcodec 58. 18.100 / 58. 18.100 libavformat 58. 12.100 / 58. 12.100 libavdevice 58. 3.100 / 58. 3.100 libavfilter 7. 16.100 / 7. 16.100 libswscale 5. 1.100 / 5. 1.100 libswresample 3. 1.100 / 3. 1.100 libpostproc 55. 1.100 / 55. 1.100 [mov,mp4,m4a,3gp,3g2,mj2 @ 000001dc6265adc0] Could not find codec parameters for stream 1 (Audio: mp3 (mp3float) (mp4a / 0x6134706D), 44100 Hz, 2 channels, fltp, 319 kb/s): unspecified frame size Consider increasing the value for the 'analyzeduration' and 'probesize' options Guessed Channel Layout for Input Stream #0.1 : stereo Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video.mp4_fixed.mp4': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf58.10.100 Duration: 00:05:29.84, start: 0.000000, bitrate: 4494 kb/s Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv), 1920x1080, 4492 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default) Metadata: handler_name : VideoHandler Stream #0:1(und): Audio: mp3 (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 319 kb/s (default) Metadata: handler_name : SoundHandler [mp4 @ 000001dc62f7f040] track 1: codec frame size is not set Output #0, mp4, to 'out.mp4': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf58.12.100 Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv), 1920x1080, q=2-31, 4492 kb/s, 25 fps, 25 tbr, 12800 tbn, 12800 tbc (default) Metadata: handler_name : VideoHandler Stream #0:1(und): Audio: mp3 (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 319 kb/s (default) Metadata: handler_name : SoundHandler Stream mapping: Stream #0:0 -> #0:0 (copy) Stream #0:1 -> #0:1 (copy) Press [q] to stop, [?] for help frame= 3661 fps=163 q=-1.0 Lsize= 80542kB time=00:02:26.40 bitrate=4506.8kbits/s speed= 6.5x video:80525kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.020840%

when i run the same command on regular file (which was used to fix the corrupt file) i don't see below warning:

[mp4 @ 000001dc62f7f040] track 1: codec frame size is not set

i tried on 2 corrupt files, one was 5.5mins, other was around 22mins, both were fixed. but ffmpeg command created output file for first 2.5mins only. the video is not getting fixed properly?

Thanks & Regards

anthwlock commented 5 years ago

I can't reproduce this message, so please give me a sample. If the file is too big, use head -c 40M to get the first 40 Mbyte. Also I wonder.. does this happen on both windows and ubuntu? Does it also happen with ponchio/untrunc? I gues so, but please test it!

Since the issue "Windows Build error " is fixed, I'll close this. Open another one!