How to trim a file using FFMpeg programmatically? (libavformat, avutils, ...)

I am creating an iOS application that requires re-encoding and cropping video in the background.

I can’t use iOS libraries (AVFoundation), since they rely on the GPU, and no application can access the GPU if it is set.

Due to this problem, I switched to FFMpeg and compiled it (along with libx264) and integrated it into my iOS application.

To summarize what I need:

  • Trim video in the first 10 seconds
  • zoom out video

After a couple of weeks - and quite often I hit my head against the wall - I managed:

  • split the video container into streams (demuxing)
  • copy the audio stream to the output stream (without decoding or encoding)
  • , , ( h264, , h264)

ffmpeg , :

ffmpeg -i input.MOV -ss 0 -t 10  -vf scale=320:240 -c:v libx264 -preset ultrafast -c:a copy output.mkv

, ? , /, FPS , , , .

- - , 10 ( ) .

AV?

+4
1

, ffmpeg:

ffmpeg -i input.MOV -filter_complex [0:v]trim=duration=10.0,scale=320:240[vid];[0:a]atrim=duration=10.0[aud] -map [vid] -map [aud] -c:v libx264 -preset ultrafast -c:a libvo_aacenc -b:a 128k -flags +aic+mv4 output.mkv
-1

Source: https://habr.com/ru/post/1624342/


All Articles