User Tools

Site Tools


ubuntu:video:rotate_videos_with_ffmpeg

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
ubuntu:video:rotate_videos_with_ffmpeg [2020/02/13 00:02] – created peterubuntu:video:rotate_videos_with_ffmpeg [2023/06/06 18:30] (current) peter
Line 1: Line 1:
 ====== Ubuntu - Video - Rotate Videos with FFmpeg ====== ====== Ubuntu - Video - Rotate Videos with FFmpeg ======
 +
 +===== Software Encoding =====
  
 <code bash> <code bash>
 ffmpeg -i in.mov -vf "transpose=1" out.mov ffmpeg -i in.mov -vf "transpose=1" out.mov
 </code> </code>
 +
 +<WRAP info>
 +**NOTE:**  This will re-encode the audio and video parts.
 +
 +  * You can usually copy the audio without touching it, by using **-c:a copy**.
 +  * To change the video quality, set the bitrate (for example with **-b:v 1M**) or have a look at the H.264 encoding guide if you want VBR options.
 +
  
 For the transpose parameter you can pass: For the transpose parameter you can pass:
Line 13: Line 22:
  
 Use **-vf "transpose=2,transpose=2"** for 180 degrees. Use **-vf "transpose=2,transpose=2"** for 180 degrees.
 +
 +</WRAP>
  
 ---- ----
  
-Running +If you don't want to re-encode your video AND your player can handle rotation metadata you can just change the rotation in the metadata using ffmpeg:
  
 <code bash> <code bash>
-ffmpeg -filters +ffmpeg -i input.m4v -metadata:s:v rotate="90" -codec copy output.m4v
 </code> </code>
  
-shows this:+Check the rotate metadata first with: 
 + 
 +<code bash> 
 +ffmpeg -i input.m4v 2>&1 | grep rotate 
 +</code> 
 + 
 +---- 
 + 
 +To rotate the picture clockwise you can use the rotate filter, indicating a positive angle in radians. With 90 degrees equating with PI/2, you can do it like so: 
 + 
 +<code bash> 
 +ffmpeg -i in.mp4 -vf "rotate=PI/2" out.mp4 
 +</code> 
 + 
 +for counter-clockwise the angle must be negative 
 + 
 +<code bash> 
 +ffmpeg -i in.mp4 -vf "rotate=-PI/2" out.mp4 
 +</code> 
 + 
 + 
 +It is possible to get finer-grained resolution of radians, because * behaves as multiplication: 
 + 
 +<code bash> 
 +ffmpeg -i in.avi -vf "rotate=-8*PI/40" -q 1 out.avi  
 +</code> 
 + 
 +(slightly less rotation than -PI/4 = -10*PI/40 
 + 
 + 
 +---- 
 + 
 +===== Determine filters supported by ffmpeg ===== 
 + 
 +Other filters that can be used. 
 + 
 +<code bash> 
 +ffmpeg -filters  
 +</code>
  
 +returns:
  
 <code> <code>
Line 433: Line 483:
  
  
----- 
- 
-<code> 
-Filters: 
-anull            Pass the source unchanged to the output. 
-aspect           Set the frame aspect ratio. 
-crop             Crop the input video to x:y:width:height. 
-fifo             Buffer input images and send them when they are requested. 
-format           Convert the input video to one of the specified pixel formats. 
-hflip            Horizontally flip the input video. 
-noformat         Force libavfilter not to use any of the specified pixel formats 
- for the input to the next filter. 
-null             Pass the source unchanged to the output. 
-pad              Pad input image to width:height[:x:y[:color]] (default x and y: 
- 0, default color: black). 
-pixdesctest      Test pixel format definitions. 
-pixelaspect      Set the pixel aspect ratio. 
-scale            Scale the input video to width:height size and/or convert the i 
-mage format. 
-slicify          Pass the images of input video on to next video filter as multi 
-ple slices. 
-unsharp          Sharpen or blur the input video. 
-vflip            Flip the input video vertically. 
-buffer           Buffer video frames, and make them accessible to the filterchai 
-n. 
-color            Provide an uniformly colored input, syntax is: [color[:size[:ra 
-te]]] 
-nullsrc          Null video source, never return images. 
-nullsink         Do absolutely nothing with the input video. 
-</code> 
ubuntu/video/rotate_videos_with_ffmpeg.1581552127.txt.gz · Last modified: 2020/07/15 09:30 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki