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

ffprobekit getMediaInformation session.getMediaInformation() == null, but logCallback can get info. #213

Closed
xwolf47 opened this issue Oct 29, 2021 · 16 comments
Assignees
Labels
android Affect Android platform flutter Affect flutter platform library Affects the library question Further information is requested v4.5 Affects v4.5 release

Comments

@xwolf47
Copy link

xwolf47 commented Oct 29, 2021

Description
Can't get medial info use session.getMediaInformation() alway return null, but print the logCallback can get info.

Expected behavior

Current behavior

To Reproduce

Screenshots
--.

Logs

W/ffmpeg-kit(23314): Get media information execute failed: -i /storage/emulated/0/Download/MOV_0021.mp4.
W/ffmpeg-kit(23314): org.json.JSONException: Value ffprobe of type java.lang.String cannot be converted to JSONObject
W/ffmpeg-kit(23314): 	at org.json.JSON.typeMismatch(JSON.java:111)
W/ffmpeg-kit(23314): 	at org.json.JSONObject.<init>(JSONObject.java:163)
W/ffmpeg-kit(23314): 	at org.json.JSONObject.<init>(JSONObject.java:176)
W/ffmpeg-kit(23314): 	at com.arthenica.ffmpegkit.MediaInformationJsonParser.fromWithError(MediaInformationJsonParser.java:62)
W/ffmpeg-kit(23314): 	at org.json.JSON.typeMismatch(JSON.java:111)
W/ffmpeg-kit(23314): 	at org.json.JSONObject.<init>(JSONObject.java:163)
W/ffmpeg-kit(23314): 	at org.json.JSONObject.<init>(JSONObject.java:176)
W/ffmpeg-kit(23314): 	at com.arthenica.ffmpegkit.FFmpegKitConfig.getMediaInformationExecute(FFmpegKitConfig.java:649)
W/ffmpeg-kit(23314): 	at org.json.JSON.typeMismatch(JSON.java:111)
W/ffmpeg-kit(23314): 	at org.json.JSONObject.<init>(JSONObject.java:163)
W/ffmpeg-kit(23314): 	at org.json.JSONObject.<init>(JSONObject.java:176)
W/ffmpeg-kit(23314): 	at com.arthenica.ffmpegkit.AsyncGetMediaInformationTask.run(AsyncGetMediaInformationTask.java:42)

but the logCallback can return info

