How can I remove multiple segments from a video using FFmpeg?












39














I am trying to delete a few sections of a video using FFmpeg.



For example, imagine if you recorded a show on television and wanted to cut out the commercials. This is simple with a GUI video-editor; you just mark the beginning and ending of each clip to be removed, and select delete. I am trying to do the same thing from the command-line with FFmpeg.



I know how to cut a single segment to a new video like so:



ffmpeg -i input.avi -ss 00:00:20 -t 00:00:05 -map 0 -codec copy output.avi


This cuts a five-second clip and saves it as a new video file, but how can I do the opposite and save the whole video without the specified clip, and how I can I specify multiple clips to be removed?



For example, if my video could be represented by ABCDEFG, I would like to create a new one that would consist of ACDFG.










share|improve this question
























  • possible duplicate of Splitting video in multiple episodes with ffmpeg, also perhaps check out Using FFMpeg to cut a video into 2 minute clips
    – Ƭᴇcʜιᴇ007
    Nov 28 '13 at 20:18












  • That is not what I am asking, I would like to get it all in one "episode", but this would have different sections from the original video.
    – Matias
    Nov 29 '13 at 15:21










  • @Matias, if you were asking how to cut a few clips out of the video and leave the rest as is, that would be one thing, but you want to take a few clips from it and combine them with clips from other videos which makes this not a separate, unique question. You have to do what the other questions asked to get the separate segments, then combine them.
    – Synetech
    Nov 29 '13 at 16:47










  • @Synetech thanks for your answers. I do not want to combine them with clips from other videos. I just want to remove some parts from the videos. For example, if my video could be represented by ABCDEFG, I would like to create a new one that would consist of ACDFG.
    – Matias
    Nov 29 '13 at 17:10










  • @Synetech That wasn't me, it was Tog who must have missunderstood.
    – Matias
    Nov 29 '13 at 17:47
















39














I am trying to delete a few sections of a video using FFmpeg.



For example, imagine if you recorded a show on television and wanted to cut out the commercials. This is simple with a GUI video-editor; you just mark the beginning and ending of each clip to be removed, and select delete. I am trying to do the same thing from the command-line with FFmpeg.



I know how to cut a single segment to a new video like so:



ffmpeg -i input.avi -ss 00:00:20 -t 00:00:05 -map 0 -codec copy output.avi


This cuts a five-second clip and saves it as a new video file, but how can I do the opposite and save the whole video without the specified clip, and how I can I specify multiple clips to be removed?



For example, if my video could be represented by ABCDEFG, I would like to create a new one that would consist of ACDFG.










share|improve this question
























  • possible duplicate of Splitting video in multiple episodes with ffmpeg, also perhaps check out Using FFMpeg to cut a video into 2 minute clips
    – Ƭᴇcʜιᴇ007
    Nov 28 '13 at 20:18












  • That is not what I am asking, I would like to get it all in one "episode", but this would have different sections from the original video.
    – Matias
    Nov 29 '13 at 15:21










  • @Matias, if you were asking how to cut a few clips out of the video and leave the rest as is, that would be one thing, but you want to take a few clips from it and combine them with clips from other videos which makes this not a separate, unique question. You have to do what the other questions asked to get the separate segments, then combine them.
    – Synetech
    Nov 29 '13 at 16:47










  • @Synetech thanks for your answers. I do not want to combine them with clips from other videos. I just want to remove some parts from the videos. For example, if my video could be represented by ABCDEFG, I would like to create a new one that would consist of ACDFG.
    – Matias
    Nov 29 '13 at 17:10










  • @Synetech That wasn't me, it was Tog who must have missunderstood.
    – Matias
    Nov 29 '13 at 17:47














39












39








39


14





I am trying to delete a few sections of a video using FFmpeg.



For example, imagine if you recorded a show on television and wanted to cut out the commercials. This is simple with a GUI video-editor; you just mark the beginning and ending of each clip to be removed, and select delete. I am trying to do the same thing from the command-line with FFmpeg.



I know how to cut a single segment to a new video like so:



ffmpeg -i input.avi -ss 00:00:20 -t 00:00:05 -map 0 -codec copy output.avi


This cuts a five-second clip and saves it as a new video file, but how can I do the opposite and save the whole video without the specified clip, and how I can I specify multiple clips to be removed?



For example, if my video could be represented by ABCDEFG, I would like to create a new one that would consist of ACDFG.










share|improve this question















I am trying to delete a few sections of a video using FFmpeg.



For example, imagine if you recorded a show on television and wanted to cut out the commercials. This is simple with a GUI video-editor; you just mark the beginning and ending of each clip to be removed, and select delete. I am trying to do the same thing from the command-line with FFmpeg.



I know how to cut a single segment to a new video like so:



ffmpeg -i input.avi -ss 00:00:20 -t 00:00:05 -map 0 -codec copy output.avi


This cuts a five-second clip and saves it as a new video file, but how can I do the opposite and save the whole video without the specified clip, and how I can I specify multiple clips to be removed?



For example, if my video could be represented by ABCDEFG, I would like to create a new one that would consist of ACDFG.







ffmpeg video-editing mp4






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 2 '14 at 9:15









Der Hochstapler

67.3k49230284




67.3k49230284










asked Nov 28 '13 at 20:09









Matias

4381411




4381411












  • possible duplicate of Splitting video in multiple episodes with ffmpeg, also perhaps check out Using FFMpeg to cut a video into 2 minute clips
    – Ƭᴇcʜιᴇ007
    Nov 28 '13 at 20:18












  • That is not what I am asking, I would like to get it all in one "episode", but this would have different sections from the original video.
    – Matias
    Nov 29 '13 at 15:21










  • @Matias, if you were asking how to cut a few clips out of the video and leave the rest as is, that would be one thing, but you want to take a few clips from it and combine them with clips from other videos which makes this not a separate, unique question. You have to do what the other questions asked to get the separate segments, then combine them.
    – Synetech
    Nov 29 '13 at 16:47










  • @Synetech thanks for your answers. I do not want to combine them with clips from other videos. I just want to remove some parts from the videos. For example, if my video could be represented by ABCDEFG, I would like to create a new one that would consist of ACDFG.
    – Matias
    Nov 29 '13 at 17:10










  • @Synetech That wasn't me, it was Tog who must have missunderstood.
    – Matias
    Nov 29 '13 at 17:47


















  • possible duplicate of Splitting video in multiple episodes with ffmpeg, also perhaps check out Using FFMpeg to cut a video into 2 minute clips
    – Ƭᴇcʜιᴇ007
    Nov 28 '13 at 20:18












  • That is not what I am asking, I would like to get it all in one "episode", but this would have different sections from the original video.
    – Matias
    Nov 29 '13 at 15:21










  • @Matias, if you were asking how to cut a few clips out of the video and leave the rest as is, that would be one thing, but you want to take a few clips from it and combine them with clips from other videos which makes this not a separate, unique question. You have to do what the other questions asked to get the separate segments, then combine them.
    – Synetech
    Nov 29 '13 at 16:47










  • @Synetech thanks for your answers. I do not want to combine them with clips from other videos. I just want to remove some parts from the videos. For example, if my video could be represented by ABCDEFG, I would like to create a new one that would consist of ACDFG.
    – Matias
    Nov 29 '13 at 17:10










  • @Synetech That wasn't me, it was Tog who must have missunderstood.
    – Matias
    Nov 29 '13 at 17:47
















possible duplicate of Splitting video in multiple episodes with ffmpeg, also perhaps check out Using FFMpeg to cut a video into 2 minute clips
– Ƭᴇcʜιᴇ007
Nov 28 '13 at 20:18






possible duplicate of Splitting video in multiple episodes with ffmpeg, also perhaps check out Using FFMpeg to cut a video into 2 minute clips
– Ƭᴇcʜιᴇ007
Nov 28 '13 at 20:18














That is not what I am asking, I would like to get it all in one "episode", but this would have different sections from the original video.
– Matias
Nov 29 '13 at 15:21




That is not what I am asking, I would like to get it all in one "episode", but this would have different sections from the original video.
– Matias
Nov 29 '13 at 15:21












@Matias, if you were asking how to cut a few clips out of the video and leave the rest as is, that would be one thing, but you want to take a few clips from it and combine them with clips from other videos which makes this not a separate, unique question. You have to do what the other questions asked to get the separate segments, then combine them.
– Synetech
Nov 29 '13 at 16:47




@Matias, if you were asking how to cut a few clips out of the video and leave the rest as is, that would be one thing, but you want to take a few clips from it and combine them with clips from other videos which makes this not a separate, unique question. You have to do what the other questions asked to get the separate segments, then combine them.
– Synetech
Nov 29 '13 at 16:47












@Synetech thanks for your answers. I do not want to combine them with clips from other videos. I just want to remove some parts from the videos. For example, if my video could be represented by ABCDEFG, I would like to create a new one that would consist of ACDFG.
– Matias
Nov 29 '13 at 17:10




@Synetech thanks for your answers. I do not want to combine them with clips from other videos. I just want to remove some parts from the videos. For example, if my video could be represented by ABCDEFG, I would like to create a new one that would consist of ACDFG.
– Matias
Nov 29 '13 at 17:10












@Synetech That wasn't me, it was Tog who must have missunderstood.
– Matias
Nov 29 '13 at 17:47




@Synetech That wasn't me, it was Tog who must have missunderstood.
– Matias
Nov 29 '13 at 17:47










4 Answers
4






active

oldest

votes


















42














Well, you still can use the trim filter for that. Here is an example, lets assume that you want to cut out segments 30-40 sec (10 sec) and 50-80 sec (30 sec):



ffmpeg -i in.ts -filter_complex 
"[0:v]trim=duration=30[a];
[0:v]trim=start=40:end=50,setpts=PTS-STARTPTS[b];
[a][b]concat[c];
[0:v]trim=start=80,setpts=PTS-STARTPTS[d];
[c][d]concat[out1]" -map [out1] out.ts


What I did here? I trimmed first 30 sec, 40-50 sec and 80 sec to end, and then combined them into stream out1 with the concat filter.



About setpts: we need this because trim does not modify picture display time, and when we cut out 10 sec decoder counter does not see any frames for this 10 sec.



If you want to have audio too, You have to do the same for audio streams. So the command should be:



ffmpeg -i utv.ts -filter_complex 
"[0:v]trim=duration=30[av];[0:a]atrim=duration=30[aa];
[0:v]trim=start=40:end=50,setpts=PTS-STARTPTS[bv];
[0:a]atrim=start=40:end=50,asetpts=PTS-STARTPTS[ba];
[av][bv]concat[cv];[aa][ba]concat=v=0:a=1[ca];
[0:v]trim=start=80,setpts=PTS-STARTPTS[dv];
[0:a]atrim=start=80,asetpts=PTS-STARTPTS[da];
[cv][dv]concat[outv];[ca][da]concat=v=0:a=1[outa]" -map [outv] -map [outa] out.ts





share|improve this answer























  • Great one! Why do we need setpts? Could you add the explanation?
    – Rajib
    Dec 1 '13 at 4:32










  • Ok, see updated answer.
    – ptQa
    Dec 2 '13 at 7:41






  • 4




    +1 This really should be selected as the answer. It is more suited for "multiple segments" and removes the necessity to perform multiple commands one after another. (unless another way is more speed efficient)
    – Knossos
    Dec 17 '13 at 10:19












  • For the record, when I tried this with serveral segments (about 8) I got an error message about a "buffer queue overflow" and the program crashed. I don't know which versions are affected by this, but I wouldn't want to use this method for that reason.
    – Wutaz
    Feb 13 '14 at 22:35






  • 1




    How would you go about maintaining subtitle data when you're skipping frames?
    – Andrew Scagnelli
    Mar 2 '15 at 14:46



















12














I can never get ptQa's solution to work, mostly because I can never figure out what the errors from the filters mean or how to fix them. My solution seems a little clunkier because it can leave behind a mess, but if you're throwing it into a script, the clean up can be automated. I also like this approach because if something goes wrong on step 4, you end up with completed steps 1-3 so recovering from errors is a little more efficient.



The basic strategy is using -t and -ss to get videos of each segment you want, then join together all the parts for your final version.



Say you have 6 segments ABCDEF each 5 seconds long and you want A (0-5 seconds), C (10-15 seconds) and E (20-25 seconds) you'd do this:



ffmpeg -i abcdef.tvshow -t 5 a.tvshow -ss 10 -t 5 c.tvshow -ss 20 -t 5 e.tvshow


or



ffmpeg -i abcdef.tvshow -t 0:00:05 a.tvshow -ss 0:00:10 -t 0:00:05 c.tvshow -ss 0:00:20 -t 0:00:05 e.tvshow


That will make files a.tvshow, c.tvshow and e.tvshow. The -t says how long each clip is, so if c is 30 seconds long you could pass in 30 or 0:00:30. The -ss option says how far to skip into the source video, so it's always relative to the start of the file.



Then once you have a bunch of video files I make a file ace-files.txt like this:



file 'a.tvshow'
file 'c.tvshow'
file 'e.tvshow'


Note the "file" at the beginning and the escaped file name after that.



Then the command:



ffmpeg -f concat -i ace-files.txt -c copy ace.tvshow


That concats all the files in abe-files.txt together, copying their audio and video codecs and makes a file ace.tvshow which should just be sections a, c and e. Then just remember to delete ace-files.txt, a.tvshow, c.tvshow and e.tvshow.



Disclaimer: I have no idea how (in)efficient this is compared to the other approaches in terms of ffmpeg but for my purposes it works better. Hope it helps someone.






share|improve this answer

















  • 1




    this one is very understandable for newbies as me, thanks
    – juanpastas
    Apr 19 '15 at 21:48








  • 2




    Note if you are using bash, you can avoid the creation of a file (ace-files.txt in your example) with: ffmpeg -f concat -i <(printf "file '%s'n" $(pwd)/prefix_*.tvshow) -c copy output.tvshow
    – bufh
    Mar 31 '16 at 19:40










  • This was really helpful but I had to remove the single quotes from around file names or it didn't work.
    – tchaymore
    Jan 17 '18 at 18:08



















2














Although the answer provided by ptQa seems to work, I have developed an other solution which has prooved to work fine.



