How do I add a 1 second fade out effect to the end of a video with ffmpeg?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







2















How do I add a simple one or half second fade effect to the start or end of a video using ffmpeg and keep everything else the same (codec,quality)










share|improve this question


















  • 1





    I am not a ffmpeg expert, I am using it sometimes. But I know it is well documented. So I've tried google.com/search?q=ffmpeg+add+fade+out Short answer: hoover.gplrank.info/?p=531 Long Answer: stackoverflow.com/questions/44291954/… ... And for automation of the process: video.stackexchange.com/questions/19867/…

    – LupusE
    Mar 26 at 7:58




















2















How do I add a simple one or half second fade effect to the start or end of a video using ffmpeg and keep everything else the same (codec,quality)










share|improve this question


















  • 1





    I am not a ffmpeg expert, I am using it sometimes. But I know it is well documented. So I've tried google.com/search?q=ffmpeg+add+fade+out Short answer: hoover.gplrank.info/?p=531 Long Answer: stackoverflow.com/questions/44291954/… ... And for automation of the process: video.stackexchange.com/questions/19867/…

    – LupusE
    Mar 26 at 7:58
















2












2








2


1






How do I add a simple one or half second fade effect to the start or end of a video using ffmpeg and keep everything else the same (codec,quality)










share|improve this question














How do I add a simple one or half second fade effect to the start or end of a video using ffmpeg and keep everything else the same (codec,quality)







ffmpeg video-editor






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 26 at 7:41









llllll

367




367








  • 1





    I am not a ffmpeg expert, I am using it sometimes. But I know it is well documented. So I've tried google.com/search?q=ffmpeg+add+fade+out Short answer: hoover.gplrank.info/?p=531 Long Answer: stackoverflow.com/questions/44291954/… ... And for automation of the process: video.stackexchange.com/questions/19867/…

    – LupusE
    Mar 26 at 7:58
















  • 1





    I am not a ffmpeg expert, I am using it sometimes. But I know it is well documented. So I've tried google.com/search?q=ffmpeg+add+fade+out Short answer: hoover.gplrank.info/?p=531 Long Answer: stackoverflow.com/questions/44291954/… ... And for automation of the process: video.stackexchange.com/questions/19867/…

    – LupusE
    Mar 26 at 7:58










1




1





I am not a ffmpeg expert, I am using it sometimes. But I know it is well documented. So I've tried google.com/search?q=ffmpeg+add+fade+out Short answer: hoover.gplrank.info/?p=531 Long Answer: stackoverflow.com/questions/44291954/… ... And for automation of the process: video.stackexchange.com/questions/19867/…

– LupusE
Mar 26 at 7:58







I am not a ffmpeg expert, I am using it sometimes. But I know it is well documented. So I've tried google.com/search?q=ffmpeg+add+fade+out Short answer: hoover.gplrank.info/?p=531 Long Answer: stackoverflow.com/questions/44291954/… ... And for automation of the process: video.stackexchange.com/questions/19867/…

– LupusE
Mar 26 at 7:58












2 Answers
2






active

oldest

votes


















1
















  1. find out the number of frames in the video clip. Command:



    ffmpeg -i clip.mp4 -vcodec copy -f rawvideo -y /dev/null 2>&1 | tr ^M 'n' | awk '/^frame=/ {print $2}'|tail -n 1
    5130


  2. Find the frames per second



fps



it's 24





  1. Add fade in/out



    ffmpeg -i clip.mp4 -vf "fade=in:0:24,fade=out:5106:24" -acodec copy clip-out.mp4



Done






share|improve this answer































    1














    For a 10 second duration video, 1 second fade in in beginning, 1 second fade out in the ending use the fade filter:



    ffmpeg -i input.mp4 -vf "fade=type=in:duration=1,fade=type=out:duration=1:start_time=9" -c:a copy output.mp4


    If you want to fade audio too then add the afade filter:



    ffmpeg -i input.mp4 -filter_complex "[0:v]fade=type=in:duration=1,fade=type=out:duration=1:start_time=9[v];[0:a]afade=type=in:duration=1,afade=type=out:duration=1:start_time=9[a]" -map "[v]" -map "[a]" output.mp4


    To automate it use ffprobe to get the duration and bc to calculate the start time for the fade out at the end:



    #!/bin/bash
    mkdir fade
    for f in *.mp4; do
    dur=$(ffprobe -loglevel error -show_entries format=duration -of default=nk=1:nw=1 "$f")
    offset=$(bc -l <<< "$dur"-1)
    ffmpeg -i "$f" -filter_complex "[0:v]fade=type=in:duration=1,fade=type=out:duration=1:start_time='$offset'[v];[0:a]afade=type=in:duration=1,afade=type=out:duration=1:start_time='$offset'[a]" -map "[v]" -map "[a]" fade/"$f"
    done


    This assumes all inputs have video and audio. If not you can use an if/then statement in conjunction with ffprobe to determine if there is audio.




    ...and keep everything else the same (codec,quality)




    Filtering requires encoding. You can't keep the quality when outputting a lossy format. Either output a lossless format (not recommended, huge files, compatibility issues), or accept some amount of loss. Luckily you probably won't notice. Just use the -crf option when outputting H.264 video. Use the highest value that still looks good enough. See FFmpeg Wiki: H.264 for more details.






    share|improve this answer


























      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "89"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1128754%2fhow-do-i-add-a-1-second-fade-out-effect-to-the-end-of-a-video-with-ffmpeg%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1
















      1. find out the number of frames in the video clip. Command:



        ffmpeg -i clip.mp4 -vcodec copy -f rawvideo -y /dev/null 2>&1 | tr ^M 'n' | awk '/^frame=/ {print $2}'|tail -n 1
        5130


      2. Find the frames per second



      fps



      it's 24





      1. Add fade in/out



        ffmpeg -i clip.mp4 -vf "fade=in:0:24,fade=out:5106:24" -acodec copy clip-out.mp4



      Done






      share|improve this answer




























        1
















        1. find out the number of frames in the video clip. Command:



          ffmpeg -i clip.mp4 -vcodec copy -f rawvideo -y /dev/null 2>&1 | tr ^M 'n' | awk '/^frame=/ {print $2}'|tail -n 1
          5130


        2. Find the frames per second



        fps



        it's 24





        1. Add fade in/out



          ffmpeg -i clip.mp4 -vf "fade=in:0:24,fade=out:5106:24" -acodec copy clip-out.mp4



        Done






        share|improve this answer


























          1












          1








          1









          1. find out the number of frames in the video clip. Command:



            ffmpeg -i clip.mp4 -vcodec copy -f rawvideo -y /dev/null 2>&1 | tr ^M 'n' | awk '/^frame=/ {print $2}'|tail -n 1
            5130


          2. Find the frames per second



          fps



          it's 24





          1. Add fade in/out



            ffmpeg -i clip.mp4 -vf "fade=in:0:24,fade=out:5106:24" -acodec copy clip-out.mp4



          Done






          share|improve this answer















          1. find out the number of frames in the video clip. Command:



            ffmpeg -i clip.mp4 -vcodec copy -f rawvideo -y /dev/null 2>&1 | tr ^M 'n' | awk '/^frame=/ {print $2}'|tail -n 1
            5130


          2. Find the frames per second



          fps



          it's 24





          1. Add fade in/out



            ffmpeg -i clip.mp4 -vf "fade=in:0:24,fade=out:5106:24" -acodec copy clip-out.mp4



          Done







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 26 at 13:32









          VijayVijay

          2,1041822




          2,1041822

























              1














              For a 10 second duration video, 1 second fade in in beginning, 1 second fade out in the ending use the fade filter:



              ffmpeg -i input.mp4 -vf "fade=type=in:duration=1,fade=type=out:duration=1:start_time=9" -c:a copy output.mp4


              If you want to fade audio too then add the afade filter:



              ffmpeg -i input.mp4 -filter_complex "[0:v]fade=type=in:duration=1,fade=type=out:duration=1:start_time=9[v];[0:a]afade=type=in:duration=1,afade=type=out:duration=1:start_time=9[a]" -map "[v]" -map "[a]" output.mp4


              To automate it use ffprobe to get the duration and bc to calculate the start time for the fade out at the end:



              #!/bin/bash
              mkdir fade
              for f in *.mp4; do
              dur=$(ffprobe -loglevel error -show_entries format=duration -of default=nk=1:nw=1 "$f")
              offset=$(bc -l <<< "$dur"-1)
              ffmpeg -i "$f" -filter_complex "[0:v]fade=type=in:duration=1,fade=type=out:duration=1:start_time='$offset'[v];[0:a]afade=type=in:duration=1,afade=type=out:duration=1:start_time='$offset'[a]" -map "[v]" -map "[a]" fade/"$f"
              done


              This assumes all inputs have video and audio. If not you can use an if/then statement in conjunction with ffprobe to determine if there is audio.




              ...and keep everything else the same (codec,quality)




              Filtering requires encoding. You can't keep the quality when outputting a lossy format. Either output a lossless format (not recommended, huge files, compatibility issues), or accept some amount of loss. Luckily you probably won't notice. Just use the -crf option when outputting H.264 video. Use the highest value that still looks good enough. See FFmpeg Wiki: H.264 for more details.






              share|improve this answer






























                1














                For a 10 second duration video, 1 second fade in in beginning, 1 second fade out in the ending use the fade filter:



                ffmpeg -i input.mp4 -vf "fade=type=in:duration=1,fade=type=out:duration=1:start_time=9" -c:a copy output.mp4


                If you want to fade audio too then add the afade filter:



                ffmpeg -i input.mp4 -filter_complex "[0:v]fade=type=in:duration=1,fade=type=out:duration=1:start_time=9[v];[0:a]afade=type=in:duration=1,afade=type=out:duration=1:start_time=9[a]" -map "[v]" -map "[a]" output.mp4


                To automate it use ffprobe to get the duration and bc to calculate the start time for the fade out at the end:



                #!/bin/bash
                mkdir fade
                for f in *.mp4; do
                dur=$(ffprobe -loglevel error -show_entries format=duration -of default=nk=1:nw=1 "$f")
                offset=$(bc -l <<< "$dur"-1)
                ffmpeg -i "$f" -filter_complex "[0:v]fade=type=in:duration=1,fade=type=out:duration=1:start_time='$offset'[v];[0:a]afade=type=in:duration=1,afade=type=out:duration=1:start_time='$offset'[a]" -map "[v]" -map "[a]" fade/"$f"
                done


                This assumes all inputs have video and audio. If not you can use an if/then statement in conjunction with ffprobe to determine if there is audio.




                ...and keep everything else the same (codec,quality)




                Filtering requires encoding. You can't keep the quality when outputting a lossy format. Either output a lossless format (not recommended, huge files, compatibility issues), or accept some amount of loss. Luckily you probably won't notice. Just use the -crf option when outputting H.264 video. Use the highest value that still looks good enough. See FFmpeg Wiki: H.264 for more details.






                share|improve this answer




























                  1












                  1








                  1







                  For a 10 second duration video, 1 second fade in in beginning, 1 second fade out in the ending use the fade filter:



                  ffmpeg -i input.mp4 -vf "fade=type=in:duration=1,fade=type=out:duration=1:start_time=9" -c:a copy output.mp4


                  If you want to fade audio too then add the afade filter:



                  ffmpeg -i input.mp4 -filter_complex "[0:v]fade=type=in:duration=1,fade=type=out:duration=1:start_time=9[v];[0:a]afade=type=in:duration=1,afade=type=out:duration=1:start_time=9[a]" -map "[v]" -map "[a]" output.mp4


                  To automate it use ffprobe to get the duration and bc to calculate the start time for the fade out at the end:



                  #!/bin/bash
                  mkdir fade
                  for f in *.mp4; do
                  dur=$(ffprobe -loglevel error -show_entries format=duration -of default=nk=1:nw=1 "$f")
                  offset=$(bc -l <<< "$dur"-1)
                  ffmpeg -i "$f" -filter_complex "[0:v]fade=type=in:duration=1,fade=type=out:duration=1:start_time='$offset'[v];[0:a]afade=type=in:duration=1,afade=type=out:duration=1:start_time='$offset'[a]" -map "[v]" -map "[a]" fade/"$f"
                  done


                  This assumes all inputs have video and audio. If not you can use an if/then statement in conjunction with ffprobe to determine if there is audio.




                  ...and keep everything else the same (codec,quality)




                  Filtering requires encoding. You can't keep the quality when outputting a lossy format. Either output a lossless format (not recommended, huge files, compatibility issues), or accept some amount of loss. Luckily you probably won't notice. Just use the -crf option when outputting H.264 video. Use the highest value that still looks good enough. See FFmpeg Wiki: H.264 for more details.






                  share|improve this answer















                  For a 10 second duration video, 1 second fade in in beginning, 1 second fade out in the ending use the fade filter:



                  ffmpeg -i input.mp4 -vf "fade=type=in:duration=1,fade=type=out:duration=1:start_time=9" -c:a copy output.mp4


                  If you want to fade audio too then add the afade filter:



                  ffmpeg -i input.mp4 -filter_complex "[0:v]fade=type=in:duration=1,fade=type=out:duration=1:start_time=9[v];[0:a]afade=type=in:duration=1,afade=type=out:duration=1:start_time=9[a]" -map "[v]" -map "[a]" output.mp4


                  To automate it use ffprobe to get the duration and bc to calculate the start time for the fade out at the end:



                  #!/bin/bash
                  mkdir fade
                  for f in *.mp4; do
                  dur=$(ffprobe -loglevel error -show_entries format=duration -of default=nk=1:nw=1 "$f")
                  offset=$(bc -l <<< "$dur"-1)
                  ffmpeg -i "$f" -filter_complex "[0:v]fade=type=in:duration=1,fade=type=out:duration=1:start_time='$offset'[v];[0:a]afade=type=in:duration=1,afade=type=out:duration=1:start_time='$offset'[a]" -map "[v]" -map "[a]" fade/"$f"
                  done


                  This assumes all inputs have video and audio. If not you can use an if/then statement in conjunction with ffprobe to determine if there is audio.




                  ...and keep everything else the same (codec,quality)




                  Filtering requires encoding. You can't keep the quality when outputting a lossy format. Either output a lossless format (not recommended, huge files, compatibility issues), or accept some amount of loss. Luckily you probably won't notice. Just use the -crf option when outputting H.264 video. Use the highest value that still looks good enough. See FFmpeg Wiki: H.264 for more details.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Mar 26 at 17:51

























                  answered Mar 26 at 17:43









                  lloganllogan

                  5,4251737




                  5,4251737






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Ask Ubuntu!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1128754%2fhow-do-i-add-a-1-second-fade-out-effect-to-the-end-of-a-video-with-ffmpeg%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      How did Captain America manage to do this?

                      迪纳利

                      南乌拉尔铁路局