Overview

jMediaHandler is ASP.NET Core video encoder utility that can help you publish any format video to another format.

This page provide detail example how to publish videos to mp4 format and apply meta information.

jMediaHandler Built-in Project Example

Example: Publish 360p MP4

    {
        "sourceFile": "intro_102.mp4",
        "publishFile": "intro_102_pub.mp4",
        "ffmpegCommand": "-s 640x380 -c:v libx264 -preset medium -crf 22 -b:v 500k -b:a 128k -profile:v baseline -level 3.1",
        "outputExtension": ".mp4"
    }

Prepare mp4 video for web by applying meta information.

    {
        "sourceFile": "intro_102.mp4",
        "publishFile": "intro_102_pub.mp4",
        "ffmpegCommand": "-s 640x380 -c:v libx264 -preset medium -crf 22 -b:v 500k -b:a 128k -profile:v baseline -level 3.1",
        "outputExtension": ".mp4",
        "applyMeta": true
    }

Enable generate thumbnails to allow script to grab multiple thumbnails from start to end of video.

    {
        "sourceFile": "intro_102.mp4",
        "publishFile": "intro_102_pub.mp4",
        "ffmpegCommand": "-s 640x380 -c:v libx264 -preset medium -crf 22 -b:v 500k -b:a 128k -profile:v baseline -level 3.1",
        "outputExtension": ".mp4",
        "generateThumbnails": true,
    }

Some useful commands to publish mp4 video to 480p, 720p, 1080p formats.

    // command to publish 480p mp4 video 
    "ffmpegCommand": "-s 854x480 -c:v libx264 -preset fast -crf 22 -b:v 1000k -b:a 128k -profile:v baseline -level 3.1" 
    // command to publish 720p mp4 video 
    "ffmpegCommand": "-s 1280x720 -c:v libx264 -preset fast -crf 22 -b:v 5000k -b:a 128k -profile:v baseline -level 3.1" 
    // command to publish 1080p mp4 video 
    "ffmpegCommand": "-s 1920x1080 -c:v libx264 -preset fast -crf 22 -b:v 8000k -b:a 128k -profile:v baseline -level 3.1"

jMediaHandler Core Example

    var _mhandler = new MediaHandler();
     _mhandler.FFMPEGPath = "{ffmpeg_binary_path}";
     _mhandler.InputPath = "{source_video_directory_path}";
     _mhandler.OutputPath = "{published_video_directory_path}";
     _mhandler.BackgroundProcessing = true;
     _mhandler.FileName = "sample.wmv"; // source filename
     _mhandler.OutputFileName = "sample_"; // publish video filename without extension
     _mhandler.Parameters = "-s 640x380 -c:v libx264 -preset medium -crf 22 -b:v 500k -b:a 128k -profile:v baseline -level 3.1";
     _mhandler.OutputExtension = ".mp4";
    _mhandler.vinfo = _mhandler.ProcessMedia();
     if (_mhandler.vinfo.ErrorCode > 0)
     {
         // error occured 
         var error_code = _mhandler.vinfo.ErrorCode.ToString();
         var error_desc = _mhandler.vinfo.FFMPEGOutput.ToString();
         var error_message = _mhandler.vinfo.ErrorMessage;
     }
     else 
     {
         // video published successfully 
         
         // fetch published video information
         var video_information = _mhandler.vinfo; 
     }

Articles