0

Xamarin.MP4Transcoder.Transcoderを使用してビデオを640 * 480解像度にトランスコードする必要があります。現在、720pFormatと960x540Formatの2つの解像度が利用可能です。 TranscoderクラスにはTranscoder For (IMediaFormatStrategy strategy)というメソッドがあります。Xamarin.MP4Transcoder.Transcoderを使用してビデオをカスタム解像度にトランスコードする方法

私は以下のことでMIMEタイプ、幅と高さ でMediaFormatオブジェクトを作成することができますが、コードスニペットを述べた:

MediaFormat obj = MediaFormat.CreateVideoFormat("video/mp4", 480, 640);


が、問題はIMediaFormatStrategyに割り当てることができる方法であるか、いずれかがありますこれを達成する他の方法。詳細情報については

Piece of code for Transcoding a video: 
 

 
Xamarin.MP4Transcoder.Transcoder.For960x540Format().ConvertAsync(inputFile, outputFile, f =>
 \t \t \t \t {
 \t \t \t \t onProgress?.Invoke((int)(f * (double)100), 100);

 \t \t \t \t 
 \t \t \t \t }); 
 

 
inputFile: Video file which needs to be transcoded. 
 
outputFile: Resultant file generated after transcoding.

あなたはすべてのヘルプは高く評価されhttps://github.com/neurospeech/xamarin-android-ffmpeg

を参照することができます。前もって感謝します!!

答えて

0

私は似たようなことをしなければならず、幸いにもそれがJavaでどのように作成されたのかを見つけ出し、それをC#に変換しなければなりませんでした。 (640×360用)

結果のクラスは次のようになります。

public class For640x360Format : Java.Lang.Object, IMediaFormatStrategy 
{ 
    public static int AUDIO_BITRATE_AS_IS = -1; 
    public static int AUDIO_CHANNELS_AS_IS = -1; 
    static String TAG = "640x360FormatStrategy"; 
    static int LONGER_LENGTH = 640; 
    static int SHORTER_LENGTH = 360; 
    static int DEFAULT_VIDEO_BITRATE = 8000 * 1000; // From Nexus 4 Camera in 720p 
    int mVideoBitrate; 
    int mAudioBitrate; 
    int mAudioChannels; 

    public For640x360Format() 
    { 
     mVideoBitrate = DEFAULT_VIDEO_BITRATE; 
     mAudioBitrate = AUDIO_BITRATE_AS_IS; 
     mAudioChannels = AUDIO_CHANNELS_AS_IS; 
    } 

    public For640x360Format (int videoBitrate) 
    { 
     mVideoBitrate = videoBitrate; 
     mAudioBitrate = AUDIO_BITRATE_AS_IS; 
     mAudioChannels = AUDIO_CHANNELS_AS_IS; 
    } 

    public For640x360Format (int videoBitrate, int audioBitrate, int audioChannels) 
    { 
     mVideoBitrate = videoBitrate; 
     mAudioBitrate = audioBitrate; 
     mAudioChannels = audioChannels; 
    } 

    public MediaFormat CreateAudioOutputFormat (MediaFormat inputFormat) 
    { 
     if (mAudioBitrate == AUDIO_BITRATE_AS_IS || mAudioChannels == AUDIO_CHANNELS_AS_IS) return null; 

     // Use original sample rate, as resampling is not supported yet. 
     MediaFormat format = MediaFormat.CreateAudioFormat (MediaFormatExtraConstants.MimetypeAudioAac, 
                  inputFormat.GetInteger (MediaFormat.KeySampleRate), 
                  mAudioChannels); 
     // this is obsolete: MediaCodecInfo.CodecProfileLevel.AACObjectLC, so using MediaCodecProfileType.Aacobjectlc instead 
     format.SetInteger (MediaFormat.KeyAacProfile, (int)MediaCodecProfileType.Aacobjectlc); 
     format.SetInteger (MediaFormat.KeyBitRate, mAudioBitrate); 
     return format; 
    } 

    public MediaFormat CreateVideoOutputFormat (MediaFormat inputFormat) 
    { 
     int width = inputFormat.GetInteger (MediaFormat.KeyWidth); 
     int height = inputFormat.GetInteger (MediaFormat.KeyHeight); 
     int longer, shorter, outWidth, outHeight; 

     if (width >= height) 
     { 
      longer = width; 
      shorter = height; 
      outWidth = LONGER_LENGTH; 
      outHeight = SHORTER_LENGTH; 
     } 
     else 
     { 
      shorter = width; 
      longer = height; 
      outWidth = SHORTER_LENGTH; 
      outHeight = LONGER_LENGTH; 
     } 

     if (longer * 9 != shorter * 16) 
     { 
      throw new OutputFormatUnavailableException ("This video is not 16:9, and is not able to transcode. (" + width + "x" + height + ")"); 
     } 
     if (shorter <= SHORTER_LENGTH) 
     { 
      #if DEBUG 
      Console.WriteLine ("This video is less or equal to 720p, pass-through. (" + width + "x" + height + ")"); 
      #endif 

      return null; 
     } 

     MediaFormat format = MediaFormat.CreateVideoFormat ("video/avc", outWidth, outHeight); 
     format.SetInteger (MediaFormat.KeyBitRate, mVideoBitrate); 
     format.SetInteger (MediaFormat.KeyFrameRate, 30); 
     format.SetInteger (MediaFormat.KeyIFrameInterval, 3); 
     // this is obsolete: MediaCodecInfo.CodecCapabilities.COLORFormatSurface, so using MediaCodecCapabilities.Formatsurface instead 
     format.SetInteger (MediaFormat.KeyColorFormat, (int)MediaCodecCapabilities.Formatsurface); 

     return format; 
    } 
} 

はちょうどあなたが必要とするものは何でも解決にLONGER_LENGTHとSHORTER_LENGTHを変更すると、明らかに、それのために新しいクラスを作成します。 おそらく2つの長さを取るジェネリッククラスを作ることもできますが、私はそれをまだ必要としていません。

Link to the Java code

関連する問題