swan: Bug in RunProcessAsync?

I’m trying to process the output data from ffprobe. I have a problem processing with RunProcessAsync. The output is duplicated and garbled. Can you look at it, please?

Here is my code:

        private async Task RunTest()
        {
            string output = "";
            string output2 = "";

            var result = await ProcessRunner.RunProcessAsync(
               @"C:\Users\Test\Documents\ff\ffprobe.exe",
               "-v quiet -print_format xml -show_format \"b.mp4\"",
               // A success callback with a reference to the output and the process itself
               (data, proc) =>
               {
                   output = Encoding.GetEncoding("utf-8").GetString(data);
                   output2 += output;
                   Console.WriteLine("Success callback. Length: " + output.Length);
               },
               // An error callback with a reference to the error and the process itself
               (data, proc) =>
               {

               }
              );

            Console.WriteLine("Complete length:" + output2.Length);
            Console.WriteLine(output2);
        }

The console output is:

Success callback. Length: 517
Success callback. Length: 2048
Complete length:2565
<?xml version="1.0" encoding="UTF-8"?>
<ffprobe>
    <format filename="b.mp4" nb_streams="4" nb_programs="0" format_name="mov,mp4,m4a,3gp,3g2,mj2" format_long_name="QuickTime / MOV" start_time="0.000000" duration="60.095000" size="5510872" bit_rate="733621" probe_score="100">
        <tag key="major_brand" value="mp42"/>
        <tag key="minor_version" value="1"/>
        <tag key="compatible_brands" value="mp42avc1"/>
        <tag key="creation_time" value="2010-02-09T01:55:39.000000Z"/>
    </format>
</ffprobe>
n="1.0" encoding="UTF-8"?>
<ffprobe>
    <format filename="b.mp4" nb_streams="4" nb_programs="0" format_name="mov,mp4,m4a,3gp,3g2,mj2" format_long_name="QuickTime / MOV" start_time="0.000000" duration="60.095000" size="5510872" bit_rate="733621" probe_score="100">
        <tag key="major_brand" value="mp42"/>
        <tag key="minor_version" value="1"/>
        <tag key="compatible_brands" value="mp42avc1"/>
        <tag key="creation_time" value="2010-02-09T01:55:39.000000Z"/>
    </format>
???????????????????????????????????????????????????????????????????????????????????????????????

Here is sample video: b.zip

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 17 (12 by maintainers)

Most upvoted comments

I apologize for the delay. Tested - output is still doubled. I think the problem is not in encoding but rather in buffer processing.

Thanks a lot for working on it. I tested this branch. The bug is still there 😦 I’m sending a simplified test code:

ProcessResult data1 = await ProcessRunner.GetProcessResultAsync(@"C:\ffmpeg\ffprobe.exe",
    "-v quiet -print_format xml -show_format \"b.mp4\"",
    Encoding.UTF8);
Console.WriteLine(data1.StandardOutput);

Incorrect output (current state):

<?xml version="1.0" encoding="UTF-8"?>
<ffprobe>
    <format filename="b.mp4" nb_streams="4" nb_programs="0" format_name="mov,mp4,m4a,3gp,3g2,mj2" format_long_name="QuickTime / MOV" start_time="0.000000" duration="60.095000" size="5510872" bit_rate="733621" probe_score="100">
        <tag key="major_brand" value="mp42"/>
        <tag key="minor_version" value="1"/>
        <tag key="compatible_brands" value="mp42avc1"/>
        <tag key="creation_time" value="2010-02-09T01:55:39.000000Z"/>
    </format>
</ffprobe>
n="1.0" encoding="UTF-8"?>
<ffprobe>
    <format filename="b.mp4" nb_streams="4" nb_programs="0" format_name="mov,mp4,m4a,3gp,3g2,mj2" format_long_name="QuickTime / MOV" start_time="0.000000" duration="60.095000" size="5510872" bit_rate="733621" probe_score="100">
        <tag key="major_brand" value="mp42"/>
        <tag key="minor_version" value="1"/>
        <tag key="compatible_brands" value="mp42avc1"/>
        <tag key="creation_time" value="2010-02-09T01:55:39.000000Z"/>
    </format>
???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

Correct output is:

<?xml version="1.0" encoding="UTF-8"?>
<ffprobe>
    <format filename="b.mp4" nb_streams="4" nb_programs="0" format_name="mov,mp4,m4a,3gp,3g2,mj2" format_long_name="QuickTime / MOV" start_time="0.000000" duration="60.095000" size="5510872" bit_rate="733621" probe_score="100">
        <tag key="major_brand" value="mp42"/>
        <tag key="minor_version" value="1"/>
        <tag key="compatible_brands" value="mp42avc1"/>
        <tag key="creation_time" value="2010-02-09T01:55:39.000000Z"/>
    </format>
</ffprobe>