Answers.Body: <p>You have specified that you are interested in working on a huge number of videos, if you have a multicore machine and you will use a normal <code>for</code> loop provided by your shell, you will have one of your cores running hot, while others are doing absolutely nothing. This is <em>not</em> ideal.</p>
  
  <p>What you should be doing for such a job is using <code>parallel</code>, a tool that allows you to start several jobs at once, and it can do everything that a for-loop can, but better.</p>
  
  <p>I will not write about all the features of this tool, but will concentrate on your specific task.</p>
  
  <p>One way to start all these jobs would be:</p>
  
  <pre><code>parallel avconv -i "{}" -vf transpose=2 "{.}[rotated].mp4" ::: *.mp4
  </code></pre>
  
  <p>In here <code>{}</code> replaces each filename, and <code>{.}</code> replaces filename without an extension.</p>
  
  <p>I will suggest that you will start as many jobs as you have cores, take away one. The reason for that is so your operating system will still remain useable, and also this will save you in case if you are using harddisk encryption (which will be using processing power to read/write data). To do this simply add <code>--jobs -1</code> to your command line, and you will limit the number of jobs.</p>
  
  <pre><code>parallel --jobs -1 avconv -i "{}" -vf transpose=2 "{.}[rotated].mp4" ::: *.mp4
  </code></pre>
  
  <p>Please keep in mind that no output will be given until each encoding completes. So you will not see just how much of each of your video is done.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-27T11:07:44.840Z
Answers.LastActivityDate: 2015-04-27T11:17:11.060Z
Answers.LastEditDate: 2015-04-27T11:17:11.060Z
Answers.UserDisplayName: v010dya
Answers.Body: <p>Based on <a href="https://stackoverflow.com/questions/3937387/rotating-videos-with-ffmpeg">this answer</a> you can use ffmpeg with following commands to rotate a video: </p>
  
  <pre><code>ffmpeg -i input -vf transpose=2 output
  </code></pre>
  
  <p>To Batch process a folder of movies you can use a programming language of your choice and iterate through the files. I've used linux with python 2.7+ here. You only have to edit <code>folder_movies</code> path, <code>path_to_ffmpeg</code> and set
  your movie <code>extension</code>:</p>
  
  <pre class="lang-py prettyprint-override"><code>import os # import os module
  import subprocess # import subprocess module
  
  # set the path to your video folder
  folder_movies = '/home/user/Desktop/test/'
  
  # set ffmpeg path
  path_to_ffmpeg = "/opt/ffmpeg/ffmpeg"
  
  # set file extension
  ext = ".mp4"
  
  # collect all videos in folder_movies
  movie_files = [f for f in os.listdir(folder_movies) if f.endswith(ext)] 
  
  # iterate through the files
  for i in movie_files:
  
      # setup correct filepath for mov's
      file_path = os.path.join(folder_movies,i)
  
      # generate new file path
      new_path = os.path.splitext(file_path)[0] + '_rotated_90' + ext
  
      # call ffmpeg with the correct arguments
      # command: ffmpeg -i input -vf transpose=2 output
      subprocess.call([path_to_ffmpeg, "-i",  file_path, "-vf", "transpose=2", "-c:a", "copy", new_path])
  </code></pre>
  
  <p>Afterwards your movie folder should looks like:</p>
  
  <p><img src="https://i.sstatic.net/tpl0h.png" alt="enter image description here"></p>
  
  <p>The advantage of using python is that the code runs <strong>cross platform</strong>. The only thing you need to consider are the paths to the directory and the ffmpeg executable. In order to run this on a <strong>windows machine</strong> you only have to replace the paths to something like:</p>
  
  <pre class="lang-py prettyprint-override"><code># folder_movies = '/home/user/Desktop/test/' # linux or osx
  folder_movies = r'c:\some\directory\test'    # windows, the r is important
  folder_movies = 'c:/some/directory\test'     # windows (alternative)
  
  # path_to_ffmpeg = '/opt/ffmpeg/ffmpeg'            # linux or osx
  path_to_ffmpeg = r'c:\Program Files\ffmpeg\ffmpeg' # windows, the r is important
  path_to_ffmpeg = 'c:/Program Files/ffmpeg\ffmpeg'  # windows (alternative)
  </code></pre>
  
  <p><strong>Note:</strong> I'm not a ffmpeg expert, maybe there is a way to batch process with it directly.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-23T17:48:32.210Z
