Skip to content
This repository was archived by the owner on Apr 21, 2025. It is now read-only.
This repository was archived by the owner on Apr 21, 2025. It is now read-only.

[ReactNative] FFmpegKitConfig.getSafParameterForWrite return -1.unknown with absolute path #205

Closed
@iclassPeter

Description

@iclassPeter

Description
Doing React Native video conversion, I reckon path conversion is needed for android. Failed to convert video with absolute path (maybe I was using wrong absolute path syntax for android?)

For inputPath, I am able to convert successfully as the original path is get from file system and tested and used inputSafUrl on FFprobeKit.getMediaInformationAsync.

However I fail to do the same for outputPath as I am using absolute path?

Expected behavior
Convert path to saf path so ffmpeg can read.

Current behavior
saf:-1.unknown is returned from FFmpegKitConfig.getSafParameterForWrite

To Reproduce
For context, video conversion using FFmpegKit.executeAsync with argument:
-y -i ${inputPath} -map 0 -c:v libx264 -crf 18 -c:a copy ${outputPath}"

The part including FFmpegKitConfig.getSafParameterForWrite:

prepareVideoConversion = (inputRawPath:string, duration:number, inputSafPath?:string) => {

    let inputPath = inputSafPath || inputRawPath;
    
    let outputName = `${new Date().toISOString().slice(0, 19)}.mp4`;
    let outputDir = `${RNFS.DocumentDirectoryPath}/temp/`;
    let outputRawPath = outputDir + outputName;

    // conversion would fail if dir not exist
    RNFS.mkdir(outputDir).then( 
        (res)=>{
            console.log('outputDir created/existed:',outputDir)
            if (Platform.OS === 'ios') {
                outputRawPath = 'file://' + outputRawPath;
                this.convertVideo(inputRawPath, outputRawPath, duration);
            } else if (Platform.OS === "android") {
                let androidOutputPath = outputRawPath;
                // console.log('Test whether output need content://.');androidOutputPath = 'content:/' + outputRawPath
                // console.log('Test using inputpath as output path.'); androidOutputPath = 'inputRawPath';
                FFmpegKitConfig.getSafParameterForWrite(androidOutputPath).then(outputSafUrl => {
                    this.convertVideo(inputRawPath, outputRawPath, duration, inputSafPath, outputSafUrl);
                });
            }
        },
        (reason)=>{
            console.log('error on mkdir:', reason);
        }
    );
}

Screenshots
Capture1

Logs

Environment

  • Platform: React Native
  • Architecture: Android simulator Google Pixel 4a on Window 10
  • Version (if applicable) v4.5
  • Android Studio version (if applicable) 11.0.10+0-b96-7249189 amd64

Metadata

Metadata

Assignees

Labels

androidAffect Android platformenhancementNew feature or requestfixed-in-v4.5.1flutterAffect flutter platformreact-nativeAffect react-native platformsafIssue about storage access frameworkv4.5Affects v4.5 release

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions