Answers.Body: <p>FFmpeg has a <a href="https://ffmpeg.org/ffmpeg-filters.html#reverse" rel="noreferrer">reverse video filter</a> and <a href="https://ffmpeg.org/ffmpeg-filters.html#areverse" rel="noreferrer">reverse audio filter</a>.</p>
  <p>For video only:</p>
  <pre><code>ffmpeg -i /storage/emulated/0/ffvid/frameCount.mp4 -vf reverse reversed.mp4
  </code></pre>
  <p>For audio and video:</p>
  <pre><code>ffmpeg -i /storage/emulated/0/ffvid/frameCount.mp4 -vf reverse -af areverse reversed.mp4
  </code></pre>
  <p>This filter buffers the <strong>entire</strong> clip. For larger files, segment the file, reverse each segment and then concat the reversed segments. Remember that you have to concat the reversed segments in the <em>reverse order</em>!</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2016-02-22T14:22:03.310Z
Answers.LastActivityDate: 2020-07-21T17:51:13.803Z
Answers.LastEditDate: 2020-07-21T17:51:13.803Z
Answers.UserDisplayName: Gyan
Answers.Body: <p>@Gyan is correct. You can reverse a video using <code>ffmegs</code> built in <a href="https://ffmpeg.org/ffmpeg-filters.html#reverse" rel="nofollow noreferrer">reverse video filter</a>:</p>
  <pre class="lang-bash prettyprint-override"><code>ffmpeg -i video.mp4 -vf reverse video_reversed.mp4
  </code></pre>
  <p>However this is incredibly memory intensive. I wont go into details but it has to do with the video is saved in a compressed format. To reverse it, it needs basically load each frame of the video into memory.</p>
  <p>Therefor for any reasonably sized video (&gt; 10 minutes) you are going to have a tough time using the above command. Thus to complete @Gyan's answer. Here is how to segment the video, reverse each part, and then concatenate them again.</p>
  <p>You can first segment a video into <code>300</code> second chunks using:</p>
  <pre class="lang-bash prettyprint-override"><code>ffmpeg -i video.mp4 -map 0 -c copy -f segment -segment_time 300 -reset_timestamps 1 video_%03d.mp4
  </code></pre>
  <p>This will output a bunch of video files named <code>video_000.mp4</code>, <code>video_001.mp4</code> etc. Next you need to reverse each of these segments. You can either do that manually using the original reverse command, or you can use the loop provided below.</p>
  <p><strong>NOTE</strong>: Make sure you remove the original video <code>video.mp4</code> from the folder before using the loop below (otherwise you are back to the start).</p>
  <p>Alternatively for long videos you might want to use a loop. This loop looks for all <code>mp4</code> files in the current directory and reverses each of them:</p>
  <p><strong>To reverse only the video but not the audio:</strong></p>
  <pre class="lang-bash prettyprint-override"><code>for f in *.mp4; do
      ffmpeg -i $f -vf reverse ${f/.mp4/_reversed.mp4}
  done
  </code></pre>
  <p><strong>To reverse the video and audio:</strong></p>
  <pre class="lang-bash prettyprint-override"><code>for f in *.mp4; do
      ffmpeg -i $f -vf reverse -af areverse ${f/.mp4/_reversed.mp4}
  done
  </code></pre>
  <p>You will now have a set of reversed segments med <code>video_000_reversed.mp4</code>, <code>video_001_reversed.mp4</code> etc. The final command concatenates them into a single video. To do that we need a text file with all the files we want to concatenate. You can automatically create this text file using the following:</p>
  <pre class="lang-bash prettyprint-override"><code>for f in ./SegmentedVideos/*_reversed.mp4;  do 
      echo file \'$f\' &gt; tmp.txt
      cat fileList.txt &gt;&gt; tmp.txt
      rm fileList.txt
      mv tmp.txt fileList.txt
  done
  </code></pre>
  <p>At this point you should have a text file <code>fileList.txt</code> that contains the video files in reverse order like this:</p>
  <pre><code>file './video_XXX_reversed.mp4'
  ...
  file './video_001_reversed.mp4'
  file './video_000_reversed.mp4'
  </code></pre>
  <p>Then all we need to do is concatenate everything:</p>
  <pre class="lang-bash prettyprint-override"><code>ffmpeg -f concat -safe 0 -i fileList.txt -c copy final_revered_video.mp4
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-05T04:43:22.533Z
Answers.Text: I tried this, got as far as the last step, but at that point got the `moov atom not found` error.
Answers.UserDisplayName: Lori
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-05-01T00:58:35.230Z
Answers.LastActivityDate: 2023-04-13T18:11:49.577Z
Answers.LastEditDate: 2023-04-13T18:11:49.577Z
Answers.UserDisplayName: Carl H
Body: <p>i am use to FFmpeg library in android for reverse video. I can dump images from video but how to reverse all images and make video. See <a href="http://writingminds.github.io/ffmpeg-android-java/" rel="noreferrer">this</a> link that from i am use to library in my gradle.. Library is <code>compile 'com.github.hiteshsondhi88.libffmpeg:FFmpegAndroid:0.2.5'</code> i can use some of command and some are not. i use command as like below</p>
  
  <p><code>-i /storage/emulated/0/ffvid/frameCount.mp4 -an -qscale 1 /storage/emulated/0/ffimg/revi%06d.jpg</code></p>
  
  <p>above command use for dump images from video. i can't use command as liki <code>$ffmpeg</code> , <code>$sox</code> and <code>$cat</code></p>
  
  <p>i have referred many link but not success in see below some links...</p>
  
  <p><a href="https://unix.stackexchange.com/questions/214327/how-can-i-reverse-a-video-clip">https://unix.stackexchange.com/questions/214327/how-can-i-reverse-a-video-clip</a></p>
  
  <p><a href="http://jiaxihu.blogspot.in/2012/05/reverse-video-clip-with-ffmpeg.html" rel="noreferrer">http://jiaxihu.blogspot.in/2012/05/reverse-video-clip-with-ffmpeg.html</a></p>
  
  <p>So please help me and give me solution. if other library available then suggest me. thanks advance </p>
  
Tags: <video><ffmpeg>
Title: How to use FFmpeg Command for Reverse Video?
UserDisplayName: Ravi Vaghela
ThreadText: # How to use FFmpeg Command for Reverse Video?
  
  (Asked by: username_0 on 2016-02-22)
  
  i am use to FFmpeg library in android for reverse video. I can dump images from video but how to reverse all images and make video. See [this](http://writingminds.github.io/ffmpeg-android-java/) link that from i am use to library in my gradle.. Library is `compile 'com.github.hiteshsondhi88.libffmpeg:FFmpegAndroid:0.2.5'` i can use some of command and some are not. i use command as like below
  
  `-i /storage/emulated/0/ffvid/frameCount.mp4 -an -qscale 1 /storage/emulated/0/ffimg/revi%06d.jpg`
  
  above command use for dump images from video. i can't use command as liki `$ffmpeg` , `$sox` and `$cat`
  
  i have referred many link but not success in see below some links...
  
  <https://unix.stackexchange.com/questions/214327/how-can-i-reverse-a-video-clip>
  
  <http://jiaxihu.blogspot.in/2012/05/reverse-video-clip-with-ffmpeg.html>
  
  So please help me and give me solution. if other library available then suggest me. thanks advance
  
  **Tags:** video, ffmpeg
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2016-02-22. Score: 71
  
  FFmpeg has a [reverse video filter](https://ffmpeg.org/ffmpeg-filters.html#reverse) and [reverse audio filter](https://ffmpeg.org/ffmpeg-filters.html#areverse).
  
  For video only:
  
  ```
  ffmpeg -i /storage/emulated/0/ffvid/frameCount.mp4 -vf reverse reversed.mp4
  
  ```
  
  For audio and video:
  
  ```
  ffmpeg -i /storage/emulated/0/ffvid/frameCount.mp4 -vf reverse -af areverse reversed.mp4
  
  ```
  
  This filter buffers the **entire** clip. For larger files, segment the file, reverse each segment and then concat the reversed segments. Remember that you have to concat the reversed segments in the *reverse order*!
  
  
  ---
  
  ### Answer by username_2 on 2022-05-01. Score: 12
  
  @username_1 is correct. You can reverse a video using `ffmegs` built in [reverse video filter](https://ffmpeg.org/ffmpeg-filters.html#reverse):
  
  ```bash
  ffmpeg -i video.mp4 -vf reverse video_reversed.mp4
  
  ```
  
  However this is incredibly memory intensive. I wont go into details but it has to do with the video is saved in a compressed format. To reverse it, it needs basically load each frame of the video into memory.
  
  Therefor for any reasonably sized video (> 10 minutes) you are going to have a tough time using the above command. Thus to complete @username_1's answer. Here is how to segment the video, reverse each part, and then concatenate them again.
  
  You can first segment a video into `300` second chunks using:
  
  ```bash
  ffmpeg -i video.mp4 -map 0 -c copy -f segment -segment_time 300 -reset_timestamps 1 video_%03d.mp4
  
  ```
  
  This will output a bunch of video files named `video_000.mp4`, `video_001.mp4` etc. Next you need to reverse each of these segments. You can either do that manually using the original reverse command, or you can use the loop provided below.
  
  **NOTE**: Make sure you remove the original video `video.mp4` from the folder before using the loop below (otherwise you are back to the start).
  
  Alternatively for long videos you might want to use a loop. This loop looks for all `mp4` files in the current directory and reverses each of them:
  
  **To reverse only the video but not the audio:**
  
  ```bash
  for f in *.mp4; do
      ffmpeg -i $f -vf reverse ${f/.mp4/_reversed.mp4}
  done
  
  ```
  
  **To reverse the video and audio:**
  
  ```bash
  for f in *.mp4; do
      ffmpeg -i $f -vf reverse -af areverse ${f/.mp4/_reversed.mp4}
  done
  
  ```
  
  You will now have a set of reversed segments med `video_000_reversed.mp4`, `video_001_reversed.mp4` etc. The final command concatenates them into a single video. To do that we need a text file with all the files we want to concatenate. You can automatically create this text file using the following:
  
  ```bash
  for f in ./SegmentedVideos/*_reversed.mp4;  do 
      echo file \'$f\' > tmp.txt
      cat fileList.txt >> tmp.txt
      rm fileList.txt
      mv tmp.txt fileList.txt
  done
  
  ```
  
  At this point you should have a text file `fileList.txt` that contains the video files in reverse order like this:
  
  ```
  file './video_XXX_reversed.mp4'
  ...
  file './video_001_reversed.mp4'
  file './video_000_reversed.mp4'
  
  ```
  
  Then all we need to do is concatenate everything:
  
  ```bash
  ffmpeg -f concat -safe 0 -i fileList.txt -c copy final_revered_video.mp4
  
  ```
  
  > **Comments:**
  > **username_3**: I tried this, got as far as the last step, but at that point got the `moov atom not found` error.  
  
  ---
  
  