Answers.Text: You don't really need a whole script for this. It can be done directly on the Mac or Linux command-line with something like : `mkdir -p rotated; for f in *.mp4; do ffmpeg -i "$f" -vf transpose=2 rotated/"$f"; done` (assuming your video files are .mp4 in this example).
Answers.UserDisplayName: mivk
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-24T07:17:05.173Z
Answers.Text: @mivk nice, why not converting this to an answer?
Answers.UserDisplayName: p2or
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-05T11:54:41.853Z
Answers.Text: @mivk Since you are using a for loop it's nearly the same. For those who don't use linux or osx, it makes sense to use python or another scripting language.
Answers.UserDisplayName: p2or
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-05T16:51:35.097Z
Answers.Text: @poor : well, for those users who are neither on linux nor on mac, the translation into PowerShell is "left as an exercise for the reader"... :-)
Answers.UserDisplayName: mivk
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-05T16:53:50.730Z
Answers.Text: @mivk hehe, yeah, but no one wants to use it ;)
Answers.UserDisplayName: p2or
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-02T19:53:20.597Z
Answers.Text: @mivk : Well, I had to, so here's the implementation for powershell. 
  Get-ChildItem "." -Filter *.mp4 | Foreach-Object { ffmpeg.exe -i "$_" -vf transpose=2 -c:a copy -metadata:s:v rotate="" rotated/"$_" }
Answers.UserDisplayName: PvB
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-23T17:37:52.023Z
Answers.LastActivityDate: 2015-06-05T11:48:57.117Z
Answers.LastEditDate: 2017-05-23T12:40:36.170Z
Answers.UserDisplayName: p2or
Answers.Body: <p>This worked for me.  create a batch file.  Make a directory called output in your videos directory.  Also put a copy of ffmpeg.exe in the directory.  You can get ffmpeg download with google.  it is a zip file, you just need ffmpeg.exe.</p>
  <p>Run the batch file and wait.</p>
  <pre><code>for %%a in (&quot;*.mp4&quot;) do ffmpeg -i &quot;%%a&quot; -vf transpose=2 -c:a copy -metadata:s:v rotate=&quot;&quot; &quot;output\%%~na.mp4&quot;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-02-06T03:12:33.273Z
Answers.LastActivityDate: 2023-02-06T17:00:57.560Z
Answers.LastEditDate: 2023-02-06T17:00:57.560Z
Answers.UserDisplayName: user40517
Answers.Body: <p>Use <code>ffmpeg</code> and the <a href="https://ffmpeg.org/ffmpeg-filters.html#transpose" rel="nofollow noreferrer">"transpose" filter</a> as <a href="https://video.stackexchange.com/a/15405/3138">"poor" suggested</a>. For example, if your files are mp4 and are in the current directory:</p>
  
  <pre class="lang-bash prettyprint-override"><code>mkdir -p rotated
  for f in *.mp4; do ffmpeg -i "$f" -vf transpose=2 -c:a copy -metadata:s:v rotate="" rotated/"$f"; done
  </code></pre>
  
  <ul>
  <li><p>The transpose value can be "1" or "clock" for clockwise rotation, "2" or "cclock" for counter-clockwise rotation. There are other values which will also apply a flip.</p></li>
  <li><p>The audio will be <a href="https://ffmpeg.org/ffmpeg.html#Stream-copy" rel="nofollow noreferrer">stream copied</a> to avoid unnecessary re-encoding.</p></li>
  <li><p>The video stream rotation metadata is cleared in this example. Otherwise <code>ffmpeg</code> will copy it from the input to the output resulting in an incorrect rotation for players that pay attention to this metadata (some do, and some don't).</p></li>
  </ul>
  
  <p>Another example, more verbose and flexible, and which keeps the rotated file in the same directory with a new name:</p>
  
  <pre class="lang-bash prettyprint-override"><code>ext=mp4
  for f in /some/dir/*.$ext; do
      new=${f/%.$ext/-rotated.$ext};
      ffmpeg -i "$f" -vf transpose=2 -c:a copy -metadata:s:v rotate="" "$new"
  done
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-24T18:57:08.977Z
Answers.Text: Yes! I should learn more about bash scripting :)
Answers.UserDisplayName: p2or
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-24T15:09:08.047Z
Answers.LastActivityDate: 2015-05-13T00:01:56.163Z
Answers.LastEditDate: 2017-04-13T12:46:08.110Z
Answers.UserDisplayName: mivk
Body: <p>I have approximately 3000 short video clips, each about 3 seconds in duration. I need to rotate each of them 90 degrees. What is the best way to do this? I have Adobe Creative Cloud subscription, as well as access to both Windows and Mac machines. Looking for the easiest solution to automate/batch process the rotation of so many videos.</p>
  
  <p>If you were wondering - the videos are part of an e-learning course on lumber. The learner views each randomly selected video, which is just a short clip of a piece of lumber rotating. The videos were shot so that the lumber (2x4s, etc.) were horizontal. But now the client wants the lumber to be vertical in the clips.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-04-22T12:11:28.843Z
Comments.Text: Only rotation? From e.g. 1280x720 to 720x1280 right?
Comments.UserDisplayName: p2or
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-04-22T15:49:17.330Z
Comments.Text: Just rotation 90 degrees clockwise (or counter cw - doesn't matter for this project).
Comments.UserDisplayName: user172586
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-04-23T08:41:53.703Z
Comments.Text: Does the container of your video files includes an 'orientation' metadata ?
Comments.UserDisplayName: audionuma
Tags: <video>
Title: Best way to batch rotate 3000+ h.264 videos?
UserDisplayName: user172586
ThreadText: # Best way to batch rotate 3000+ h.264 videos?
  
  (Asked by: username_0 on 2015-04-21)
  
  I have approximately 3000 short video clips, each about 3 seconds in duration. I need to rotate each of them 90 degrees. What is the best way to do this? I have Adobe Creative Cloud subscription, as well as access to both Windows and Mac machines. Looking for the easiest solution to automate/batch process the rotation of so many videos.
  
  If you were wondering - the videos are part of an e-learning course on lumber. The learner views each randomly selected video, which is just a short clip of a piece of lumber rotating. The videos were shot so that the lumber (2x4s, etc.) were horizontal. But now the client wants the lumber to be vertical in the clips.
  
  **Tags:** video
  
  > **Comments:**
  > **username_1**: Only rotation? From e.g. 1280x720 to 720x1280 right?  
  > **username_0**: Just rotation 90 degrees clockwise (or counter cw - doesn't matter for this project).  
  > **username_2**: Does the container of your video files includes an 'orientation' metadata ?  
  
  ---
  
  ## 4 answers
  
  ### Answer by username_4 on 2015-04-24. Score: 11 | Accepted answer
  
  Use `ffmpeg` and the ["transpose" filter](https://ffmpeg.org/ffmpeg-filters.html#transpose) as ["poor" suggested](https://video.stackexchange.com/a/15405/3138). For example, if your files are mp4 and are in the current directory:
  
  ```bash
  mkdir -p rotated
  for f in *.mp4; do ffmpeg -i "$f" -vf transpose=2 -c:a copy -metadata:s:v rotate="" rotated/"$f"; done
  
  ```
  
  * The transpose value can be "1" or "clock" for clockwise rotation, "2" or "cclock" for counter-clockwise rotation. There are other values which will also apply a flip.
  * The audio will be [stream copied](https://ffmpeg.org/ffmpeg.html#Stream-copy) to avoid unnecessary re-encoding.
  * The video stream rotation metadata is cleared in this example. Otherwise `ffmpeg` will copy it from the input to the output resulting in an incorrect rotation for players that pay attention to this metadata (some do, and some don't).
  
  Another example, more verbose and flexible, and which keeps the rotated file in the same directory with a new name:
  
  ```bash
  ext=mp4
  for f in /some/dir/*.$ext; do
      new=${f/%.$ext/-rotated.$ext};
      ffmpeg -i "$f" -vf transpose=2 -c:a copy -metadata:s:v rotate="" "$new"
  done
  
  ```
  
  > **Comments:**
  > **username_1**: Yes! I should learn more about bash scripting :)  
  
  ---
  
  ### Answer by username_3 on 2015-04-27. Score: 1
  
  You have specified that you are interested in working on a huge number of videos, if you have a multicore machine and you will use a normal `for` loop provided by your shell, you will have one of your cores running hot, while others are doing absolutely nothing. This is *not* ideal.
  
  What you should be doing for such a job is using `parallel`, a tool that allows you to start several jobs at once, and it can do everything that a for-loop can, but better.
  
  I will not write about all the features of this tool, but will concentrate on your specific task.
  
  One way to start all these jobs would be:
  
  ```
  parallel avconv -i "{}" -vf transpose=2 "{.}[rotated].mp4" ::: *.mp4
  
  ```
  
  In here `{}` replaces each filename, and `{.}` replaces filename without an extension.
  
  I will suggest that you will start as many jobs as you have cores, take away one. The reason for that is so your operating system will still remain useable, and also this will save you in case if you are using harddisk encryption (which will be using processing power to read/write data). To do this simply add `--jobs -1` to your command line, and you will limit the number of jobs.
  
  ```
  parallel --jobs -1 avconv -i "{}" -vf transpose=2 "{.}[rotated].mp4" ::: *.mp4
  
  ```
  
  Please keep in mind that no output will be given until each encoding completes. So you will not see just how much of each of your video is done.
  
  
  ---
  
  ### Answer by username_1 on 2015-04-23. Score: 1
  
  Based on [this answer](https://stackoverflow.com/questions/3937387/rotating-videos-with-ffmpeg) you can use ffmpeg with following commands to rotate a video:
  
  ```
  ffmpeg -i input -vf transpose=2 output
  
  ```
  
  To Batch process a folder of movies you can use a programming language of your choice and iterate through the files. I've used linux with python 2.7+ here. You only have to edit `folder_movies` path, `path_to_ffmpeg` and set
  your movie `extension`:
  
  ```py
  import os # import os module
  import subprocess # import subprocess module
  
  # set the path to your video folder
  folder_movies = '/home/user/Desktop/test/'
  
  # set ffmpeg path
  path_to_ffmpeg = "/opt/ffmpeg/ffmpeg"
  
  # set file extension
  ext = ".mp4"
  
  # collect all videos in folder_movies
  movie_files = [f for f in os.listdir(folder_movies) if f.endswith(ext)] 
  
  # iterate through the files
  for i in movie_files:
  
      # setup correct filepath for mov's
      file_path = os.path.join(folder_movies,i)
  
      # generate new file path
      new_path = os.path.splitext(file_path)[0] + '_rotated_90' + ext
  
      # call ffmpeg with the correct arguments
      # command: ffmpeg -i input -vf transpose=2 output
      subprocess.call([path_to_ffmpeg, "-i",  file_path, "-vf", "transpose=2", "-c:a", "copy", new_path])
  
  ```
  
  Afterwards your movie folder should looks like:
  
  ![enter image description here](https://i.sstatic.net/tpl0h.png)
  
  The advantage of using python is that the code runs **cross platform**. The only thing you need to consider are the paths to the directory and the ffmpeg executable. In order to run this on a **windows machine** you only have to replace the paths to something like:
  
  ```py
  # folder_movies = '/home/user/Desktop/test/' # linux or osx
  folder_movies = r'c:\some\directory\test'    # windows, the r is important
  folder_movies = 'c:/some/directory\test'     # windows (alternative)
  
  # path_to_ffmpeg = '/opt/ffmpeg/ffmpeg'            # linux or osx
  path_to_ffmpeg = r'c:\Program Files\ffmpeg\ffmpeg' # windows, the r is important
  path_to_ffmpeg = 'c:/Program Files/ffmpeg\ffmpeg'  # windows (alternative)
  
  ```
  
  **Note:** I'm not a ffmpeg expert, maybe there is a way to batch process with it directly.
  
  > **Comments:**
  > **username_4**: You don't really need a whole script for this. It can be done directly on the Mac or Linux command-line with something like : `mkdir -p rotated; for f in *.mp4; do ffmpeg -i "$f" -vf transpose=2 rotated/"$f"; done` (assuming your video files are .mp4 in this example).  
  > **username_1**: @username_4 nice, why not converting this to an answer?  
  > **username_1**: @username_4 Since you are using a for loop it's nearly the same. For those who don't use linux or osx, it makes sense to use python or another scripting language.  
  > **username_4**: @poor : well, for those users who are neither on linux nor on mac, the translation into PowerShell is "left as an exercise for the reader"... :-)  
  > **username_1**: @username_4 hehe, yeah, but no one wants to use it ;)  
  > **username_5**: @username_4 : Well, I had to, so here's the implementation for powershell.  Get-ChildItem "." -Filter *.mp4 | Foreach-Object { ffmpeg.exe -i "$_" -vf transpose=2 -c:a copy -metadata:s:v rotate="" rotated/"$_" }  
  
  ---
  
  ### Answer by username_6 on 2023-02-06. Score: 0
  
  This worked for me. create a batch file. Make a directory called output in your videos directory. Also put a copy of ffmpeg.exe in the directory. You can get ffmpeg download with google. it is a zip file, you just need ffmpeg.exe.
  
  Run the batch file and wait.
  
  ```
  for %%a in ("*.mp4") do ffmpeg -i "%%a" -vf transpose=2 -c:a copy -metadata:s:v rotate="" "output\%%~na.mp4"
  
  ```
  
  
  ---
  
  