Essentially, what I do is to cut one video for each part of the original video that I want to include on my result. Later, I concatenate them with the Concat Demuxer explained here.



The solution is the same that waht I have tried first and presented sync problems. What I have added is the command -avoid_negative_ts 1 when generating the different videos. With this solution, the sync problems dissapear.






share|improve this answer





























    1














    I made a script to speed up editing recorded TV.
    The script asks you for the beginning and end times of segments you want to keep and splits them out into files. It gives you options, you can:




    • Take one or multiple segments.

    • You can combine the segments into one resulting file.

    • After joining you can keep or delete the part files.

    • You can keep the original file or replace it with your new file.


    Video of it in action: here



    Let me know what you think.



     #!/bin/bash
    /bin/date >>segmenter.log

    function segment (){
    while true; do
    echo "Would you like to cut out a segment ?"
    echo -e "1) Yesn2) Non3) Quit"
    read CHOICE
    if [ "$CHOICE" == "3" ]; then
    exit
    elif [ "$CHOICE" == "2" ]; then
    clear
    break
    elif [ "$CHOICE" == "1" ]; then
    clear
    ((segments++))
    echo "What time does segment $segments start ?"
    read SEGSTART
    clear
    echo -e "Segment $segments start set to $SEGSTARTn"
    echo "What time does segment $segments end ?"
    read SEGEND
    clear
    echo -e "Segment $segments end set to $SEGENDn"
    break
    else
    clear
    echo -e "Bad option"
    segment "$segments"
    fi
    done
    if [ "$CHOICE" == "1" ]; then
    echo "Cutting file $file video segment $segments starting at $SEGSTART and ending at $SEGEND"
    ffmpeg -i "$file" -ss $SEGSTART -to $SEGEND -map 0:0 -map 0:1 -c:a copy -c:v copy "$filename-part$segments.$extension" >> segmenter.log 2>&1
    clear
    echo -e "Cut file $filename-part$segments.$extension starting at $SEGSTART and ending at $SEGENDn"
    segment "$segments"
    fi
    }

    file="$1"
    filename="${file%.*}"
    extension="${file##*.}"
    clear
    segments=0
    segment "$segments"
    clear
    if (("$segments"==1)); then
    mv $filename"-part1."$extension "$filename-segmented.$extension"
    elif (("$segments">1)); then
    echo "Would you like to join the segments into one file ?"
    OPTIONS="Yes No Quit"
    select opt in $OPTIONS; do
    clear
    if [ "$opt" == "Quit" ]; then
    exit
    elif [ "$opt" == "Yes" ]; then
    clear
    echo "Joining segments"
    ffmpeg -f concat -i <(for f in $filename"-part"*$extension; do echo "file '$(pwd)/$f'"; done) -c:a copy -c:v copy "$filename-segmented.$extension" >> segmenter.log 2>&1
    clear
    echo "Would you like to delete the part files ?"
    select opt in $OPTIONS; do
    clear
    if [ "$opt" == "Quit" ]; then
    exit
    elif [ "$opt" == "Yes" ]; then
    for f in $filename"-part"*$extension; do rm $f; done
    break
    elif [ "$opt" == "No" ]; then
    break
    else
    clear
    echo -e "Bad optionn"
    fi
    done
    break
    clear
    elif [ "$opt" == "No" ]; then
    exit
    else
    clear
    echo -e "Bad optionn"
    fi
    done
    fi
    echo "Would you like to replace the original file with the result of your changes ?"
    OPTIONS="Yes No Quit"
    select opt in $OPTIONS; do
    clear
    if [ "$opt" == "Quit" ]; then
    exit
    elif [ "$opt" == "Yes" ]; then
    rm $file
    mv "$filename-segmented.$extension" $file
    break
    elif [ "$opt" == "No" ]; then
    break
    else
    clear
    echo -e "Bad optionn"
    fi
    done





    share|improve this answer























      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "3"
      };
      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%2fsuperuser.com%2fquestions%2f681885%2fhow-can-i-remove-multiple-segments-from-a-video-using-ffmpeg%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      42














      Well, you still can use the trim filter for that. Here is an example, lets assume that you want to cut out segments 30-40 sec (10 sec) and 50-80 sec (30 sec):



      ffmpeg -i in.ts -filter_complex 
      "[0:v]trim=duration=30[a];
      [0:v]trim=start=40:end=50,setpts=PTS-STARTPTS[b];
      [a][b]concat[c];
      [0:v]trim=start=80,setpts=PTS-STARTPTS[d];
      [c][d]concat[out1]" -map [out1] out.ts


      What I did here? I trimmed first 30 sec, 40-50 sec and 80 sec to end, and then combined them into stream out1 with the concat filter.



      About setpts: we need this because trim does not modify picture display time, and when we cut out 10 sec decoder counter does not see any frames for this 10 sec.



      If you want to have audio too, You have to do the same for audio streams. So the command should be:



      ffmpeg -i utv.ts -filter_complex 
      "[0:v]trim=duration=30[av];[0:a]atrim=duration=30[aa];
      [0:v]trim=start=40:end=50,setpts=PTS-STARTPTS[bv];
      [0:a]atrim=start=40:end=50,asetpts=PTS-STARTPTS[ba];
      [av][bv]concat[cv];[aa][ba]concat=v=0:a=1[ca];
      [0:v]trim=start=80,setpts=PTS-STARTPTS[dv];
      [0:a]atrim=start=80,asetpts=PTS-STARTPTS[da];
      [cv][dv]concat[outv];[ca][da]concat=v=0:a=1[outa]" -map [outv] -map [outa] out.ts





      share|improve this answer























      • Great one! Why do we need setpts? Could you add the explanation?
        – Rajib
        Dec 1 '13 at 4:32










      • Ok, see updated answer.
        – ptQa
        Dec 2 '13 at 7:41






      • 4




        +1 This really should be selected as the answer. It is more suited for "multiple segments" and removes the necessity to perform multiple commands one after another. (unless another way is more speed efficient)
        – Knossos
        Dec 17 '13 at 10:19












      • For the record, when I tried this with serveral segments (about 8) I got an error message about a "buffer queue overflow" and the program crashed. I don't know which versions are affected by this, but I wouldn't want to use this method for that reason.
        – Wutaz
        Feb 13 '14 at 22:35






      • 1




        How would you go about maintaining subtitle data when you're skipping frames?
        – Andrew Scagnelli
        Mar 2 '15 at 14:46
















      42














      Well, you still can use the trim filter for that. Here is an example, lets assume that you want to cut out segments 30-40 sec (10 sec) and 50-80 sec (30 sec):



      ffmpeg -i in.ts -filter_complex 
      "[0:v]trim=duration=30[a];
      [0:v]trim=start=40:end=50,setpts=PTS-STARTPTS[b];
      [a][b]concat[c];
      [0:v]trim=start=80,setpts=PTS-STARTPTS[d];
      [c][d]concat[out1]" -map [out1] out.ts


      What I did here? I trimmed first 30 sec, 40-50 sec and 80 sec to end, and then combined them into stream out1 with the concat filter.



      About setpts: we need this because trim does not modify picture display time, and when we cut out 10 sec decoder counter does not see any frames for this 10 sec.



      If you want to have audio too, You have to do the same for audio streams. So the command should be:



      ffmpeg -i utv.ts -filter_complex 
      "[0:v]trim=duration=30[av];[0:a]atrim=duration=30[aa];
      [0:v]trim=start=40:end=50,setpts=PTS-STARTPTS[bv];
      [0:a]atrim=start=40:end=50,asetpts=PTS-STARTPTS[ba];
      [av][bv]concat[cv];[aa][ba]concat=v=0:a=1[ca];
      [0:v]trim=start=80,setpts=PTS-STARTPTS[dv];
      [0:a]atrim=start=80,asetpts=PTS-STARTPTS[da];
      [cv][dv]concat[outv];[ca][da]concat=v=0:a=1[outa]" -map [outv] -map [outa] out.ts





      share|improve this answer























      • Great one! Why do we need setpts? Could you add the explanation?
        – Rajib
        Dec 1 '13 at 4:32










      • Ok, see updated answer.
        – ptQa
        Dec 2 '13 at 7:41






      • 4




        +1 This really should be selected as the answer. It is more suited for "multiple segments" and removes the necessity to perform multiple commands one after another. (unless another way is more speed efficient)
        – Knossos
        Dec 17 '13 at 10:19












      • For the record, when I tried this with serveral segments (about 8) I got an error message about a "buffer queue overflow" and the program crashed. I don't know which versions are affected by this, but I wouldn't want to use this method for that reason.
        – Wutaz
        Feb 13 '14 at 22:35






      • 1




        How would you go about maintaining subtitle data when you're skipping frames?
        – Andrew Scagnelli
        Mar 2 '15 at 14:46














      42












      42








      42






      Well, you still can use the trim filter for that. Here is an example, lets assume that you want to cut out segments 30-40 sec (10 sec) and 50-80 sec (30 sec):



      ffmpeg -i in.ts -filter_complex 
      "[0:v]trim=duration=30[a];
      [0:v]trim=start=40:end=50,setpts=PTS-STARTPTS[b];
      [a][b]concat[c];
      [0:v]trim=start=80,setpts=PTS-STARTPTS[d];
      [c][d]concat[out1]" -map [out1] out.ts


      What I did here? I trimmed first 30 sec, 40-50 sec and 80 sec to end, and then combined them into stream out1 with the concat filter.



      About setpts: we need this because trim does not modify picture display time, and when we cut out 10 sec decoder counter does not see any frames for this 10 sec.



      If you want to have audio too, You have to do the same for audio streams. So the command should be:



      ffmpeg -i utv.ts -filter_complex 
      "[0:v]trim=duration=30[av];[0:a]atrim=duration=30[aa];
      [0:v]trim=start=40:end=50,setpts=PTS-STARTPTS[bv];
      [0:a]atrim=start=40:end=50,asetpts=PTS-STARTPTS[ba];
      [av][bv]concat[cv];[aa][ba]concat=v=0:a=1[ca];
      [0:v]trim=start=80,setpts=PTS-STARTPTS[dv];
      [0:a]atrim=start=80,asetpts=PTS-STARTPTS[da];
      [cv][dv]concat[outv];[ca][da]concat=v=0:a=1[outa]" -map [outv] -map [outa] out.ts





      share|improve this answer














      Well, you still can use the trim filter for that. Here is an example, lets assume that you want to cut out segments 30-40 sec (10 sec) and 50-80 sec (30 sec):



      ffmpeg -i in.ts -filter_complex 
      "[0:v]trim=duration=30[a];
      [0:v]trim=start=40:end=50,setpts=PTS-STARTPTS[b];
      [a][b]concat[c];
      [0:v]trim=start=80,setpts=PTS-STARTPTS[d];
      [c][d]concat[out1]" -map [out1] out.ts


      What I did here? I trimmed first 30 sec, 40-50 sec and 80 sec to end, and then combined them into stream out1 with the concat filter.



      About setpts: we need this because trim does not modify picture display time, and when we cut out 10 sec decoder counter does not see any frames for this 10 sec.



      If you want to have audio too, You have to do the same for audio streams. So the command should be:



      ffmpeg -i utv.ts -filter_complex 
      "[0:v]trim=duration=30[av];[0:a]atrim=duration=30[aa];
      [0:v]trim=start=40:end=50,setpts=PTS-STARTPTS[bv];
      [0:a]atrim=start=40:end=50,asetpts=PTS-STARTPTS[ba];
      [av][bv]concat[cv];[aa][ba]concat=v=0:a=1[ca];
      [0:v]trim=start=80,setpts=PTS-STARTPTS[dv];
      [0:a]atrim=start=80,asetpts=PTS-STARTPTS[da];
      [cv][dv]concat[outv];[ca][da]concat=v=0:a=1[outa]" -map [outv] -map [outa] out.ts






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Apr 1 '14 at 10:48

























      answered Nov 30 '13 at 20:57









      ptQa

      1,424812




      1,424812












      • Great one! Why do we need setpts? Could you add the explanation?
        – Rajib
        Dec 1 '13 at 4:32










      • Ok, see updated answer.
        – ptQa
        Dec 2 '13 at 7:41






      • 4




        +1 This really should be selected as the answer. It is more suited for "multiple segments" and removes the necessity to perform multiple commands one after another. (unless another way is more speed efficient)
        – Knossos
        Dec 17 '13 at 10:19












      • For the record, when I tried this with serveral segments (about 8) I got an error message about a "buffer queue overflow" and the program crashed. I don't know which versions are affected by this, but I wouldn't want to use this method for that reason.
        – Wutaz
        Feb 13 '14 at 22:35






      • 1




        How would you go about maintaining subtitle data when you're skipping frames?
        – Andrew Scagnelli
        Mar 2 '15 at 14:46


















      • Great one! Why do we need setpts? Could you add the explanation?
        – Rajib
        Dec 1 '13 at 4:32










      • Ok, see updated answer.
        – ptQa
        Dec 2 '13 at 7:41






      • 4




        +1 This really should be selected as the answer. It is more suited for "multiple segments" and removes the necessity to perform multiple commands one after another. (unless another way is more speed efficient)
        – Knossos
        Dec 17 '13 at 10:19












      • For the record, when I tried this with serveral segments (about 8) I got an error message about a "buffer queue overflow" and the program crashed. I don't know which versions are affected by this, but I wouldn't want to use this method for that reason.
        – Wutaz
        Feb 13 '14 at 22:35






      • 1




        How would you go about maintaining subtitle data when you're skipping frames?
        – Andrew Scagnelli
        Mar 2 '15 at 14:46
















      Great one! Why do we need setpts? Could you add the explanation?
      – Rajib
      Dec 1 '13 at 4:32




      Great one! Why do we need setpts? Could you add the explanation?
      – Rajib
      Dec 1 '13 at 4:32












      Ok, see updated answer.
      – ptQa
      Dec 2 '13 at 7:41




      Ok, see updated answer.
      – ptQa
      Dec 2 '13 at 7:41




      4




      4




      +1 This really should be selected as the answer. It is more suited for "multiple segments" and removes the necessity to perform multiple commands one after another. (unless another way is more speed efficient)
      – Knossos
      Dec 17 '13 at 10:19






      +1 This really should be selected as the answer. It is more suited for "multiple segments" and removes the necessity to perform multiple commands one after another. (unless another way is more speed efficient)
      – Knossos
      Dec 17 '13 at 10:19














      For the record, when I tried this with serveral segments (about 8) I got an error message about a "buffer queue overflow" and the program crashed. I don't know which versions are affected by this, but I wouldn't want to use this method for that reason.
      – Wutaz
      Feb 13 '14 at 22:35




      For the record, when I tried this with serveral segments (about 8) I got an error message about a "buffer queue overflow" and the program crashed. I don't know which versions are affected by this, but I wouldn't want to use this method for that reason.
      – Wutaz
      Feb 13 '14 at 22:35




      1




      1




      How would you go about maintaining subtitle data when you're skipping frames?
      – Andrew Scagnelli
      Mar 2 '15 at 14:46




      How would you go about maintaining subtitle data when you're skipping frames?
      – Andrew Scagnelli
      Mar 2 '15 at 14:46













      12














      I can never get ptQa's solution to work, mostly because I can never figure out what the errors from the filters mean or how to fix them. My solution seems a little clunkier because it can leave behind a mess, but if you're throwing it into a script, the clean up can be automated. I also like this approach because if something goes wrong on step 4, you end up with completed steps 1-3 so recovering from errors is a little more efficient.



      The basic strategy is using -t and -ss to get videos of each segment you want, then join together all the parts for your final version.



      Say you have 6 segments ABCDEF each 5 seconds long and you want A (0-5 seconds), C (10-15 seconds) and E (20-25 seconds) you'd do this:



      ffmpeg -i abcdef.tvshow -t 5 a.tvshow -ss 10 -t 5 c.tvshow -ss 20 -t 5 e.tvshow


      or



      ffmpeg -i abcdef.tvshow -t 0:00:05 a.tvshow -ss 0:00:10 -t 0:00:05 c.tvshow -ss 0:00:20 -t 0:00:05 e.tvshow


      That will make files a.tvshow, c.tvshow and e.tvshow. The -t says how long each clip is, so if c is 30 seconds long you could pass in 30 or 0:00:30. The -ss option says how far to skip into the source video, so it's always relative to the start of the file.



      Then once you have a bunch of video files I make a file ace-files.txt like this:



      file 'a.tvshow'
      file 'c.tvshow'
      file 'e.tvshow'


      Note the "file" at the beginning and the escaped file name after that.



      Then the command:



      ffmpeg -f concat -i ace-files.txt -c copy ace.tvshow


      That concats all the files in abe-files.txt together, copying their audio and video codecs and makes a file ace.tvshow which should just be sections a, c and e. Then just remember to delete ace-files.txt, a.tvshow, c.tvshow and e.tvshow.



      Disclaimer: I have no idea how (in)efficient this is compared to the other approaches in terms of ffmpeg but for my purposes it works better. Hope it helps someone.






      share|improve this answer

















      • 1




        this one is very understandable for newbies as me, thanks
        – juanpastas
        Apr 19 '15 at 21:48








      • 2




        Note if you are using bash, you can avoid the creation of a file (ace-files.txt in your example) with: ffmpeg -f concat -i <(printf "file '%s'n" $(pwd)/prefix_*.tvshow) -c copy output.tvshow
        – bufh
        Mar 31 '16 at 19:40










      • This was really helpful but I had to remove the single quotes from around file names or it didn't work.
        – tchaymore
        Jan 17 '18 at 18:08
















      12














      I can never get ptQa's solution to work, mostly because I can never figure out what the errors from the filters mean or how to fix them. My solution seems a little clunkier because it can leave behind a mess, but if you're throwing it into a script, the clean up can be automated. I also like this approach because if something goes wrong on step 4, you end up with completed steps 1-3 so recovering from errors is a little more efficient.



      The basic strategy is using -t and -ss to get videos of each segment you want, then join together all the parts for your final version.



      Say you have 6 segments ABCDEF each 5 seconds long and you want A (0-5 seconds), C (10-15 seconds) and E (20-25 seconds) you'd do this:



      ffmpeg -i abcdef.tvshow -t 5 a.tvshow -ss 10 -t 5 c.tvshow -ss 20 -t 5 e.tvshow


      or



      ffmpeg -i abcdef.tvshow -t 0:00:05 a.tvshow -ss 0:00:10 -t 0:00:05 c.tvshow -ss 0:00:20 -t 0:00:05 e.tvshow


      That will make files a.tvshow, c.tvshow and e.tvshow. The -t says how long each clip is, so if c is 30 seconds long you could pass in 30 or 0:00:30. The -ss option says how far to skip into the source video, so it's always relative to the start of the file.



      Then once you have a bunch of video files I make a file ace-files.txt like this:



      file 'a.tvshow'
      file 'c.tvshow'
      file 'e.tvshow'


      Note the "file" at the beginning and the escaped file name after that.



      Then the command:



      ffmpeg -f concat -i ace-files.txt -c copy ace.tvshow


      That concats all the files in abe-files.txt together, copying their audio and video codecs and makes a file ace.tvshow which should just be sections a, c and e. Then just remember to delete ace-files.txt, a.tvshow, c.tvshow and e.tvshow.



      Disclaimer: I have no idea how (in)efficient this is compared to the other approaches in terms of ffmpeg but for my purposes it works better. Hope it helps someone.






      share|improve this answer

















      • 1




        this one is very understandable for newbies as me, thanks
        – juanpastas
        Apr 19 '15 at 21:48








      • 2




        Note if you are using bash, you can avoid the creation of a file (ace-files.txt in your example) with: ffmpeg -f concat -i <(printf "file '%s'n" $(pwd)/prefix_*.tvshow) -c copy output.tvshow
        – bufh
        Mar 31 '16 at 19:40










      • This was really helpful but I had to remove the single quotes from around file names or it didn't work.
        – tchaymore
        Jan 17 '18 at 18:08














      12












      12








      12






      I can never get ptQa's solution to work, mostly because I can never figure out what the errors from the filters mean or how to fix them. My solution seems a little clunkier because it can leave behind a mess, but if you're throwing it into a script, the clean up can be automated. I also like this approach because if something goes wrong on step 4, you end up with completed steps 1-3 so recovering from errors is a little more efficient.



      The basic strategy is using -t and -ss to get videos of each segment you want, then join together all the parts for your final version.



      Say you have 6 segments ABCDEF each 5 seconds long and you want A (0-5 seconds), C (10-15 seconds) and E (20-25 seconds) you'd do this:



      ffmpeg -i abcdef.tvshow -t 5 a.tvshow -ss 10 -t 5 c.tvshow -ss 20 -t 5 e.tvshow


      or



      ffmpeg -i abcdef.tvshow -t 0:00:05 a.tvshow -ss 0:00:10 -t 0:00:05 c.tvshow -ss 0:00:20 -t 0:00:05 e.tvshow


      That will make files a.tvshow, c.tvshow and e.tvshow. The -t says how long each clip is, so if c is 30 seconds long you could pass in 30 or 0:00:30. The -ss option says how far to skip into the source video, so it's always relative to the start of the file.



      Then once you have a bunch of video files I make a file ace-files.txt like this:



      file 'a.tvshow'
      file 'c.tvshow'
      file 'e.tvshow'


      Note the "file" at the beginning and the escaped file name after that.



      Then the command:



      ffmpeg -f concat -i ace-files.txt -c copy ace.tvshow


      That concats all the files in abe-files.txt together, copying their audio and video codecs and makes a file ace.tvshow which should just be sections a, c and e. Then just remember to delete ace-files.txt, a.tvshow, c.tvshow and e.tvshow.



      Disclaimer: I have no idea how (in)efficient this is compared to the other approaches in terms of ffmpeg but for my purposes it works better. Hope it helps someone.






      share|improve this answer












      I can never get ptQa's solution to work, mostly because I can never figure out what the errors from the filters mean or how to fix them. My solution seems a little clunkier because it can leave behind a mess, but if you're throwing it into a script, the clean up can be automated. I also like this approach because if something goes wrong on step 4, you end up with completed steps 1-3 so recovering from errors is a little more efficient.



      The basic strategy is using -t and -ss to get videos of each segment you want, then join together all the parts for your final version.



      Say you have 6 segments ABCDEF each 5 seconds long and you want A (0-5 seconds), C (10-15 seconds) and E (20-25 seconds) you'd do this:



      ffmpeg -i abcdef.tvshow -t 5 a.tvshow -ss 10 -t 5 c.tvshow -ss 20 -t 5 e.tvshow


      or



      ffmpeg -i abcdef.tvshow -t 0:00:05 a.tvshow -ss 0:00:10 -t 0:00:05 c.tvshow -ss 0:00:20 -t 0:00:05 e.tvshow


      That will make files a.tvshow, c.tvshow and e.tvshow. The -t says how long each clip is, so if c is 30 seconds long you could pass in 30 or 0:00:30. The -ss option says how far to skip into the source video, so it's always relative to the start of the file.



      Then once you have a bunch of video files I make a file ace-files.txt like this:



      file 'a.tvshow'
      file 'c.tvshow'
      file 'e.tvshow'


      Note the "file" at the beginning and the escaped file name after that.



      Then the command:



      ffmpeg -f concat -i ace-files.txt -c copy ace.tvshow


      That concats all the files in abe-files.txt together, copying their audio and video codecs and makes a file ace.tvshow which should just be sections a, c and e. Then just remember to delete ace-files.txt, a.tvshow, c.tvshow and e.tvshow.



      Disclaimer: I have no idea how (in)efficient this is compared to the other approaches in terms of ffmpeg but for my purposes it works better. Hope it helps someone.







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Jan 11 '15 at 20:03









      xbakesx

      25148




      25148








      • 1




        this one is very understandable for newbies as me, thanks
        – juanpastas
        Apr 19 '15 at 21:48








      • 2




        Note if you are using bash, you can avoid the creation of a file (ace-files.txt in your example) with: ffmpeg -f concat -i <(printf "file '%s'n" $(pwd)/prefix_*.tvshow) -c copy output.tvshow
        – bufh
        Mar 31 '16 at 19:40










      • This was really helpful but I had to remove the single quotes from around file names or it didn't work.
        – tchaymore
        Jan 17 '18 at 18:08














      • 1




        this one is very understandable for newbies as me, thanks
        – juanpastas
        Apr 19 '15 at 21:48








      • 2




        Note if you are using bash, you can avoid the creation of a file (ace-files.txt in your example) with: ffmpeg -f concat -i <(printf "file '%s'n" $(pwd)/prefix_*.tvshow) -c copy output.tvshow
        – bufh
        Mar 31 '16 at 19:40










      • This was really helpful but I had to remove the single quotes from around file names or it didn't work.
        – tchaymore
        Jan 17 '18 at 18:08








      1




      1




      this one is very understandable for newbies as me, thanks
      – juanpastas
      Apr 19 '15 at 21:48






      this one is very understandable for newbies as me, thanks
      – juanpastas
      Apr 19 '15 at 21:48






      2




      2




      Note if you are using bash, you can avoid the creation of a file (ace-files.txt in your example) with: ffmpeg -f concat -i <(printf "file '%s'n" $(pwd)/prefix_*.tvshow) -c copy output.tvshow
      – bufh
      Mar 31 '16 at 19:40




      Note if you are using bash, you can avoid the creation of a file (ace-files.txt in your example) with: ffmpeg -f concat -i <(printf "file '%s'n" $(pwd)/prefix_*.tvshow) -c copy output.tvshow
      – bufh
      Mar 31 '16 at 19:40












      This was really helpful but I had to remove the single quotes from around file names or it didn't work.
      – tchaymore
      Jan 17 '18 at 18:08




      This was really helpful but I had to remove the single quotes from around file names or it didn't work.
      – tchaymore
      Jan 17 '18 at 18:08











      2














      Although the answer provided by ptQa seems to work, I have developed an other solution which has prooved to work fine.



      Essentially, what I do is to cut one video for each part of the original video that I want to include on my result. Later, I concatenate them with the Concat Demuxer explained here.



      The solution is the same that waht I have tried first and presented sync problems. What I have added is the command -avoid_negative_ts 1 when generating the different videos. With this solution, the sync problems dissapear.






      share|improve this answer


























        2














        Although the answer provided by ptQa seems to work, I have developed an other solution which has prooved to work fine.



        Essentially, what I do is to cut one video for each part of the original video that I want to include on my result. Later, I concatenate them with the Concat Demuxer explained here.



        The solution is the same that waht I have tried first and presented sync problems. What I have added is the command -avoid_negative_ts 1 when generating the different videos. With this solution, the sync problems dissapear.






        share|improve this answer
























          2












          2








          2






          Although the answer provided by ptQa seems to work, I have developed an other solution which has prooved to work fine.



          Essentially, what I do is to cut one video for each part of the original video that I want to include on my result. Later, I concatenate them with the Concat Demuxer explained here.



          The solution is the same that waht I have tried first and presented sync problems. What I have added is the command -avoid_negative_ts 1 when generating the different videos. With this solution, the sync problems dissapear.






          share|improve this answer












          Although the answer provided by ptQa seems to work, I have developed an other solution which has prooved to work fine.



          Essentially, what I do is to cut one video for each part of the original video that I want to include on my result. Later, I concatenate them with the Concat Demuxer explained here.



          The solution is the same that waht I have tried first and presented sync problems. What I have added is the command -avoid_negative_ts 1 when generating the different videos. With this solution, the sync problems dissapear.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 2 '13 at 16:02









          Matias

          4381411




          4381411























              1














              I made a script to speed up editing recorded TV.
              The script asks you for the beginning and end times of segments you want to keep and splits them out into files. It gives you options, you can:




              • Take one or multiple segments.

              • You can combine the segments into one resulting file.

              • After joining you can keep or delete the part files.

              • You can keep the original file or replace it with your new file.


              Video of it in action: here



              Let me know what you think.



               #!/bin/bash
              /bin/date >>segmenter.log

              function segment (){
              while true; do
              echo "Would you like to cut out a segment ?"
              echo -e "1) Yesn2) Non3) Quit"
              read CHOICE
              if [ "$CHOICE" == "3" ]; then
              exit
              elif [ "$CHOICE" == "2" ]; then
              clear
              break
              elif [ "$CHOICE" == "1" ]; then
              clear
              ((segments++))
              echo "What time does segment $segments start ?"
              read SEGSTART
              clear
              echo -e "Segment $segments start set to $SEGSTARTn"
              echo "What time does segment $segments end ?"
              read SEGEND
              clear
              echo -e "Segment $segments end set to $SEGENDn"
              break
              else
              clear
              echo -e "Bad option"
              segment "$segments"
              fi
              done
              if [ "$CHOICE" == "1" ]; then
              echo "Cutting file $file video segment $segments starting at $SEGSTART and ending at $SEGEND"
              ffmpeg -i "$file" -ss $SEGSTART -to $SEGEND -map 0:0 -map 0:1 -c:a copy -c:v copy "$filename-part$segments.$extension" >> segmenter.log 2>&1
              clear
              echo -e "Cut file $filename-part$segments.$extension starting at $SEGSTART and ending at $SEGENDn"
              segment "$segments"
              fi
              }

              file="$1"
              filename="${file%.*}"
              extension="${file##*.}"
              clear
              segments=0
              segment "$segments"
              clear
              if (("$segments"==1)); then
              mv $filename"-part1."$extension "$filename-segmented.$extension"
              elif (("$segments">1)); then
              echo "Would you like to join the segments into one file ?"
              OPTIONS="Yes No Quit"
              select opt in $OPTIONS; do
              clear
              if [ "$opt" == "Quit" ]; then
              exit
              elif [ "$opt" == "Yes" ]; then
              clear
              echo "Joining segments"
              ffmpeg -f concat -i <(for f in $filename"-part"*$extension; do echo "file '$(pwd)/$f'"; done) -c:a copy -c:v copy "$filename-segmented.$extension" >> segmenter.log 2>&1
              clear
              echo "Would you like to delete the part files ?"
              select opt in $OPTIONS; do
              clear
              if [ "$opt" == "Quit" ]; then
              exit
              elif [ "$opt" == "Yes" ]; then
              for f in $filename"-part"*$extension; do rm $f; done
              break
              elif [ "$opt" == "No" ]; then
              break
              else
              clear
              echo -e "Bad optionn"
              fi
              done
              break
              clear
              elif [ "$opt" == "No" ]; then
              exit
              else
              clear
              echo -e "Bad optionn"
              fi
              done
              fi
              echo "Would you like to replace the original file with the result of your changes ?"
              OPTIONS="Yes No Quit"
              select opt in $OPTIONS; do
              clear
              if [ "$opt" == "Quit" ]; then
              exit
              elif [ "$opt" == "Yes" ]; then
              rm $file
              mv "$filename-segmented.$extension" $file
              break
              elif [ "$opt" == "No" ]; then
              break
              else
              clear
              echo -e "Bad optionn"
              fi
              done





              share|improve this answer




























                1














                I made a script to speed up editing recorded TV.
                The script asks you for the beginning and end times of segments you want to keep and splits them out into files. It gives you options, you can:




                • Take one or multiple segments.

                • You can combine the segments into one resulting file.

                • After joining you can keep or delete the part files.

                • You can keep the original file or replace it with your new file.


                Video of it in action: here



                Let me know what you think.



                 #!/bin/bash
                /bin/date >>segmenter.log

                function segment (){
                while true; do
                echo "Would you like to cut out a segment ?"
                echo -e "1) Yesn2) Non3) Quit"
                read CHOICE
                if [ "$CHOICE" == "3" ]; then
                exit
                elif [ "$CHOICE" == "2" ]; then
                clear
                break
                elif [ "$CHOICE" == "1" ]; then
                clear
                ((segments++))
                echo "What time does segment $segments start ?"
                read SEGSTART
                clear
                echo -e "Segment $segments start set to $SEGSTARTn"
                echo "What time does segment $segments end ?"
                read SEGEND
                clear
                echo -e "Segment $segments end set to $SEGENDn"
                break
                else
                clear
                echo -e "Bad option"
                segment "$segments"
                fi
                done
                if [ "$CHOICE" == "1" ]; then
                echo "Cutting file $file video segment $segments starting at $SEGSTART and ending at $SEGEND"
                ffmpeg -i "$file" -ss $SEGSTART -to $SEGEND -map 0:0 -map 0:1 -c:a copy -c:v copy "$filename-part$segments.$extension" >> segmenter.log 2>&1
                clear
                echo -e "Cut file $filename-part$segments.$extension starting at $SEGSTART and ending at $SEGENDn"
                segment "$segments"
                fi
                }

                file="$1"
                filename="${file%.*}"
                extension="${file##*.}"
                clear
                segments=0
                segment "$segments"
                clear
                if (("$segments"==1)); then
                mv $filename"-part1."$extension "$filename-segmented.$extension"
                elif (("$segments">1)); then
                echo "Would you like to join the segments into one file ?"
                OPTIONS="Yes No Quit"
                select opt in $OPTIONS; do
                clear
                if [ "$opt" == "Quit" ]; then
                exit
                elif [ "$opt" == "Yes" ]; then
                clear
                echo "Joining segments"
                ffmpeg -f concat -i <(for f in $filename"-part"*$extension; do echo "file '$(pwd)/$f'"; done) -c:a copy -c:v copy "$filename-segmented.$extension" >> segmenter.log 2>&1
                clear
                echo "Would you like to delete the part files ?"
                select opt in $OPTIONS; do
                clear
                if [ "$opt" == "Quit" ]; then
                exit
                elif [ "$opt" == "Yes" ]; then
                for f in $filename"-part"*$extension; do rm $f; done
                break
                elif [ "$opt" == "No" ]; then
                break
                else
                clear
                echo -e "Bad optionn"
                fi
                done
                break
                clear
                elif [ "$opt" == "No" ]; then
                exit
                else
                clear
                echo -e "Bad optionn"
                fi
                done
                fi
                echo "Would you like to replace the original file with the result of your changes ?"
                OPTIONS="Yes No Quit"
                select opt in $OPTIONS; do
                clear
                if [ "$opt" == "Quit" ]; then
                exit
                elif [ "$opt" == "Yes" ]; then
                rm $file
                mv "$filename-segmented.$extension" $file
                break
                elif [ "$opt" == "No" ]; then
                break
                else
                clear
                echo -e "Bad optionn"
                fi
                done





                share|improve this answer


























                  1












                  1








                  1






                  I made a script to speed up editing recorded TV.
                  The script asks you for the beginning and end times of segments you want to keep and splits them out into files. It gives you options, you can:




                  • Take one or multiple segments.

                  • You can combine the segments into one resulting file.

                  • After joining you can keep or delete the part files.

                  • You can keep the original file or replace it with your new file.


                  Video of it in action: here



                  Let me know what you think.



                   #!/bin/bash
                  /bin/date >>segmenter.log

                  function segment (){
                  while true; do
                  echo "Would you like to cut out a segment ?"
                  echo -e "1) Yesn2) Non3) Quit"
                  read CHOICE
                  if [ "$CHOICE" == "3" ]; then
                  exit
                  elif [ "$CHOICE" == "2" ]; then
                  clear
                  break
                  elif [ "$CHOICE" == "1" ]; then
                  clear
                  ((segments++))
                  echo "What time does segment $segments start ?"
                  read SEGSTART
                  clear
                  echo -e "Segment $segments start set to $SEGSTARTn"
                  echo "What time does segment $segments end ?"
                  read SEGEND
                  clear
                  echo -e "Segment $segments end set to $SEGENDn"
                  break
                  else
                  clear
                  echo -e "Bad option"
                  segment "$segments"
                  fi
                  done
                  if [ "$CHOICE" == "1" ]; then
                  echo "Cutting file $file video segment $segments starting at $SEGSTART and ending at $SEGEND"
                  ffmpeg -i "$file" -ss $SEGSTART -to $SEGEND -map 0:0 -map 0:1 -c:a copy -c:v copy "$filename-part$segments.$extension" >> segmenter.log 2>&1
                  clear
                  echo -e "Cut file $filename-part$segments.$extension starting at $SEGSTART and ending at $SEGENDn"
                  segment "$segments"
                  fi
                  }

                  file="$1"
                  filename="${file%.*}"
                  extension="${file##*.}"
                  clear
                  segments=0
                  segment "$segments"
                  clear
                  if (("$segments"==1)); then
                  mv $filename"-part1."$extension "$filename-segmented.$extension"
                  elif (("$segments">1)); then
                  echo "Would you like to join the segments into one file ?"
                  OPTIONS="Yes No Quit"
                  select opt in $OPTIONS; do
                  clear
                  if [ "$opt" == "Quit" ]; then
                  exit
                  elif [ "$opt" == "Yes" ]; then
                  clear
                  echo "Joining segments"
                  ffmpeg -f concat -i <(for f in $filename"-part"*$extension; do echo "file '$(pwd)/$f'"; done) -c:a copy -c:v copy "$filename-segmented.$extension" >> segmenter.log 2>&1
                  clear
                  echo "Would you like to delete the part files ?"
                  select opt in $OPTIONS; do
                  clear
                  if [ "$opt" == "Quit" ]; then
                  exit
                  elif [ "$opt" == "Yes" ]; then
                  for f in $filename"-part"*$extension; do rm $f; done
                  break
                  elif [ "$opt" == "No" ]; then
                  break
                  else
                  clear
                  echo -e "Bad optionn"
                  fi
                  done
                  break
                  clear
                  elif [ "$opt" == "No" ]; then
                  exit
                  else
                  clear
                  echo -e "Bad optionn"
                  fi
                  done
                  fi
                  echo "Would you like to replace the original file with the result of your changes ?"
                  OPTIONS="Yes No Quit"
                  select opt in $OPTIONS; do
                  clear
                  if [ "$opt" == "Quit" ]; then
                  exit
                  elif [ "$opt" == "Yes" ]; then
                  rm $file
                  mv "$filename-segmented.$extension" $file
                  break
                  elif [ "$opt" == "No" ]; then
                  break
                  else
                  clear
                  echo -e "Bad optionn"
                  fi
                  done





                  share|improve this answer














                  I made a script to speed up editing recorded TV.
                  The script asks you for the beginning and end times of segments you want to keep and splits them out into files. It gives you options, you can:




                  • Take one or multiple segments.

                  • You can combine the segments into one resulting file.

                  • After joining you can keep or delete the part files.

                  • You can keep the original file or replace it with your new file.


                  Video of it in action: here



                  Let me know what you think.



                   #!/bin/bash
                  /bin/date >>segmenter.log

                  function segment (){
                  while true; do
                  echo "Would you like to cut out a segment ?"
                  echo -e "1) Yesn2) Non3) Quit"
                  read CHOICE
                  if [ "$CHOICE" == "3" ]; then
                  exit
                  elif [ "$CHOICE" == "2" ]; then
                  clear
                  break
                  elif [ "$CHOICE" == "1" ]; then
                  clear
                  ((segments++))
                  echo "What time does segment $segments start ?"
                  read SEGSTART
                  clear
                  echo -e "Segment $segments start set to $SEGSTARTn"
                  echo "What time does segment $segments end ?"
                  read SEGEND
                  clear
                  echo -e "Segment $segments end set to $SEGENDn"
                  break
                  else
                  clear
                  echo -e "Bad option"
                  segment "$segments"
                  fi
                  done
                  if [ "$CHOICE" == "1" ]; then
                  echo "Cutting file $file video segment $segments starting at $SEGSTART and ending at $SEGEND"
                  ffmpeg -i "$file" -ss $SEGSTART -to $SEGEND -map 0:0 -map 0:1 -c:a copy -c:v copy "$filename-part$segments.$extension" >> segmenter.log 2>&1
                  clear
                  echo -e "Cut file $filename-part$segments.$extension starting at $SEGSTART and ending at $SEGENDn"
                  segment "$segments"
                  fi
                  }

                  file="$1"
                  filename="${file%.*}"
                  extension="${file##*.}"
                  clear
                  segments=0
                  segment "$segments"
                  clear
                  if (("$segments"==1)); then
                  mv $filename"-part1."$extension "$filename-segmented.$extension"
                  elif (("$segments">1)); then
                  echo "Would you like to join the segments into one file ?"
                  OPTIONS="Yes No Quit"
                  select opt in $OPTIONS; do
                  clear
                  if [ "$opt" == "Quit" ]; then
                  exit
                  elif [ "$opt" == "Yes" ]; then
                  clear
                  echo "Joining segments"
                  ffmpeg -f concat -i <(for f in $filename"-part"*$extension; do echo "file '$(pwd)/$f'"; done) -c:a copy -c:v copy "$filename-segmented.$extension" >> segmenter.log 2>&1
                  clear
                  echo "Would you like to delete the part files ?"
                  select opt in $OPTIONS; do
                  clear
                  if [ "$opt" == "Quit" ]; then
                  exit
                  elif [ "$opt" == "Yes" ]; then
                  for f in $filename"-part"*$extension; do rm $f; done
                  break
                  elif [ "$opt" == "No" ]; then
                  break
                  else
                  clear
                  echo -e "Bad optionn"
                  fi
                  done
                  break
                  clear
                  elif [ "$opt" == "No" ]; then
                  exit
                  else
                  clear
                  echo -e "Bad optionn"
                  fi
                  done
                  fi
                  echo "Would you like to replace the original file with the result of your changes ?"
                  OPTIONS="Yes No Quit"
                  select opt in $OPTIONS; do
                  clear
                  if [ "$opt" == "Quit" ]; then
                  exit
                  elif [ "$opt" == "Yes" ]; then
                  rm $file
                  mv "$filename-segmented.$extension" $file
                  break
                  elif [ "$opt" == "No" ]; then
                  break
                  else
                  clear
                  echo -e "Bad optionn"
                  fi
                  done






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Feb 21 '14 at 0:26

























                  answered Feb 20 '14 at 21:46









                  rocuinneagain

                  112




                  112






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Super User!


                      • 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.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • 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%2fsuperuser.com%2fquestions%2f681885%2fhow-can-i-remove-multiple-segments-from-a-video-using-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

                      Сан-Квентин

                      8-я гвардейская общевойсковая армия

                      Алькесар