菜鸟教程小白 发表于 2022-12-11 16:44:10

ios - 将 .MOV 转换为 .MP4,同时从图库中选择或从相机录制


                                            <p><p>当我从图库中选择一个视频时,我选择的文件扩展名为 .MOV,因此想将其转换为 .MP4 进行研究,但在这种情况下不知道如何做到这一点。如果你有任何想法,请帮忙。</p>

<pre><code>   - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{

    selectedVideoURL = info;
if( == UIImagePickerControllerSourceTypeCamera )
{
    NSURL *videoURL=info;
    ALAssetsLibrary *library = [init];
    [library writeVideoAtPathToSavedPhotosAlbum:videoURL completionBlock:^(NSURL *assetURL, NSError *error )
   {
         //here is your URL : assetURL
         NSLog(@&#34;url is%@&#34;,assetURL);

   // here in debugger it shows asassets.MOVi want .MP4

         PHFetchResult&lt;PHAsset*&gt; *assets =
                                                                     options:nil];

         PHAsset *asset1 = assets.firstObject;
         [ requestAVAssetForVideo:asset1 options:nil resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) {
             if (]) {
               AVURLAsset* urlAsset = (AVURLAsset*)asset;
               NSNumber *size;

               ;
               NSLog(@&#34;size video of camera %f&#34;,/(1024.0*1024.0)); //size is 43.703005
               NSData *data = ;
               NSLog(@&#34;length of camera %f&#34;,/(1024.0*1024.0)); // data size is 43.703005

               sizeofVideo=/(1024.0*1024.0);

               NSLog(@&#34;sizeofVideo arvin %f&#34;,sizeofVideo);
               if (!sizeofVideo&gt;50.00) {
                     selectedVideoURL=nil;
                     UIAlertView *alert=[initWithTitle:@&#34;Alert&#34; message:@&#34;size of video exist 50MB&#34; delegate:self cancelButtonTitle:@&#34;ok&#34; otherButtonTitles:nil];
                     ;
                     attachnoteLbl.text=;
               }
                     attachnoteLbl.text=;

             }
         }];
   }];
}
</code></pre>

<p>我尝试了以下方法,将文件扩展名从 .MOV 删除为 .MP4,但没有成功。所以我认为只有在从图库或相机中选择时才需要在乞求中转换它。</p>

<pre><code>-(void)afnetworking{

   NSString *videoUrl=;
   if(videoUrl){
    NSString *videoName = [stringByDeletingPathExtension];
    NSData *videoData= ;
    dataUsingEncoding:NSUTF8StringEncoding]];
    NSString *tmpfileinfo = ;
    ];
    ];
    ];

}
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>查看这个库。希望这可以解决您的问题。 <a href="https://github.com/Darktt/DTVideoConverter" rel="noreferrer noopener nofollow">https://github.com/Darktt/DTVideoConverter</a> </p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 将 .MOV 转换为 .MP4,同时从图库中选择或从相机录制,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/37832277/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/37832277/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 将 .MOV 转换为 .MP4,同时从图库中选择或从相机录制