arthenica / ffmpeg-kit

FFmpeg Kit for applications. Supports Android, Flutter, iOS, Linux, macOS, React Native and tvOS. Supersedes MobileFFmpeg, flutter_ffmpeg and react-native-ffmpeg.
https://arthenica.github.io/ffmpeg-kit
GNU Lesser General Public License v3.0
4.49k stars 600 forks source link

Incorrect video duration from getMediaInformation Method #412

Closed Nishit-Chauhan closed 2 years ago

Nishit-Chauhan commented 2 years ago

Description i am getting incorrect video duration from the getMediaInformation method. i have recored video about 30 seconds and getting duration is 10 seconds. facing same in Android and IOS both platform. Help appreciated, Thanks in Advance

Expected behavior Get correct video duration

Current behavior incorrect video duration

Code

FFprobeKit.getMediaInformation(uri).then(async information => { let info = await information.getDuration() console.log('INFO', info) if (info) totaltime = info });

Environment

giuseppegambino92 commented 2 years ago

I confirm this bug. The getDuration function returns values that do not match the duration of the video.

tanersener commented 2 years ago

We don't see an issue about the duration field in our test apps.

Consider sharing the logs and/or instructions to reproduce the issue if you need help. Hard to say what it is without those two.

SandipJawaleRN commented 2 years ago

