Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sample code, "Invalid data found when processing input" and av_register_all #43

Closed
PetrusM opened this issue Aug 21, 2020 · 18 comments
Closed

Comments

@PetrusM
Copy link

PetrusM commented Aug 21, 2020

Hello,

I am now trying SwiftFFmpeg as a replacement for VLCkit. I am at the very beginning of the integration, so I just integrated the sample code from README.md.
It gave me an "Invalid data found when processing input" error on the very first line (try AVFormatContext(url: input)), for any video file (correctly played with ffplay).
After some difficult research, if found this tutorial : http://dranger.com/ffmpeg/tutorial01.html, which gave me the solution : av_register_all() should be called before any operation.
So I made this :

import CFFmpeg
class FfmpegUtils
{
    static func registerAll()
    {av_register_all()}
}

and then

//...
FfmpegUtils.registerAll()
let fmtCtx = try AVFormatContext(url: url.relativePath)
//...

which makes the sample code work.

However, av_register_all() triggers a deprecation warning, as FF_API_NEXT is defined :
In avformat.h :

#if FF_API_NEXT
/**
 * Initialize libavformat and register all the muxers, demuxers and
 * protocols. If you do not call this function, then you can select
 * exactly which formats you want to support.
 *
 * @see av_register_input_format()
 * @see av_register_output_format()
 */
attribute_deprecated
void av_register_all(void);

attribute_deprecated
void av_register_input_format(AVInputFormat *format);
attribute_deprecated
void av_register_output_format(AVOutputFormat *format);
#endif

What is the correct way to do this ? Should the sample code or the lib be corrected to work right away ?

@gregcotten
Copy link
Collaborator

gregcotten commented Aug 21, 2020 via email

@PetrusM
Copy link
Author

PetrusM commented Aug 21, 2020

Version 4.3.1, freshly installed with homebrew yesterday.

% ffmpeg help
ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers
  built with Apple clang version 11.0.3 (clang-1103.0.32.62)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/4.3.1 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libsoxr --enable-videotoolbox --disable-libjack --disable-indev=jack
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100

@gregcotten
Copy link
Collaborator

Just to verify, your initialized your URL using URL(fileURLWithPath:"/The/Path/To/File.mov") and your application either is security scoped to access the file or has sandboxing disabled, correct?

@PetrusM
Copy link
Author

PetrusM commented Aug 22, 2020

  • URL is from an NSOpenPanel, but the same problem occurs when I directly give a path string to AVFormatContext.
  • I changed one letter in the file name, and the error changed to file not found, so the file is correctly found.
  • I tried deactivating sandboxing, the same error occurs. Moreover, with sandboxing activated, everything works when I add av_register_all. So even if I thought the issue could come from sandboxing, I finally think it is not the case.

@gregcotten
Copy link
Collaborator

My only thought then is that you might actually have an old FFmpeg/libav install hanging around and your app is weak linking to that instead of your homebrew FFmpeg. av_unregister_all doesn't do anything for FFmpeg >= 4.0

@PetrusM
Copy link
Author

PetrusM commented Aug 25, 2020

I did not find any other ffmpeg executable on my computer. Is there any way to know the ffmpeg version or location used through SwiftFFmpeg code ?

@sunlubo
Copy link
Owner

sunlubo commented Aug 25, 2020

av_version_info()

@PetrusM
Copy link
Author

PetrusM commented Aug 25, 2020

I got this : git-2020-05-06-106e390490, but I can't find this commit in the official repository...

I also got the versions of the libraries :
avutil : 3671396
avcodec : 3802727
avformat : 3801956
avdevice : 3803748
avfilter : 480612

@sunlubo
Copy link
Owner

sunlubo commented Aug 25, 2020

OK,I will take a look tomorrow.

@sunlubo
Copy link
Owner

sunlubo commented Aug 26, 2020

The 4.3.1 version info should be:
avutil: 3683172
avcodec: 3824484
avformat: 3812708

Your pkg-config search result should be:

pkg-config --modversion libavformat
58.45.100

@PetrusM
Copy link
Author

PetrusM commented Aug 26, 2020

Well then, I translated the version I got from code to this :

ffmpeg : git-2020-05-06-106e390490
avutil : 56.5.100
avcodec : 58.6.103
avformat : 58.3.100
avdevice : 58.10.100
avfilter : 7.85.100

which is definitely different from the ffmpeg version result given in my second message. So I have two versions of the lib on the computer. I have to find where the old one is.

As for pkg-config --modversion libavformat, it results in 58.45.100, but it must refer to the homebrew-installed version.

@PetrusM
Copy link
Author

PetrusM commented Aug 26, 2020

I used any way I know to search in my computer, and could not find any ffmpeg or avutil.h file, except those from the homebrew install.
On top of this, I removed this install (by zipping /usr/local/Cellar/ffmpeg/4\.3\.1), and this time, my project did not compile at all...

@gregcotten
Copy link
Collaborator

I would run brew doctor to see if libav or ffmpeg are lying around somewhere unknown to brew. Also perhaps totally uninstall ffmpeg via brew uninstall ffmpeg and let us know what compile-time errors you get.

@PetrusM
Copy link
Author

PetrusM commented Aug 27, 2020

  • brew doctor followed by brew cleanup : no change.

  • brew uninstall -f --ignore-dependencies ffmpeg : no more access to ffmpeg with command line, and compilation gives this :

Capture d’écran 2020-08-27 à 09 27 36

  • And then
brew install ffmpeg                           
Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/ffmpeg-4.3.1.catalina.bottle.tar.gz
Already downloaded: /Users/pierre/Library/Caches/Homebrew/downloads/ea107a64fe9dff2f0ccb5ca4550e503fb01516b943ed86ce51f1cd04766a902c--ffmpeg-4.3.1.catalina.bottle.tar.gz
==> Pouring ffmpeg-4.3.1.catalina.bottle.tar.gz
🍺  /usr/local/Cellar/ffmpeg/4.3.1: 299 files, 60MB

