0

I am using ffmpeg for rotating a video 90 degree so input this code

ffmpeg -i in.mp4 -vf "transcode=1" out.mp4

This is so slow like re-encoding. I added -c copy to make it fast but I have had an error that two function can't use at same time.

ffmpeg -i in.mp4 -c copy -vf "transcode=1" out.mp4
makgun
  • 357

3 Answers3

4

The reason it's slow is not because of the rotation, it's because you reencode the video.

When you don't specify an output video codec, the default for mp4 is H.264 (libx264) preset medium, which depending on the resolution and your hardware, can be slow.

I see you try to go around that by specifying "-c copy", but you can't : rotating the video means modifying it, so there's no way can just copy the H.264 stream. Reencoding is not an option in your case.

You can try with one of the faster presets :

ffmpeg -i in.mp4 -vf "transcode=1" -vcodec libx264 -preset veryfast -acodec copy out.mp4

But the quality/filesize will suffer.

See https://stackoverflow.com/questions/25031557/rotate-mp4-videos-without-re-encoding, there's an interesting answer about changing the metadata so that players can rotate the video.

Ely
  • 2,973
  • 20
  • 17
2
ffmpeg -i in.mp4 -c copy -metadata:s:v:0 rotate=90 out.mp4

That's worked for me but not work all video player. But it is so fast than other commands. It just change the rotate flag. (Note special angle can't work with this).

makgun
  • 357
1

I'm suggesting rotate instead of transcode.

ffmpeg -i input_video -vf "rotate=PI/2" output_video

Also see here and here for more information.

Hope this helps!

Chamath
  • 522