@tanersener await FFprobeKit.getMediaInformation(fpath) .then(async (session) => { // const information = await session.getMediaInformation(); const output = await session.getOutput(); const outputJSON = JSON.parse(output); console.log(outputJSON); }) .catch(error => console.error(error));

above code returning incorrect video dimensions i.e for portrait video its returning landscape o/p for some videos O/P => {"chapters": [], "format": {"bit_rate": "20142565", "duration": "20.433900", "filename": "/data/user/0/com.abc.appname/cache999999", "format_name": "mov,mp4,m4a,3gp,3g2,mj2", "nb_programs": 0, "nb_streams": 2, "probe_score": 100, "size": "51448897", "start_time": "0.000000", "tags": {"com.android.version": "11", "compatible_brands": "isommp42", "creation_time": "2022-06-05T12:39:01.000000Z", "location": "+19.9871+073.8417/", "location-eng": "+19.9871+073.8417/", "major_brand": "mp42", "minor_version": "0"}}, "streams": [{"avg_frame_rate": "18270000/608813", "bit_rate": "20025342", "bits_per_raw_sample": "8", "chroma_location": "left", "closed_captions": 0, "codec_long_name": "unknown", "codec_name": "h264", "codec_tag": "0x31637661", "codec_tag_string": "avc1", "codec_type": "video", "coded_height": 1080, "coded_width": 1920, "color_primaries": "bt709", "color_range": "tv", "color_space": "bt709", "color_transfer": "bt709", "display_aspect_ratio": "16:9", "disposition": [Object], "duration": "20.293767", "duration_ts": 1826439, "field_order": "progressive", "has_b_frames": 0, "height": 1080, "id": "0x1", "index": 0, "is_avc": "true", "level": 40, "nal_length_size": "4", "nb_frames": "609", "pix_fmt": "yuv420p", "profile": "100", "r_frame_rate": "30/1", "refs": 1, "sample_aspect_ratio": "1:1", "side_data_list": [Array], "start_pts": 12573, "start_time": "0.139700", "tags": [Object], "time_base": "1/90000", "width": 1920}, {"avg_frame_rate": "0/0", "bit_rate": "96005", "bits_per_sample": 0, "channel_layout": "stereo", "channels": 2, "codec_long_name": "unknown", "codec_name": "aac", "codec_tag": "0x6134706d", "codec_tag_string": "mp4a", "codec_type": "audio", "disposition": [Object], "duration": "20.415688", "duration_ts": 979953, "id": "0x2", "index": 1, "nb_frames": "957", "profile": "1", "r_frame_rate": "0/0", "sample_fmt": "fltp", "sample_rate": "48000", "start_pts": 0, "start_time": "0.000000", "tags": [Object], "time_base": "1/48000"}]}

"coded_height": 1080, "coded_width": 1920,

but ImagePicker from 'react-native-image-picker' and Video from 'react-native-video' onLoad method returning correct info

Image picker data {"assets":[{"height":1920,"width":1080,"type":"video/mp4","duration":20,"fileName":"1343421124","bitrate":20142533,"fileSize":51448897,"uri":"content://com.google.android.apps.photos.contentprovider/-1/2/content%3A%2F%2Fmedia%2Fexternal%2Fvideo%2Fmedia%2F26/ORIGINAL/NONE/video%2Fmp4/1343421124"}]}

onLoad data {"canStepBackward":true,"canPlayReverse":true,"canPlaySlowReverse":true,"canStepForward":true,"naturalSize":{"height":1920,"orientation":"portrait","width":1080},"canPlayFastForward":true,"canPlaySlowForward":true,"currentTime":0,"duration":20.434}

tanersener commented 2 years ago

@SandipJawaleRN Your question is unrelated to the original issue reported in the first post. Please ask google about it. It is not a bug, it is just how rotation information is stored in a file.

SandipJawaleRN commented 2 years ago

@tanersener. First off, thank you so much for this library. It helped me a lot. The question might be unrelated but my point is how to get such a video information correctly from FFprobeKit.getMediaInformation().

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] commented 2 years ago

This issue was closed because it has been stalled for 7 days with no activity.

FlashTang commented 1 year ago

@tanersener. First off, thank you so much for this library. It helped me a lot. The question might be unrelated but my point is how to get such a video information correctly from FFprobeKit.getMediaInformation().

@SandipJawaleRN Hello sir , how did you fix this , I' having the same issue , the video duration is 4m52s , but FFprobeKit.getMediaInformation(inputURL.path).getDuration() returns 13 which is "unrelated" 😂

Edit: I know now , it's not the video duration , but the time taken to execute of session Now , how can I get the video total duration ?

Edit2 : finally I figured out it prints 291.860000 ( 4.86 m = 4m52s) Anyway I still want to know if there is a better way to get the video duration

FFprobeKit.getMediaInformation(fromCommandAsync: "-i \(inputURL.path) -show_entries format=duration -v quiet -of csv='p=0'", withCompleteCallback: { mediaInformationSession in

                        }, withLogCallback: { log in
                            if let msg = log?.getMessage() {
                                print("----------")
                                print(msg)
                                print("----------")
                            }

                        }, onDispatchQueue: DispatchQueue.main, withTimeout: 10000)
fanpener commented 1 year ago

@tanersener. First off, thank you so much for this library. It helped me a lot. The question might be unrelated but my point is how to get such a video information correctly from FFprobeKit.getMediaInformation().

@SandipJawaleRN Hello sir , how did you fix this , I' having the same issue , the video duration is 4m52s , but FFprobeKit.getMediaInformation(inputURL.path).getDuration() returns 13 which is "unrelated" 😂

Edit: I know now , it's not the video duration , but the time taken to execute of session Now , how can I get the video total duration ?

Edit2 : finally I figured out it prints 291.860000 ( 4.86 m = 4m52s) Anyway I still want to know if there is a better way to get the video duration

FFprobeKit.getMediaInformation(fromCommandAsync: "-i \(inputURL.path) -show_entries format=duration -v quiet -of csv='p=0'", withCompleteCallback: { mediaInformationSession in

                        }, withLogCallback: { log in
                            if let msg = log?.getMessage() {
                                print("----------")
                                print(msg)
                                print("----------")
                            }

                        }, onDispatchQueue: DispatchQueue.main, withTimeout: 10000)
MediaInformationSession mediaInformationSession = await FFprobeKit.getMediaInformation(filePath);
final information = mediaInformationSession.getMediaInformation();
if(information == null){
  throw Exception('get information error');
}else{
  String? duration = information.getDuration();
}