I/flutter (23314): ffprobe version v4.5-dev-2008-g90da43557f
I/flutter (23314):  Copyright (c) 2007-2021 the FFmpeg developers
I/flutter (23314): 
I/flutter (23314):   built with Android (7284624, based on r416183b) clang version 12.0.5 (https://android.googlesource.com/toolchain/llvm-project c935d99d7cf2016289302412d708641d52d2f7ee)
I/flutter (23314):   configuration: --cross-prefix=aarch64-linux-android- --sysroot=/files/android-sdk/ndk/23.0.7599858/toolchains/llvm/prebuilt/linux-x86_64/sysroot --prefix=/storage/light/projects/ffmpeg-kit/prebuilt/android-arm64/ffmpeg --pkg-config=/usr/bin/pkg-config --enable-version3 --arch=aarch64 --cpu=armv8-a --cc=aarch64-linux-android24-clang --cxx=aarch64-linux-android24-clang++ --ranlib=llvm-ranlib --strip=llvm-strip --nm=llvm-nm --extra-libs='-L/storage/light/projects/ffmpeg-kit/prebuilt/android-arm64/cpu-features/lib -lndk_compat' --target-os=android --enable-neon --enable-asm --enable-inline-asm --enable-cross-compile --enable-pic --enable-jni --enable-optimizations --enable-swscale --disable-static --enable-shared --enable-v4l2-m2m --disable-outdev=fbdev --disable-indev=fbdev --enable-small --disable-openssl --disable-xmm-clobber-test --disable-debug --enable-lto --disable-neon-clobber-test --disable-programs --disable-postproc --disable-doc --disable-htmlpages --disable-manpages --disable-podpages --disable-tx
I/flutter (23314):   libavutil      57.  5.100 / 57.  5.100
I/flutter (23314):   libavcodec     59.  7.103 / 59.  7.103
I/flutter (23314):   libavformat    59.  5.100 / 59.  5.100
I/flutter (23314):   libavdevice    59.  0.101 / 59.  0.101
I/flutter (23314):   libavfilter     8.  9.100 /  8.  9.100
I/flutter (23314):   libswscale      6.  1.100 /  6.  1.100
I/flutter (23314):   libswresample   4.  0.100 /  4.  0.100
I/flutter (23314): Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/storage/emulated/0/Download/MOV_0021.mp4':
I/flutter (23314):   Metadata:
I/flutter (23314):     major_brand     : 
I/flutter (23314): mp42
I/flutter (23314): 
I/flutter (23314):     minor_version   : 
I/flutter (23314): 0
I/flutter (23314): 
I/flutter (23314):     compatible_brands: 
I/flutter (23314): isommp42
I/flutter (23314): 
I/flutter (23314):     creation_time   : 
I/flutter (23314): 2021-09-18T06:29:10.000000Z
I/flutter (23314): 
I/flutter (23314):     com.android.version: 
I/flutter (23314): 10
I/flutter (23314): 
I/flutter (23314):   Duration: 
I/flutter (23314): 00:00:58.45
I/flutter (23314): , start: 
I/flutter (23314): 0.000000
I/flutter (23314): , bitrate: 
I/flutter (23314): 17792 kb/s
I/flutter (23314): 
I/flutter (23314):   Stream #0:0
I/flutter (23314): [0x1]
I/flutter (23314): (eng)
I/flutter (23314): : Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 155 kb/s
I/flutter (23314):  (default)
I/flutter (23314): 
I/flutter (23314):     Metadata:
I/flutter (23314):       creation_time   : 
I/flutter (23314): 2021-09-18T06:29:10.000000Z
I/flutter (23314): 
I/flutter (23314):       handler_name    : 
I/flutter (23314): SoundHandle
I/flutter (23314): 
I/flutter (23314):       vendor_id       : 
I/flutter (23314): [0][0][0][0]
I/flutter (23314): 
I/flutter (23314):   Stream #0:1
I/flutter (23314): [0x2]
I/flutter (23314): (eng)
I/flutter (23314): : Video: h264 (avc1 / 0x31637661), yuv420p(tv, bt709/bt709/smpte170m), 1920x1080, 17526 kb/s
I/flutter (23314): , SAR 1:1 DAR 16:9
I/flutter (23314): , 
I/flutter (23314): 29.99 fps, 
I/flutter (23314): 29.99 tbr, 
I/flutter (23314): 90k tbn
I/flutter (23314):  (default)
I/flutter (23314): 
I/flutter (23314):     Metadata:
I/flutter (23314):       creation_time   : 
I/flutter (23314): 2021-09-18T06:29:10.000000Z
I/flutter (23314): 
I/flutter (23314):       handler_name    : 
I/flutter (23314): VideoHandle
I/flutter (23314): 
I/flutter (23314):       vendor_id       : 
I/flutter (23314): [0][0][0][0]
I/flutter (23314): 
I/flutter (23314):     Side data:
I/flutter (23314):       
I/flutter (23314): displaymatrix: rotation of -90.00 degrees
I/flutter (23314): 
I/flutter (23314): Instance of 'MediaInformationSession'
W/libEGL  (23314): EGLNativeWindowType 0x70709ca010 disconnect failed

Environment

  • Platform: [Android]
  • Architecture: [arm-v7a, arm-v7a-neon, arm64-v8a, x86, x86_64, armv7, armv7s, arm64, arm64-mac-catalyst, arm64-simulator, arm64e, i386, x86-64, x86-64-mac-catalyst ]
  • Version (v4.5.0)
  • Source branch (v4.5.0)
  • Android Studio version (2020.3.1 Patch 3)

Other
Add any other context about the problem here.

@tanersener
Copy link
Collaborator

There is a org.json.JSONException in your logs. That's why you have it.

Would you mind sharing the file that produces this?

@tanersener tanersener added android Affect Android platform library Affects the library needs-analysis We don't know that this is. It must be investigated further v4.5 Affects v4.5 release labels Oct 29, 2021
@xwolf47
Copy link
Author

xwolf47 commented Oct 29, 2021

@tanersener Thanks your reply.
Ok, here is the file https://1drv.ms/u/s!AuwGFeE9bwKYhx8bdMhpX2KOVpRj?e=yhkZoF

@tanersener tanersener added question Further information is requested and removed needs-analysis We don't know that this is. It must be investigated further labels Oct 29, 2021
@tanersener
Copy link
Collaborator

I tested your file. But didn't see anything wrong with it.

Which FFprobeKit.getMediaInformation method are you using? Is it one of the getMediaInformationFromCommand methods?

@xwolf47
Copy link
Author

xwolf47 commented Nov 1, 2021

Here is the code:

  Future<MediaInformation?> getVideoInfo(final String video) async {
    var logInfo = "";
    MediaInformationSession session = await FFprobeKit.getMediaInformationFromCommandAsync("-i $video", (e){
      print(e);
    }, (log){
      logInfo = log.getMessage();
      print(logInfo);
    });
    var info = session.getMediaInformation();
    if (info == null) {
      print(logInfo);
      //info = MediaInformationSession.fromMap(sessionMap).getMediaInformation();
    }
    return info;
  }

@tanersener
Copy link
Collaborator

When you pass a custom command, we are expecting that command to produce the output in JSON format. Javadoc of command parameter explains this, FFprobe command that prints media information for a file in JSON format. In this case, your command produces a standard FFprobe output which can not be parsed as JSON.

Have a look at the default command we have in FFprobeKit.getMediaInformationAsync and use something similar in your app.

@xwolf47
Copy link
Author

xwolf47 commented Nov 2, 2021

Use FFprobeKit.getMediaInformationAsync is useless, can't get media information. No any error print. But log can get information.

  Future<MediaInformation?> getVideoInfo(final String video) async {
    var logInfo = "";
    MediaInformationSession session = await FFprobeKit.getMediaInformationAsync(video, (e){
      print(e);
    }, (log){
      logInfo = log.getMessage();
      print(logInfo);
    });
    var info = session.getMediaInformation();
    if (info == null) {
      // no data.
    }
    return info;
  }

@tanersener tanersener added the flutter Affect flutter platform label Nov 2, 2021
@tanersener
Copy link
Collaborator

tanersener commented Nov 2, 2021

My suggestion was to look at the command used inside getMediaInformationAsync and use something similar in getMediaInformationFromCommand rather than calling getMediaInformationAsync directly.

Anyway, normally the session returned by getMediaInformationAsync has the MediaInformation object. If it returns null, then there are other methods in the session instance that can be used to check what went wrong. You can see some of them in the http_tab of the test application we have under the ffmpeg-kit-test project. I suggest using them to diagnose your issue.

@xwolf47
Copy link
Author

xwolf47 commented Nov 3, 2021

By use FFprobeKit.getMediaInformationAsync second parameter
ExecuteCallback that's ok. But can we get information direct by await FFprobeKit.getMediaInformationAsync return MediaInformationSession. It's will be fixed?

@tanersener
Copy link
Collaborator

tanersener commented Nov 3, 2021

There is a misunderstanding about those flutter plugin methods. Pasting this from another thread.

All async execute methods we have under FFmpegKit and FFprobeKit are responsible of only starting an execution. That's why they are called async. They return immediately and having await there doesn't change anything. If you want be notified about the completion then you can provide an ExecuteCallback to the method call. Or, creating a wait until session.getState() is completed or failed method is also possible.

@xwolf47
Copy link
Author

xwolf47 commented Nov 4, 2021

Ok, get it. Thanks!

@xwolf47 xwolf47 closed this as completed Nov 4, 2021
@tanersener tanersener self-assigned this Nov 4, 2021
@One-djey
Copy link

One-djey commented Dec 10, 2021

Even waiting for the SessionState to be not running, and waiting for a non-null ReturnCode doesn't guaranty that the MediaInformations field will be filled:

MediaInformationSession mediaInformationSession = await FFprobeKit.getMediaInformationAsync(path);
ReturnCode returnCode;
SessionState state;
do {
  returnCode = await mediaInformationSession.getReturnCode();
  state = await mediaInformationSession.getState();
  print("$state  $returnCode");
  await Future.delayed(Duration(milliseconds: 100));
} while(state == SessionState.running || returnCode == null)
if(ReturnCode.isSuccess(returnCode)){
  print("mediaInformation: ${mediaInformationSession.getMediaInformation()}");
} else if (ReturnCode.isCancel(returnCode)) {
  print("canceled");
} else {
  print("error");
}

This code print:

SessionState.running null
SessionState.completed 0
mediaInformation: null

This is not a normal behavior: completed with success and still empty.

@tanersener
Copy link
Collaborator

@One-djey There are API methods on the session object that can be used to investigate an issue. I suggest looking at them, session.getFailStackTrace() and session.getOutput() particularly.

@amirmhmdi
Copy link

@tanersener
I have same issue !
media information is always null !

@tanersener
Copy link
Collaborator

@amirmhmdi I wish I could help, but I really don't know what your problem is.

@amirmhmdi
Copy link

@tanersener
media information is null after FFprobe finish.
and some times get all logs as string function return data that not json too.

I try to understand when list of log as string is not json object;

@tanersener
Copy link
Collaborator

@amirmhmdi See #215

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android Affect Android platform flutter Affect flutter platform library Affects the library question Further information is requested v4.5 Affects v4.5 release
Projects
None yet
Development

No branches or pull requests

4 participants