3

I'm developing upload video (taken from iPhone) to my server.

However, I have no idea how to implement.

Any source code objective-c or swift will be welcomed.

I have 120fps or 240fps video (It's a slo-mo). When I playback these video on my iPhone6. I can see slo-mo effect. (I know playback frame rate is 30fps.)

I want to convert that video before upload to my server, from 120/240 fps to 30fps video. (I mean not adjusting playback frame rate, it means video transcode to 30fps.) Additionally, I want to check slo-mo effect start-point and end-point. (Maybe iPhone record this information to video binary(it might be reside in file's header.)

Well, I guess if I use ffmpeg library, it should be easy(?).

So any suggestions will be welcomed.

qubodup
  • 8,687
  • 5
  • 37
  • 45
coverboy
  • 51
  • 1
  • 10

2 Answers2

4

Here are ffmpeg command lines I use to import into Adobe Premiere:

Video:

ffmpeg -i <input MOV> -filter "setpts=4.0*PTS" -r 30 -an videofilename.mp4

4.0 in -filter means that the iphone slomo video was shot at 120fps, i.e. 4 × 30fps; the related -r 30 parameter is for 30fps. For example if you want to export as 60fps, use setpts="2.0*PTS" -r 60

-an discards the audio stream

Audio:

ffmpeg -i <input MOV> -filter "setpts=4.0*PTS" audiofilename.mp3

At this point you have the video and audio streams in separate files. You can probably use ffmpeg to recombine them.

But there's a catch: the iPhone will record the audio stream at normal speed, meaning the converted sound track will be 4 times (in my example) shorter than the converted video track. if you use Premiere, import both video and audio files, right click on the sound track in your timeline, choose "Speed/Duration", and set speed=25% (or 50% for 120fps to 60fps)

Community
  • 1
  • 1
1

For 120fps footage with 44100 audio sample rate:

ffmpeg -i in.MOV -filter_complex "[0:v]setpts=4.0*PTS[v];[0:a]asetrate=11025,aresample=44100[a]" \
-map "[v]" -map "[a]" -r 30 out.mp4

For 240fps footage with 44100 audio sample rate:

ffmpeg -i in.MOV -filter_complex "[0:v]setpts=8.0*PTS[v];[0:a]asetrate=5512.5,aresample=44100[a]" \
-map "[v]" -map "[a]" -r 30 out.mp4

For 240fps footage with 48000 audio sample rate:

ffmpeg -i in.MOV -filter_complex "[0:v]setpts=8.0*PTS[v];[0:a]asetrate=6000,aresample=48000[a]" \
-map "[v]" -map "[a]" -r 30 out.mp4

The quality of the resulting video will be low. Increasing quality is a science in itself https://trac.ffmpeg.org/wiki/Encode/H.264 currently the -crf parameter (with a low number in the 0–63 range) seems to be the simplest way to increase quality (at the price of file size and encoding time). For example, use -crf 18 before out.mp4

Based on FFMPEG documentation: https://trac.ffmpeg.org/wiki/How%20to%20speed%20up%20/%20slow%20down%20a%20video

With the help of https://superuser.com/questions/292833/how-to-change-audio-frequency for the audio slowdown (chaining atempo=2.0,atempo=2.0 gives a horrible-sounding result).

qubodup
  • 8,687
  • 5
  • 37
  • 45