0

Xamarin.MP4Transcoder.Transcoder를 사용하여 비디오를 640 * 480 해상도로 코드 변환해야합니다. 현재 720pFormat 및 960x540Format의 2 가지 해상도가 있습니다. Transcoder 클래스에서 사용할 수있는 Transcoder For (IMediaFormatStrategy strategy)이라는 메서드가 있습니다. 나는 아래로 MediaFormat의 MIME 타입, 폭 객체와 높이 를 만들 수 있습니다Xamarin.MP4Transcoder.Transcoder를 사용하여 비디오를 사용자 지정 해상도로 변환하는 방법

는 코드 언급 :

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

필자도 비슷한 일을해야했습니다. 운좋게도 자바에서 어떻게 만들어 졌는지를 알았고, 그걸 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을 변경하고, 분명, 그것을 위해 새로운 클래스를 만들 수 있습니다. 아마도 두 가지 길이의 일반 클래스를 만들 수도 있지만 아직 필요하지 않습니다.

Link to the Java code