and we are back to the original situation.


Also, before doing all of this, I noticed that ffmpeg version has been increased to

ffmpeg : git-2020-06-17-32f60e8d96
avutil : 56.5.100 (3671396)
avcodec : 58.6.103 (3802727)
avformat : 58.3.100 (3801956)
avdevice : 58.10.100 (3803748)
avfilter : 7.85.100 (480612)

However, I do not know what did this. Maybe a pod update, but I have looked all over pods directories, there is nothing related to ffmpeg...

Anyway, even after this update, removing av_register_all() prevents the file to be loaded...

@sunlubo
Copy link
Owner

sunlubo commented Aug 28, 2020

Can you use otool to see which libraries your executable are linked to?

otool -L your_executable_file

/usr/local/opt/ffmpeg/lib/libavutil.56.dylib (compatibility version 56.0.0, current version 56.51.100)
 /usr/local/opt/ffmpeg/lib/libavresample.4.dylib (compatibility version 4.0.0, current version 4.0.0)
/usr/local/opt/ffmpeg/lib/libavfilter.7.dylib (compatibility version 7.0.0, current version 7.85.100)
/usr/local/opt/ffmpeg/lib/libavdevice.58.dylib (compatibility version 58.0.0, current version 58.10.100)
/usr/local/opt/ffmpeg/lib/libavformat.58.dylib (compatibility version 58.0.0, current version 58.45.100)
/usr/local/opt/ffmpeg/lib/libswresample.3.dylib (compatibility version 3.0.0, current version 3.7.100)
/usr/local/opt/ffmpeg/lib/libswscale.5.dylib (compatibility version 5.0.0, current version 5.7.100)
/usr/local/opt/ffmpeg/lib/libavcodec.58.dylib (compatibility version 58.0.0, current version 58.91.100)

@PetrusM
Copy link
Author

PetrusM commented Aug 28, 2020

Exactly the command we were looking for !

Well, it seems to be linked to the last version...

/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 902.1.0)
/usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
/usr/lib/libsqlite3.dylib (compatibility version 9.0.0, current version 308.5.0)
/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.11)
/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1894.60.100)
/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 1677.104.0)
/System/Library/Frameworks/SystemConfiguration.framework/Versions/A/SystemConfiguration (compatibility version 1.0.0, current version 1061.141.1)
@loader_path/../Frameworks/VLCKit.framework/Versions/A/VLCKit (compatibility version 1.0.0, current version 1.0.0)
/usr/local/opt/ffmpeg/lib/libavformat.58.dylib (compatibility version 58.0.0, current version 58.45.100)
/System/Library/Frameworks/Security.framework/Versions/A/Security (compatibility version 1.0.0, current version 59306.140.5)
/System/Library/Frameworks/WebKit.framework/Versions/A/WebKit (compatibility version 1.0.0, current version 609.3.5)
/System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 23.0.0)
/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1281.100.1)
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1677.104.0)
/System/Library/Frameworks/CoreGraphics.framework/Versions/A/CoreGraphics (compatibility version 64.0.0, current version 1355.22.0)
/System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 1069.24.0)
/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0)
/System/Library/Frameworks/StoreKit.framework/Versions/A/StoreKit (compatibility version 1.0.0, current version 379.0.0, weak)
/usr/local/opt/ffmpeg/lib/libavcodec.58.dylib (compatibility version 58.0.0, current version 58.91.100)
/usr/local/opt/ffmpeg/lib/libavdevice.58.dylib (compatibility version 58.0.0, current version 58.10.100)
/usr/local/opt/ffmpeg/lib/libavfilter.7.dylib (compatibility version 7.0.0, current version 7.85.100)
/usr/local/opt/ffmpeg/lib/libavutil.56.dylib (compatibility version 56.0.0, current version 56.51.100)
/usr/local/opt/ffmpeg/lib/libswresample.3.dylib (compatibility version 3.0.0, current version 3.7.100)
@rpath/libswiftAppKit.dylib (compatibility version 1.0.0, current version 0.0.0)
@rpath/libswiftCore.dylib (compatibility version 1.0.0, current version 1103.8.25)
@rpath/libswiftCoreGraphics.dylib (compatibility version 1.0.0, current version 0.0.0)
@rpath/libswiftDispatch.dylib (compatibility version 1.0.0, current version 0.0.0)
@rpath/libswiftFoundation.dylib (compatibility version 1.0.0, current version 0.0.0)
@rpath/libswiftObjectiveC.dylib (compatibility version 1.0.0, current version 0.0.0)

@sunlubo
Copy link
Owner

sunlubo commented Aug 28, 2020

Can you drop the VLCKit.framework and try again? I remember it integrated FFmpeg.

@PetrusM
Copy link
Author

PetrusM commented Aug 28, 2020

Yep. This is a success !

ffmpeg : 4.3.1
avutil : 56.51.100 (3683172)
avcodec : 58.91.100 (3824484)
avformat : 58.45.100 (3812708)
avdevice : 58.10.100 (3803748)
avfilter : 7.85.100 (480612)

I could also, as planned, remove the av_register_all()command.

I am really disappointed I could not find this phantom instance of ffmpeg inside VLCkit despite all the efforts I made to locate it. The difficulty was increased due to the fact that during development, the IDE pointed to the version 4.3.1 headers...

Anyway, thank you very much for all your help, and I can then happily close this issue, that is not due to SwiftFFmpeg.

@PetrusM PetrusM closed this as completed Aug 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants