How can I use ffmpeg to split MPEG video into 10 minute chunks?












50















There is often a need in the open source or active developer community to publish large video segments online. (Meet-up videos, campouts, tech talks...) Being that I am a developer and not a videographer I have no desire to fork out the extra scratch on a premium Vimeo account. How then do I take a 12.5 GB (1:20:00) MPEG tech talk video and slice it into 00:10:00 segments for easy uploading to video sharing sites?










share|improve this question

























  • Special thanks to @StevenD for accommodating the new tags.

    – Gabriel
    Sep 6 '10 at 17:24
















50















There is often a need in the open source or active developer community to publish large video segments online. (Meet-up videos, campouts, tech talks...) Being that I am a developer and not a videographer I have no desire to fork out the extra scratch on a premium Vimeo account. How then do I take a 12.5 GB (1:20:00) MPEG tech talk video and slice it into 00:10:00 segments for easy uploading to video sharing sites?










share|improve this question

























  • Special thanks to @StevenD for accommodating the new tags.

    – Gabriel
    Sep 6 '10 at 17:24














50












50








50


18






There is often a need in the open source or active developer community to publish large video segments online. (Meet-up videos, campouts, tech talks...) Being that I am a developer and not a videographer I have no desire to fork out the extra scratch on a premium Vimeo account. How then do I take a 12.5 GB (1:20:00) MPEG tech talk video and slice it into 00:10:00 segments for easy uploading to video sharing sites?










share|improve this question
















There is often a need in the open source or active developer community to publish large video segments online. (Meet-up videos, campouts, tech talks...) Being that I am a developer and not a videographer I have no desire to fork out the extra scratch on a premium Vimeo account. How then do I take a 12.5 GB (1:20:00) MPEG tech talk video and slice it into 00:10:00 segments for easy uploading to video sharing sites?







ffmpeg video-editing






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '14 at 1:05









Braiam

23.2k1976139




23.2k1976139










asked Sep 6 '10 at 16:16









GabrielGabriel

353138




353138













  • Special thanks to @StevenD for accommodating the new tags.

    – Gabriel
    Sep 6 '10 at 17:24



















  • Special thanks to @StevenD for accommodating the new tags.

    – Gabriel
    Sep 6 '10 at 17:24

















Special thanks to @StevenD for accommodating the new tags.

– Gabriel
Sep 6 '10 at 17:24





Special thanks to @StevenD for accommodating the new tags.

– Gabriel
Sep 6 '10 at 17:24










6 Answers
6






active

oldest

votes


















53














$ ffmpeg -i source-file.foo -ss 0 -t 600 first-10-min.m4v
$ ffmpeg -i source-file.foo -ss 600 -t 600 second-10-min.m4v
$ ffmpeg -i source-file.foo -ss 1200 -t 600 third-10-min.m4v
...


Wrapping this up into a script to do it in a loop wouldn't be hard.



Beware that if you try to calculate the number of iterations based on the duration output from an ffprobe call that this is estimated from the average bit rate at the start of the clip and the clip's file size unless you give the -count_frames argument, which slows its operation considerably.



Another thing to be aware of is that the position of the -ss option on the command line matters. Where I have it now is slow but accurate. The first version of this answer gave the fast but inaccurate alternative. The linked article also describes a mostly-fast-but-still-accurate alternative, which you pay for with a bit of complexity.



All that aside, I don't think you really want to be cutting at exactly 10 minutes for each clip. That will put cuts right in the middle of sentences, even words. I think you should be using a video editor or player to find natural cut points just shy of 10 minutes apart.



Assuming your file is in a format that YouTube can accept directly, you don't have to reencode to get segments. Just pass the natural cut point offsets to ffmpeg, telling it to pass the encoded A/V through untouched by using the "copy" codec:



$ ffmpeg -i source.m4v -ss 0 -t 593.3 -c copy part1.m4v
$ ffmpeg -i source.m4v -ss 593.3 -t 551.64 -c copy part2.m4v
$ ffmpeg -i source.m4v -ss 1144.94 -t 581.25 -c copy part3.m4v
...


The -c copy argument tells it to copy all input streams (audio, video, and potentially others, such as subtitles) into the output as-is. For simple A/V programs, it is equivalent to the more verbose flags -c:v copy -c:a copy or the old-style flags -vcodec copy -acodec copy. You would use the more verbose style when you want to copy only one of the streams, but re-encode the other. For example, many years ago there was a common practice with QuickTime files to compress the video with H.264 video but leave the audio as uncompressed PCM; if you ran across such a file today, you could modernize it with -c:v copy -c:a aac to reprocess just the audio stream, leaving the video untouched.



The start point for every command above after the first is the previous command's start point plus the previous command's duration.






share|improve this answer





















  • 1





    "cutting at exactly 10 minutes for each clip" is a good point.

    – Chris
    Sep 7 '10 at 11:42











  • maybe by using the -show_packets param you can make it more accurate.

    – rogerdpack
    Jun 13 '11 at 21:36











  • How can I find these "natural cut point offsets"?

    – JBernardo
    Sep 14 '12 at 19:58











  • I said it in the answer: "using a video editor or player." Load the video file up in one, scrub to near the 10 minute mark, then look for a reasonable place to cut. Record the time showing on the timecode display. Move forward another 10-minutes-minus-a-skosh. Repeat until done.

    – Warren Young
    Sep 14 '12 at 21:47













  • how to put above in a loop?

    – kRazzy R
    Dec 6 '17 at 19:32



















39














Here is the one line solution:



ffmpeg -i input.mp4 -c copy -map 0 -segment_time 00:20:00 -f segment output%03d.mp4


Please note that this does not give you accurate splits, but should fit your needs. It will instead cut at the first frame after the time specified after segment_time, in the code above it would be after the 20 minute mark.



If you find that only the first chunk is playable, try adding -reset_timestamps 1 as mentioned in the comments.



ffmpeg -i input.mp4 -c copy -map 0 -segment_time 00:20:00 -f segment -reset_timestamps 1 output%03d.mp4





share|improve this answer





















  • 2





    It actually gives you very accurate splits, if you value video quality. Rather than splitting based on a particular time, it splits on the nearest keyframe following the requested time, so each new segment always starts with a keyframe.

    – Malvineous
    Feb 25 '17 at 6:51






  • 3





    what are the units? 8s? 8min? 8h?

    – user1133275
    Mar 20 '17 at 20:58






  • 1





    @user1133275 its second

    – Jon
    Mar 20 '17 at 21:11






  • 2





    On Mac, I found that this resulted in N output video chunks but only the 1st of them was a valid, viewable MP4. The other N-1 chunks were blank video (all black) with no audio. To make it work, I needed to add the reset_timestamps flag like so: ffmpeg -i input.mp4 -c copy -map 0 -segment_time 8 -f segment -reset_timestamps 1 output%03d.mp4.

    – jarmod
    Jun 5 '17 at 15:32






  • 2





    found that adding -reset_timestamps 1 fixes the issue for me

    – jlarsch
    Oct 30 '17 at 8:27



















6














Faced the same problem earlier and put together a simple Python script to do just that (using FFMpeg). Available here: https://github.com/c0decracker/video-splitter, and pasted below:



#!/usr/bin/env python
import subprocess
import re
import math
from optparse import OptionParser
length_regexp = 'Duration: (d{2}):(d{2}):(d{2}).d+,'
re_length = re.compile(length_regexp)
def main():
(filename, split_length) = parse_options()
if split_length <= 0:
print "Split length can't be 0"
raise SystemExit
output = subprocess.Popen("ffmpeg -i '"+filename+"' 2>&1 | grep 'Duration'",
shell = True,
stdout = subprocess.PIPE
).stdout.read()
print output
matches = re_length.search(output)
if matches:
video_length = int(matches.group(1)) * 3600 +
int(matches.group(2)) * 60 +
int(matches.group(3))
print "Video length in seconds: "+str(video_length)
else:
print "Can't determine video length."
raise SystemExit
split_count = int(math.ceil(video_length/float(split_length)))
if(split_count == 1):
print "Video length is less then the target split length."
raise SystemExit
split_cmd = "ffmpeg -i '"+filename+"' -vcodec copy "
for n in range(0, split_count):
split_str = ""
if n == 0:
split_start = 0
else:
split_start = split_length * n
split_str += " -ss "+str(split_start)+" -t "+str(split_length) +
" '"+filename[:-4] + "-" + str(n) + "." + filename[-3:] +
"'"
print "About to run: "+split_cmd+split_str
output = subprocess.Popen(split_cmd+split_str, shell = True, stdout =
subprocess.PIPE).stdout.read()
def parse_options():
parser = OptionParser()
parser.add_option("-f", "--file",
dest = "filename",
help = "file to split, for example sample.avi",
type = "string",
action = "store"
)
parser.add_option("-s", "--split-size",
dest = "split_size",
help = "split or chunk size in seconds, for example 10",
type = "int",
action = "store"
)
(options, args) = parser.parse_args()
if options.filename and options.split_size:
return (options.filename, options.split_size)
else:
parser.print_help()
raise SystemExit
if __name__ == '__main__':
try:
main()
except Exception, e:
print "Exception occured running main():"
print str(e)





share|improve this answer





















  • 1





    Next time do this please in a comment. Link-only answers aren't really liked here, and the same if you advert your site. If it is an opensource project with source code, maybe it is an exception, but I now risked my reviewing privileges by not voting for the removal of your answer. And yes, you can't post comments, but after you collected 5 upvotes (which seems very fast in your case) you will.

    – peterh
    Nov 21 '14 at 0:40













  • Hi and welcome to the site. Please don't post link only answers. While your script itself would probably make a great answer, a link to it is not an answer. It is a signpost pointing to an answer. More on that here. Since you kindly gave the link, I went ahead and included the script in the body of your answer. If you object to that, please delete the answer altogether.

    – terdon
    Nov 21 '14 at 1:54



















2














Note the exact punctuation of the alternative format is -ss mm:ss.xxx. I struggled for hours trying to use the intuitive-but-wrong mm:ss:xx to no avail.



$ man ffmpeg | grep -C1 position



-ss position

Seek to given time position in seconds. "hh:mm:ss[.xxx]" syntax is also supported.




References here and here.






share|improve this answer

































    2














    If you want to create really same Chunks must force ffmpeg to create i-frame on the every chunks' first frame so you can use this command for create 0.5 second chunk.



    ffmpeg -hide_banner  -err_detect ignore_err -i input.mp4 -r 24 -codec:v libx264  -vsync 1  -codec:a aac  -ac 2  -ar 48k  -f segment   -preset fast  -segment_format mpegts  -segment_time 0.5 -force_key_frames  "expr: gte(t, n_forced * 0.5)" out%d.mkv





    share|improve this answer































      -2














      You shouldn't really be following any of the answers in this thread, instead just use what is built into ffmpeg to do exactly this.



      ffmpeg -i invid.mp4 -threads 3 -vcodec copy -f segment -segment_time 2 cam_out_h264%04d.mp4


      This will split it into roughly 2 second chucks, split at the relevant keyframes, and will output to the files
      cam_out_h2640001.mp4, cam_out_h2640002.mp4, etc.






      share|improve this answer

























        Your Answer








        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "106"
        };
        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: false,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        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%2funix.stackexchange.com%2fquestions%2f1670%2fhow-can-i-use-ffmpeg-to-split-mpeg-video-into-10-minute-chunks%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        6 Answers
        6






        active

        oldest

        votes








        6 Answers
        6






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        53














        $ ffmpeg -i source-file.foo -ss 0 -t 600 first-10-min.m4v
        $ ffmpeg -i source-file.foo -ss 600 -t 600 second-10-min.m4v
        $ ffmpeg -i source-file.foo -ss 1200 -t 600 third-10-min.m4v
        ...


        Wrapping this up into a script to do it in a loop wouldn't be hard.



        Beware that if you try to calculate the number of iterations based on the duration output from an ffprobe call that this is estimated from the average bit rate at the start of the clip and the clip's file size unless you give the -count_frames argument, which slows its operation considerably.



        Another thing to be aware of is that the position of the -ss option on the command line matters. Where I have it now is slow but accurate. The first version of this answer gave the fast but inaccurate alternative. The linked article also describes a mostly-fast-but-still-accurate alternative, which you pay for with a bit of complexity.



        All that aside, I don't think you really want to be cutting at exactly 10 minutes for each clip. That will put cuts right in the middle of sentences, even words. I think you should be using a video editor or player to find natural cut points just shy of 10 minutes apart.



        Assuming your file is in a format that YouTube can accept directly, you don't have to reencode to get segments. Just pass the natural cut point offsets to ffmpeg, telling it to pass the encoded A/V through untouched by using the "copy" codec:



        $ ffmpeg -i source.m4v -ss 0 -t 593.3 -c copy part1.m4v
        $ ffmpeg -i source.m4v -ss 593.3 -t 551.64 -c copy part2.m4v
        $ ffmpeg -i source.m4v -ss 1144.94 -t 581.25 -c copy part3.m4v
        ...


        The -c copy argument tells it to copy all input streams (audio, video, and potentially others, such as subtitles) into the output as-is. For simple A/V programs, it is equivalent to the more verbose flags -c:v copy -c:a copy or the old-style flags -vcodec copy -acodec copy. You would use the more verbose style when you want to copy only one of the streams, but re-encode the other. For example, many years ago there was a common practice with QuickTime files to compress the video with H.264 video but leave the audio as uncompressed PCM; if you ran across such a file today, you could modernize it with -c:v copy -c:a aac to reprocess just the audio stream, leaving the video untouched.



        The start point for every command above after the first is the previous command's start point plus the previous command's duration.






        share|improve this answer





















        • 1





          "cutting at exactly 10 minutes for each clip" is a good point.

          – Chris
          Sep 7 '10 at 11:42











        • maybe by using the -show_packets param you can make it more accurate.

          – rogerdpack
          Jun 13 '11 at 21:36











        • How can I find these "natural cut point offsets"?

          – JBernardo
          Sep 14 '12 at 19:58











        • I said it in the answer: "using a video editor or player." Load the video file up in one, scrub to near the 10 minute mark, then look for a reasonable place to cut. Record the time showing on the timecode display. Move forward another 10-minutes-minus-a-skosh. Repeat until done.

          – Warren Young
          Sep 14 '12 at 21:47













        • how to put above in a loop?

          – kRazzy R
          Dec 6 '17 at 19:32
















        53














        $ ffmpeg -i source-file.foo -ss 0 -t 600 first-10-min.m4v
        $ ffmpeg -i source-file.foo -ss 600 -t 600 second-10-min.m4v
        $ ffmpeg -i source-file.foo -ss 1200 -t 600 third-10-min.m4v
        ...


        Wrapping this up into a script to do it in a loop wouldn't be hard.



        Beware that if you try to calculate the number of iterations based on the duration output from an ffprobe call that this is estimated from the average bit rate at the start of the clip and the clip's file size unless you give the -count_frames argument, which slows its operation considerably.



        Another thing to be aware of is that the position of the -ss option on the command line matters. Where I have it now is slow but accurate. The first version of this answer gave the fast but inaccurate alternative. The linked article also describes a mostly-fast-but-still-accurate alternative, which you pay for with a bit of complexity.



        All that aside, I don't think you really want to be cutting at exactly 10 minutes for each clip. That will put cuts right in the middle of sentences, even words. I think you should be using a video editor or player to find natural cut points just shy of 10 minutes apart.



        Assuming your file is in a format that YouTube can accept directly, you don't have to reencode to get segments. Just pass the natural cut point offsets to ffmpeg, telling it to pass the encoded A/V through untouched by using the "copy" codec:



        $ ffmpeg -i source.m4v -ss 0 -t 593.3 -c copy part1.m4v
        $ ffmpeg -i source.m4v -ss 593.3 -t 551.64 -c copy part2.m4v
        $ ffmpeg -i source.m4v -ss 1144.94 -t 581.25 -c copy part3.m4v
        ...


        The -c copy argument tells it to copy all input streams (audio, video, and potentially others, such as subtitles) into the output as-is. For simple A/V programs, it is equivalent to the more verbose flags -c:v copy -c:a copy or the old-style flags -vcodec copy -acodec copy. You would use the more verbose style when you want to copy only one of the streams, but re-encode the other. For example, many years ago there was a common practice with QuickTime files to compress the video with H.264 video but leave the audio as uncompressed PCM; if you ran across such a file today, you could modernize it with -c:v copy -c:a aac to reprocess just the audio stream, leaving the video untouched.



        The start point for every command above after the first is the previous command's start point plus the previous command's duration.






        share|improve this answer





















        • 1





          "cutting at exactly 10 minutes for each clip" is a good point.

          – Chris
          Sep 7 '10 at 11:42











        • maybe by using the -show_packets param you can make it more accurate.

          – rogerdpack
          Jun 13 '11 at 21:36











        • How can I find these "natural cut point offsets"?

          – JBernardo
          Sep 14 '12 at 19:58











        • I said it in the answer: "using a video editor or player." Load the video file up in one, scrub to near the 10 minute mark, then look for a reasonable place to cut. Record the time showing on the timecode display. Move forward another 10-minutes-minus-a-skosh. Repeat until done.

          – Warren Young
          Sep 14 '12 at 21:47













        • how to put above in a loop?

          – kRazzy R
          Dec 6 '17 at 19:32














        53












        53








        53







        $ ffmpeg -i source-file.foo -ss 0 -t 600 first-10-min.m4v
        $ ffmpeg -i source-file.foo -ss 600 -t 600 second-10-min.m4v
        $ ffmpeg -i source-file.foo -ss 1200 -t 600 third-10-min.m4v
        ...


        Wrapping this up into a script to do it in a loop wouldn't be hard.



        Beware that if you try to calculate the number of iterations based on the duration output from an ffprobe call that this is estimated from the average bit rate at the start of the clip and the clip's file size unless you give the -count_frames argument, which slows its operation considerably.



        Another thing to be aware of is that the position of the -ss option on the command line matters. Where I have it now is slow but accurate. The first version of this answer gave the fast but inaccurate alternative. The linked article also describes a mostly-fast-but-still-accurate alternative, which you pay for with a bit of complexity.



        All that aside, I don't think you really want to be cutting at exactly 10 minutes for each clip. That will put cuts right in the middle of sentences, even words. I think you should be using a video editor or player to find natural cut points just shy of 10 minutes apart.



        Assuming your file is in a format that YouTube can accept directly, you don't have to reencode to get segments. Just pass the natural cut point offsets to ffmpeg, telling it to pass the encoded A/V through untouched by using the "copy" codec:



        $ ffmpeg -i source.m4v -ss 0 -t 593.3 -c copy part1.m4v
        $ ffmpeg -i source.m4v -ss 593.3 -t 551.64 -c copy part2.m4v
        $ ffmpeg -i source.m4v -ss 1144.94 -t 581.25 -c copy part3.m4v
        ...


        The -c copy argument tells it to copy all input streams (audio, video, and potentially others, such as subtitles) into the output as-is. For simple A/V programs, it is equivalent to the more verbose flags -c:v copy -c:a copy or the old-style flags -vcodec copy -acodec copy. You would use the more verbose style when you want to copy only one of the streams, but re-encode the other. For example, many years ago there was a common practice with QuickTime files to compress the video with H.264 video but leave the audio as uncompressed PCM; if you ran across such a file today, you could modernize it with -c:v copy -c:a aac to reprocess just the audio stream, leaving the video untouched.



        The start point for every command above after the first is the previous command's start point plus the previous command's duration.






        share|improve this answer















        $ ffmpeg -i source-file.foo -ss 0 -t 600 first-10-min.m4v
        $ ffmpeg -i source-file.foo -ss 600 -t 600 second-10-min.m4v
        $ ffmpeg -i source-file.foo -ss 1200 -t 600 third-10-min.m4v
        ...


        Wrapping this up into a script to do it in a loop wouldn't be hard.



        Beware that if you try to calculate the number of iterations based on the duration output from an ffprobe call that this is estimated from the average bit rate at the start of the clip and the clip's file size unless you give the -count_frames argument, which slows its operation considerably.



        Another thing to be aware of is that the position of the -ss option on the command line matters. Where I have it now is slow but accurate. The first version of this answer gave the fast but inaccurate alternative. The linked article also describes a mostly-fast-but-still-accurate alternative, which you pay for with a bit of complexity.



        All that aside, I don't think you really want to be cutting at exactly 10 minutes for each clip. That will put cuts right in the middle of sentences, even words. I think you should be using a video editor or player to find natural cut points just shy of 10 minutes apart.



        Assuming your file is in a format that YouTube can accept directly, you don't have to reencode to get segments. Just pass the natural cut point offsets to ffmpeg, telling it to pass the encoded A/V through untouched by using the "copy" codec:



        $ ffmpeg -i source.m4v -ss 0 -t 593.3 -c copy part1.m4v
        $ ffmpeg -i source.m4v -ss 593.3 -t 551.64 -c copy part2.m4v
        $ ffmpeg -i source.m4v -ss 1144.94 -t 581.25 -c copy part3.m4v
        ...


        The -c copy argument tells it to copy all input streams (audio, video, and potentially others, such as subtitles) into the output as-is. For simple A/V programs, it is equivalent to the more verbose flags -c:v copy -c:a copy or the old-style flags -vcodec copy -acodec copy. You would use the more verbose style when you want to copy only one of the streams, but re-encode the other. For example, many years ago there was a common practice with QuickTime files to compress the video with H.264 video but leave the audio as uncompressed PCM; if you ran across such a file today, you could modernize it with -c:v copy -c:a aac to reprocess just the audio stream, leaving the video untouched.



        The start point for every command above after the first is the previous command's start point plus the previous command's duration.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Sep 23 '16 at 15:24

























        answered Sep 6 '10 at 17:49









        Warren YoungWarren Young

        54.9k10143147




        54.9k10143147








        • 1





          "cutting at exactly 10 minutes for each clip" is a good point.

          – Chris
          Sep 7 '10 at 11:42











        • maybe by using the -show_packets param you can make it more accurate.

          – rogerdpack
          Jun 13 '11 at 21:36











        • How can I find these "natural cut point offsets"?

          – JBernardo
          Sep 14 '12 at 19:58











        • I said it in the answer: "using a video editor or player." Load the video file up in one, scrub to near the 10 minute mark, then look for a reasonable place to cut. Record the time showing on the timecode display. Move forward another 10-minutes-minus-a-skosh. Repeat until done.

          – Warren Young
          Sep 14 '12 at 21:47













        • how to put above in a loop?

          – kRazzy R
          Dec 6 '17 at 19:32














        • 1





          "cutting at exactly 10 minutes for each clip" is a good point.

          – Chris
          Sep 7 '10 at 11:42











        • maybe by using the -show_packets param you can make it more accurate.

          – rogerdpack
          Jun 13 '11 at 21:36











        • How can I find these "natural cut point offsets"?

          – JBernardo
          Sep 14 '12 at 19:58











        • I said it in the answer: "using a video editor or player." Load the video file up in one, scrub to near the 10 minute mark, then look for a reasonable place to cut. Record the time showing on the timecode display. Move forward another 10-minutes-minus-a-skosh. Repeat until done.

          – Warren Young
          Sep 14 '12 at 21:47













        • how to put above in a loop?

          – kRazzy R
          Dec 6 '17 at 19:32








        1




        1





        "cutting at exactly 10 minutes for each clip" is a good point.

        – Chris
        Sep 7 '10 at 11:42





        "cutting at exactly 10 minutes for each clip" is a good point.

        – Chris
        Sep 7 '10 at 11:42













        maybe by using the -show_packets param you can make it more accurate.

        – rogerdpack
        Jun 13 '11 at 21:36





        maybe by using the -show_packets param you can make it more accurate.

        – rogerdpack
        Jun 13 '11 at 21:36













        How can I find these "natural cut point offsets"?

        – JBernardo
        Sep 14 '12 at 19:58





        How can I find these "natural cut point offsets"?

        – JBernardo
        Sep 14 '12 at 19:58













        I said it in the answer: "using a video editor or player." Load the video file up in one, scrub to near the 10 minute mark, then look for a reasonable place to cut. Record the time showing on the timecode display. Move forward another 10-minutes-minus-a-skosh. Repeat until done.

        – Warren Young
        Sep 14 '12 at 21:47







        I said it in the answer: "using a video editor or player." Load the video file up in one, scrub to near the 10 minute mark, then look for a reasonable place to cut. Record the time showing on the timecode display. Move forward another 10-minutes-minus-a-skosh. Repeat until done.

        – Warren Young
        Sep 14 '12 at 21:47















        how to put above in a loop?

        – kRazzy R
        Dec 6 '17 at 19:32





        how to put above in a loop?

        – kRazzy R
        Dec 6 '17 at 19:32













        39














        Here is the one line solution:



        ffmpeg -i input.mp4 -c copy -map 0 -segment_time 00:20:00 -f segment output%03d.mp4


        Please note that this does not give you accurate splits, but should fit your needs. It will instead cut at the first frame after the time specified after segment_time, in the code above it would be after the 20 minute mark.



        If you find that only the first chunk is playable, try adding -reset_timestamps 1 as mentioned in the comments.



        ffmpeg -i input.mp4 -c copy -map 0 -segment_time 00:20:00 -f segment -reset_timestamps 1 output%03d.mp4





        share|improve this answer





















        • 2





          It actually gives you very accurate splits, if you value video quality. Rather than splitting based on a particular time, it splits on the nearest keyframe following the requested time, so each new segment always starts with a keyframe.

          – Malvineous
          Feb 25 '17 at 6:51






        • 3





          what are the units? 8s? 8min? 8h?

          – user1133275
          Mar 20 '17 at 20:58






        • 1





          @user1133275 its second

          – Jon
          Mar 20 '17 at 21:11






        • 2





          On Mac, I found that this resulted in N output video chunks but only the 1st of them was a valid, viewable MP4. The other N-1 chunks were blank video (all black) with no audio. To make it work, I needed to add the reset_timestamps flag like so: ffmpeg -i input.mp4 -c copy -map 0 -segment_time 8 -f segment -reset_timestamps 1 output%03d.mp4.

          – jarmod
          Jun 5 '17 at 15:32






        • 2





          found that adding -reset_timestamps 1 fixes the issue for me

          – jlarsch
          Oct 30 '17 at 8:27
















        39














        Here is the one line solution:



        ffmpeg -i input.mp4 -c copy -map 0 -segment_time 00:20:00 -f segment output%03d.mp4


        Please note that this does not give you accurate splits, but should fit your needs. It will instead cut at the first frame after the time specified after segment_time, in the code above it would be after the 20 minute mark.



        If you find that only the first chunk is playable, try adding -reset_timestamps 1 as mentioned in the comments.



        ffmpeg -i input.mp4 -c copy -map 0 -segment_time 00:20:00 -f segment -reset_timestamps 1 output%03d.mp4





        share|improve this answer





















        • 2





          It actually gives you very accurate splits, if you value video quality. Rather than splitting based on a particular time, it splits on the nearest keyframe following the requested time, so each new segment always starts with a keyframe.

          – Malvineous
          Feb 25 '17 at 6:51






        • 3





          what are the units? 8s? 8min? 8h?

          – user1133275
          Mar 20 '17 at 20:58






        • 1





          @user1133275 its second

          – Jon
          Mar 20 '17 at 21:11






        • 2





          On Mac, I found that this resulted in N output video chunks but only the 1st of them was a valid, viewable MP4. The other N-1 chunks were blank video (all black) with no audio. To make it work, I needed to add the reset_timestamps flag like so: ffmpeg -i input.mp4 -c copy -map 0 -segment_time 8 -f segment -reset_timestamps 1 output%03d.mp4.

          – jarmod
          Jun 5 '17 at 15:32






        • 2





          found that adding -reset_timestamps 1 fixes the issue for me

          – jlarsch
          Oct 30 '17 at 8:27














        39












        39








        39







        Here is the one line solution:



        ffmpeg -i input.mp4 -c copy -map 0 -segment_time 00:20:00 -f segment output%03d.mp4


        Please note that this does not give you accurate splits, but should fit your needs. It will instead cut at the first frame after the time specified after segment_time, in the code above it would be after the 20 minute mark.



        If you find that only the first chunk is playable, try adding -reset_timestamps 1 as mentioned in the comments.



        ffmpeg -i input.mp4 -c copy -map 0 -segment_time 00:20:00 -f segment -reset_timestamps 1 output%03d.mp4





        share|improve this answer















        Here is the one line solution:



        ffmpeg -i input.mp4 -c copy -map 0 -segment_time 00:20:00 -f segment output%03d.mp4


        Please note that this does not give you accurate splits, but should fit your needs. It will instead cut at the first frame after the time specified after segment_time, in the code above it would be after the 20 minute mark.



        If you find that only the first chunk is playable, try adding -reset_timestamps 1 as mentioned in the comments.



        ffmpeg -i input.mp4 -c copy -map 0 -segment_time 00:20:00 -f segment -reset_timestamps 1 output%03d.mp4






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 7 hours ago









        joelfischerr

        1032




        1032










        answered Jun 27 '15 at 1:39









        JonJon

        53248




        53248








        • 2





          It actually gives you very accurate splits, if you value video quality. Rather than splitting based on a particular time, it splits on the nearest keyframe following the requested time, so each new segment always starts with a keyframe.

          – Malvineous
          Feb 25 '17 at 6:51






        • 3





          what are the units? 8s? 8min? 8h?

          – user1133275
          Mar 20 '17 at 20:58






        • 1





          @user1133275 its second

          – Jon
          Mar 20 '17 at 21:11






        • 2





          On Mac, I found that this resulted in N output video chunks but only the 1st of them was a valid, viewable MP4. The other N-1 chunks were blank video (all black) with no audio. To make it work, I needed to add the reset_timestamps flag like so: ffmpeg -i input.mp4 -c copy -map 0 -segment_time 8 -f segment -reset_timestamps 1 output%03d.mp4.

          – jarmod
          Jun 5 '17 at 15:32






        • 2





          found that adding -reset_timestamps 1 fixes the issue for me

          – jlarsch
          Oct 30 '17 at 8:27














        • 2





          It actually gives you very accurate splits, if you value video quality. Rather than splitting based on a particular time, it splits on the nearest keyframe following the requested time, so each new segment always starts with a keyframe.

          – Malvineous
          Feb 25 '17 at 6:51






        • 3





          what are the units? 8s? 8min? 8h?

          – user1133275
          Mar 20 '17 at 20:58






        • 1





          @user1133275 its second

          – Jon
          Mar 20 '17 at 21:11






        • 2





          On Mac, I found that this resulted in N output video chunks but only the 1st of them was a valid, viewable MP4. The other N-1 chunks were blank video (all black) with no audio. To make it work, I needed to add the reset_timestamps flag like so: ffmpeg -i input.mp4 -c copy -map 0 -segment_time 8 -f segment -reset_timestamps 1 output%03d.mp4.

          – jarmod
          Jun 5 '17 at 15:32






        • 2





          found that adding -reset_timestamps 1 fixes the issue for me

          – jlarsch
          Oct 30 '17 at 8:27








        2




        2





        It actually gives you very accurate splits, if you value video quality. Rather than splitting based on a particular time, it splits on the nearest keyframe following the requested time, so each new segment always starts with a keyframe.

        – Malvineous
        Feb 25 '17 at 6:51





        It actually gives you very accurate splits, if you value video quality. Rather than splitting based on a particular time, it splits on the nearest keyframe following the requested time, so each new segment always starts with a keyframe.

        – Malvineous
        Feb 25 '17 at 6:51




        3




        3





        what are the units? 8s? 8min? 8h?

        – user1133275
        Mar 20 '17 at 20:58





        what are the units? 8s? 8min? 8h?

        – user1133275
        Mar 20 '17 at 20:58




        1




        1





        @user1133275 its second

        – Jon
        Mar 20 '17 at 21:11





        @user1133275 its second

        – Jon
        Mar 20 '17 at 21:11




        2




        2





        On Mac, I found that this resulted in N output video chunks but only the 1st of them was a valid, viewable MP4. The other N-1 chunks were blank video (all black) with no audio. To make it work, I needed to add the reset_timestamps flag like so: ffmpeg -i input.mp4 -c copy -map 0 -segment_time 8 -f segment -reset_timestamps 1 output%03d.mp4.

        – jarmod
        Jun 5 '17 at 15:32





        On Mac, I found that this resulted in N output video chunks but only the 1st of them was a valid, viewable MP4. The other N-1 chunks were blank video (all black) with no audio. To make it work, I needed to add the reset_timestamps flag like so: ffmpeg -i input.mp4 -c copy -map 0 -segment_time 8 -f segment -reset_timestamps 1 output%03d.mp4.

        – jarmod
        Jun 5 '17 at 15:32




        2




        2





        found that adding -reset_timestamps 1 fixes the issue for me

        – jlarsch
        Oct 30 '17 at 8:27





        found that adding -reset_timestamps 1 fixes the issue for me

        – jlarsch
        Oct 30 '17 at 8:27











        6














        Faced the same problem earlier and put together a simple Python script to do just that (using FFMpeg). Available here: https://github.com/c0decracker/video-splitter, and pasted below:



        #!/usr/bin/env python
        import subprocess
        import re
        import math
        from optparse import OptionParser
        length_regexp = 'Duration: (d{2}):(d{2}):(d{2}).d+,'
        re_length = re.compile(length_regexp)
        def main():
        (filename, split_length) = parse_options()
        if split_length <= 0:
        print "Split length can't be 0"
        raise SystemExit
        output = subprocess.Popen("ffmpeg -i '"+filename+"' 2>&1 | grep 'Duration'",
        shell = True,
        stdout = subprocess.PIPE
        ).stdout.read()
        print output
        matches = re_length.search(output)
        if matches:
        video_length = int(matches.group(1)) * 3600 +
        int(matches.group(2)) * 60 +
        int(matches.group(3))
        print "Video length in seconds: "+str(video_length)
        else:
        print "Can't determine video length."
        raise SystemExit
        split_count = int(math.ceil(video_length/float(split_length)))
        if(split_count == 1):
        print "Video length is less then the target split length."
        raise SystemExit
        split_cmd = "ffmpeg -i '"+filename+"' -vcodec copy "
        for n in range(0, split_count):
        split_str = ""
        if n == 0:
        split_start = 0
        else:
        split_start = split_length * n
        split_str += " -ss "+str(split_start)+" -t "+str(split_length) +
        " '"+filename[:-4] + "-" + str(n) + "." + filename[-3:] +
        "'"
        print "About to run: "+split_cmd+split_str
        output = subprocess.Popen(split_cmd+split_str, shell = True, stdout =
        subprocess.PIPE).stdout.read()
        def parse_options():
        parser = OptionParser()
        parser.add_option("-f", "--file",
        dest = "filename",
        help = "file to split, for example sample.avi",
        type = "string",
        action = "store"
        )
        parser.add_option("-s", "--split-size",
        dest = "split_size",
        help = "split or chunk size in seconds, for example 10",
        type = "int",
        action = "store"
        )
        (options, args) = parser.parse_args()
        if options.filename and options.split_size:
        return (options.filename, options.split_size)
        else:
        parser.print_help()
        raise SystemExit
        if __name__ == '__main__':
        try:
        main()
        except Exception, e:
        print "Exception occured running main():"
        print str(e)





        share|improve this answer





















        • 1





          Next time do this please in a comment. Link-only answers aren't really liked here, and the same if you advert your site. If it is an opensource project with source code, maybe it is an exception, but I now risked my reviewing privileges by not voting for the removal of your answer. And yes, you can't post comments, but after you collected 5 upvotes (which seems very fast in your case) you will.

          – peterh
          Nov 21 '14 at 0:40













        • Hi and welcome to the site. Please don't post link only answers. While your script itself would probably make a great answer, a link to it is not an answer. It is a signpost pointing to an answer. More on that here. Since you kindly gave the link, I went ahead and included the script in the body of your answer. If you object to that, please delete the answer altogether.

          – terdon
          Nov 21 '14 at 1:54
















        6














        Faced the same problem earlier and put together a simple Python script to do just that (using FFMpeg). Available here: https://github.com/c0decracker/video-splitter, and pasted below:



        #!/usr/bin/env python
        import subprocess
        import re
        import math
        from optparse import OptionParser
        length_regexp = 'Duration: (d{2}):(d{2}):(d{2}).d+,'
        re_length = re.compile(length_regexp)
        def main():
        (filename, split_length) = parse_options()
        if split_length <= 0:
        print "Split length can't be 0"
        raise SystemExit
        output = subprocess.Popen("ffmpeg -i '"+filename+"' 2>&1 | grep 'Duration'",
        shell = True,
        stdout = subprocess.PIPE
        ).stdout.read()
        print output
        matches = re_length.search(output)
        if matches:
        video_length = int(matches.group(1)) * 3600 +
        int(matches.group(2)) * 60 +
        int(matches.group(3))
        print "Video length in seconds: "+str(video_length)
        else:
        print "Can't determine video length."
        raise SystemExit
        split_count = int(math.ceil(video_length/float(split_length)))
        if(split_count == 1):
        print "Video length is less then the target split length."
        raise SystemExit
        split_cmd = "ffmpeg -i '"+filename+"' -vcodec copy "
        for n in range(0, split_count):
        split_str = ""
        if n == 0:
        split_start = 0
        else:
        split_start = split_length * n
        split_str += " -ss "+str(split_start)+" -t "+str(split_length) +
        " '"+filename[:-4] + "-" + str(n) + "." + filename[-3:] +
        "'"
        print "About to run: "+split_cmd+split_str
        output = subprocess.Popen(split_cmd+split_str, shell = True, stdout =
        subprocess.PIPE).stdout.read()
        def parse_options():
        parser = OptionParser()
        parser.add_option("-f", "--file",
        dest = "filename",
        help = "file to split, for example sample.avi",
        type = "string",
        action = "store"
        )
        parser.add_option("-s", "--split-size",
        dest = "split_size",
        help = "split or chunk size in seconds, for example 10",
        type = "int",
        action = "store"
        )
        (options, args) = parser.parse_args()
        if options.filename and options.split_size:
        return (options.filename, options.split_size)
        else:
        parser.print_help()
        raise SystemExit
        if __name__ == '__main__':
        try:
        main()
        except Exception, e:
        print "Exception occured running main():"
        print str(e)





        share|improve this answer





















        • 1





          Next time do this please in a comment. Link-only answers aren't really liked here, and the same if you advert your site. If it is an opensource project with source code, maybe it is an exception, but I now risked my reviewing privileges by not voting for the removal of your answer. And yes, you can't post comments, but after you collected 5 upvotes (which seems very fast in your case) you will.

          – peterh
          Nov 21 '14 at 0:40













        • Hi and welcome to the site. Please don't post link only answers. While your script itself would probably make a great answer, a link to it is not an answer. It is a signpost pointing to an answer. More on that here. Since you kindly gave the link, I went ahead and included the script in the body of your answer. If you object to that, please delete the answer altogether.

          – terdon
          Nov 21 '14 at 1:54














        6












        6








        6







        Faced the same problem earlier and put together a simple Python script to do just that (using FFMpeg). Available here: https://github.com/c0decracker/video-splitter, and pasted below:



        #!/usr/bin/env python
        import subprocess
        import re
        import math
        from optparse import OptionParser
        length_regexp = 'Duration: (d{2}):(d{2}):(d{2}).d+,'
        re_length = re.compile(length_regexp)
        def main():
        (filename, split_length) = parse_options()
        if split_length <= 0:
        print "Split length can't be 0"
        raise SystemExit
        output = subprocess.Popen("ffmpeg -i '"+filename+"' 2>&1 | grep 'Duration'",
        shell = True,
        stdout = subprocess.PIPE
        ).stdout.read()
        print output
        matches = re_length.search(output)
        if matches:
        video_length = int(matches.group(1)) * 3600 +
        int(matches.group(2)) * 60 +
        int(matches.group(3))
        print "Video length in seconds: "+str(video_length)
        else:
        print "Can't determine video length."
        raise SystemExit
        split_count = int(math.ceil(video_length/float(split_length)))
        if(split_count == 1):
        print "Video length is less then the target split length."
        raise SystemExit
        split_cmd = "ffmpeg -i '"+filename+"' -vcodec copy "
        for n in range(0, split_count):
        split_str = ""
        if n == 0:
        split_start = 0
        else:
        split_start = split_length * n
        split_str += " -ss "+str(split_start)+" -t "+str(split_length) +
        " '"+filename[:-4] + "-" + str(n) + "." + filename[-3:] +
        "'"
        print "About to run: "+split_cmd+split_str
        output = subprocess.Popen(split_cmd+split_str, shell = True, stdout =
        subprocess.PIPE).stdout.read()
        def parse_options():
        parser = OptionParser()
        parser.add_option("-f", "--file",
        dest = "filename",
        help = "file to split, for example sample.avi",
        type = "string",
        action = "store"
        )
        parser.add_option("-s", "--split-size",
        dest = "split_size",
        help = "split or chunk size in seconds, for example 10",
        type = "int",
        action = "store"
        )
        (options, args) = parser.parse_args()
        if options.filename and options.split_size:
        return (options.filename, options.split_size)
        else:
        parser.print_help()
        raise SystemExit
        if __name__ == '__main__':
        try:
        main()
        except Exception, e:
        print "Exception occured running main():"
        print str(e)





        share|improve this answer















        Faced the same problem earlier and put together a simple Python script to do just that (using FFMpeg). Available here: https://github.com/c0decracker/video-splitter, and pasted below:



        #!/usr/bin/env python
        import subprocess
        import re
        import math
        from optparse import OptionParser
        length_regexp = 'Duration: (d{2}):(d{2}):(d{2}).d+,'
        re_length = re.compile(length_regexp)
        def main():
        (filename, split_length) = parse_options()
        if split_length <= 0:
        print "Split length can't be 0"
        raise SystemExit
        output = subprocess.Popen("ffmpeg -i '"+filename+"' 2>&1 | grep 'Duration'",
        shell = True,
        stdout = subprocess.PIPE
        ).stdout.read()
        print output
        matches = re_length.search(output)
        if matches:
        video_length = int(matches.group(1)) * 3600 +
        int(matches.group(2)) * 60 +
        int(matches.group(3))
        print "Video length in seconds: "+str(video_length)
        else:
        print "Can't determine video length."
        raise SystemExit
        split_count = int(math.ceil(video_length/float(split_length)))
        if(split_count == 1):
        print "Video length is less then the target split length."
        raise SystemExit
        split_cmd = "ffmpeg -i '"+filename+"' -vcodec copy "
        for n in range(0, split_count):
        split_str = ""
        if n == 0:
        split_start = 0
        else:
        split_start = split_length * n
        split_str += " -ss "+str(split_start)+" -t "+str(split_length) +
        " '"+filename[:-4] + "-" + str(n) + "." + filename[-3:] +
        "'"
        print "About to run: "+split_cmd+split_str
        output = subprocess.Popen(split_cmd+split_str, shell = True, stdout =
        subprocess.PIPE).stdout.read()
        def parse_options():
        parser = OptionParser()
        parser.add_option("-f", "--file",
        dest = "filename",
        help = "file to split, for example sample.avi",
        type = "string",
        action = "store"
        )
        parser.add_option("-s", "--split-size",
        dest = "split_size",
        help = "split or chunk size in seconds, for example 10",
        type = "int",
        action = "store"
        )
        (options, args) = parser.parse_args()
        if options.filename and options.split_size:
        return (options.filename, options.split_size)
        else:
        parser.print_help()
        raise SystemExit
        if __name__ == '__main__':
        try:
        main()
        except Exception, e:
        print "Exception occured running main():"
        print str(e)






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Feb 8 '16 at 16:00









        Community

        1




        1










        answered Nov 20 '14 at 23:28









        c0decrackerc0decracker

        6711




        6711








        • 1





          Next time do this please in a comment. Link-only answers aren't really liked here, and the same if you advert your site. If it is an opensource project with source code, maybe it is an exception, but I now risked my reviewing privileges by not voting for the removal of your answer. And yes, you can't post comments, but after you collected 5 upvotes (which seems very fast in your case) you will.

          – peterh
          Nov 21 '14 at 0:40













        • Hi and welcome to the site. Please don't post link only answers. While your script itself would probably make a great answer, a link to it is not an answer. It is a signpost pointing to an answer. More on that here. Since you kindly gave the link, I went ahead and included the script in the body of your answer. If you object to that, please delete the answer altogether.

          – terdon
          Nov 21 '14 at 1:54














        • 1





          Next time do this please in a comment. Link-only answers aren't really liked here, and the same if you advert your site. If it is an opensource project with source code, maybe it is an exception, but I now risked my reviewing privileges by not voting for the removal of your answer. And yes, you can't post comments, but after you collected 5 upvotes (which seems very fast in your case) you will.

          – peterh
          Nov 21 '14 at 0:40













        • Hi and welcome to the site. Please don't post link only answers. While your script itself would probably make a great answer, a link to it is not an answer. It is a signpost pointing to an answer. More on that here. Since you kindly gave the link, I went ahead and included the script in the body of your answer. If you object to that, please delete the answer altogether.

          – terdon
          Nov 21 '14 at 1:54








        1




        1





        Next time do this please in a comment. Link-only answers aren't really liked here, and the same if you advert your site. If it is an opensource project with source code, maybe it is an exception, but I now risked my reviewing privileges by not voting for the removal of your answer. And yes, you can't post comments, but after you collected 5 upvotes (which seems very fast in your case) you will.

        – peterh
        Nov 21 '14 at 0:40







        Next time do this please in a comment. Link-only answers aren't really liked here, and the same if you advert your site. If it is an opensource project with source code, maybe it is an exception, but I now risked my reviewing privileges by not voting for the removal of your answer. And yes, you can't post comments, but after you collected 5 upvotes (which seems very fast in your case) you will.

        – peterh
        Nov 21 '14 at 0:40















        Hi and welcome to the site. Please don't post link only answers. While your script itself would probably make a great answer, a link to it is not an answer. It is a signpost pointing to an answer. More on that here. Since you kindly gave the link, I went ahead and included the script in the body of your answer. If you object to that, please delete the answer altogether.

        – terdon
        Nov 21 '14 at 1:54





        Hi and welcome to the site. Please don't post link only answers. While your script itself would probably make a great answer, a link to it is not an answer. It is a signpost pointing to an answer. More on that here. Since you kindly gave the link, I went ahead and included the script in the body of your answer. If you object to that, please delete the answer altogether.

        – terdon
        Nov 21 '14 at 1:54











        2














        Note the exact punctuation of the alternative format is -ss mm:ss.xxx. I struggled for hours trying to use the intuitive-but-wrong mm:ss:xx to no avail.



        $ man ffmpeg | grep -C1 position



        -ss position

        Seek to given time position in seconds. "hh:mm:ss[.xxx]" syntax is also supported.




        References here and here.






        share|improve this answer






























          2














          Note the exact punctuation of the alternative format is -ss mm:ss.xxx. I struggled for hours trying to use the intuitive-but-wrong mm:ss:xx to no avail.



          $ man ffmpeg | grep -C1 position



          -ss position

          Seek to given time position in seconds. "hh:mm:ss[.xxx]" syntax is also supported.




          References here and here.






          share|improve this answer




























            2












            2








            2







            Note the exact punctuation of the alternative format is -ss mm:ss.xxx. I struggled for hours trying to use the intuitive-but-wrong mm:ss:xx to no avail.



            $ man ffmpeg | grep -C1 position



            -ss position

            Seek to given time position in seconds. "hh:mm:ss[.xxx]" syntax is also supported.




            References here and here.






            share|improve this answer















            Note the exact punctuation of the alternative format is -ss mm:ss.xxx. I struggled for hours trying to use the intuitive-but-wrong mm:ss:xx to no avail.



            $ man ffmpeg | grep -C1 position



            -ss position

            Seek to given time position in seconds. "hh:mm:ss[.xxx]" syntax is also supported.




            References here and here.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Jun 11 '11 at 12:49









            Caleb

            50.6k9146191




            50.6k9146191










            answered Jun 11 '11 at 2:43









            Mark HudsonMark Hudson

            258310




            258310























                2














                If you want to create really same Chunks must force ffmpeg to create i-frame on the every chunks' first frame so you can use this command for create 0.5 second chunk.



                ffmpeg -hide_banner  -err_detect ignore_err -i input.mp4 -r 24 -codec:v libx264  -vsync 1  -codec:a aac  -ac 2  -ar 48k  -f segment   -preset fast  -segment_format mpegts  -segment_time 0.5 -force_key_frames  "expr: gte(t, n_forced * 0.5)" out%d.mkv





                share|improve this answer




























                  2














                  If you want to create really same Chunks must force ffmpeg to create i-frame on the every chunks' first frame so you can use this command for create 0.5 second chunk.



                  ffmpeg -hide_banner  -err_detect ignore_err -i input.mp4 -r 24 -codec:v libx264  -vsync 1  -codec:a aac  -ac 2  -ar 48k  -f segment   -preset fast  -segment_format mpegts  -segment_time 0.5 -force_key_frames  "expr: gte(t, n_forced * 0.5)" out%d.mkv





                  share|improve this answer


























                    2












                    2








                    2







                    If you want to create really same Chunks must force ffmpeg to create i-frame on the every chunks' first frame so you can use this command for create 0.5 second chunk.



                    ffmpeg -hide_banner  -err_detect ignore_err -i input.mp4 -r 24 -codec:v libx264  -vsync 1  -codec:a aac  -ac 2  -ar 48k  -f segment   -preset fast  -segment_format mpegts  -segment_time 0.5 -force_key_frames  "expr: gte(t, n_forced * 0.5)" out%d.mkv





                    share|improve this answer













                    If you want to create really same Chunks must force ffmpeg to create i-frame on the every chunks' first frame so you can use this command for create 0.5 second chunk.



                    ffmpeg -hide_banner  -err_detect ignore_err -i input.mp4 -r 24 -codec:v libx264  -vsync 1  -codec:a aac  -ac 2  -ar 48k  -f segment   -preset fast  -segment_format mpegts  -segment_time 0.5 -force_key_frames  "expr: gte(t, n_forced * 0.5)" out%d.mkv






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Aug 23 '18 at 7:27









                    alireza akbaribayatalireza akbaribayat

                    211




                    211























                        -2














                        You shouldn't really be following any of the answers in this thread, instead just use what is built into ffmpeg to do exactly this.



                        ffmpeg -i invid.mp4 -threads 3 -vcodec copy -f segment -segment_time 2 cam_out_h264%04d.mp4


                        This will split it into roughly 2 second chucks, split at the relevant keyframes, and will output to the files
                        cam_out_h2640001.mp4, cam_out_h2640002.mp4, etc.






                        share|improve this answer






























                          -2














                          You shouldn't really be following any of the answers in this thread, instead just use what is built into ffmpeg to do exactly this.



                          ffmpeg -i invid.mp4 -threads 3 -vcodec copy -f segment -segment_time 2 cam_out_h264%04d.mp4


                          This will split it into roughly 2 second chucks, split at the relevant keyframes, and will output to the files
                          cam_out_h2640001.mp4, cam_out_h2640002.mp4, etc.






                          share|improve this answer




























                            -2












                            -2








                            -2







                            You shouldn't really be following any of the answers in this thread, instead just use what is built into ffmpeg to do exactly this.



                            ffmpeg -i invid.mp4 -threads 3 -vcodec copy -f segment -segment_time 2 cam_out_h264%04d.mp4


                            This will split it into roughly 2 second chucks, split at the relevant keyframes, and will output to the files
                            cam_out_h2640001.mp4, cam_out_h2640002.mp4, etc.






                            share|improve this answer















                            You shouldn't really be following any of the answers in this thread, instead just use what is built into ffmpeg to do exactly this.



                            ffmpeg -i invid.mp4 -threads 3 -vcodec copy -f segment -segment_time 2 cam_out_h264%04d.mp4


                            This will split it into roughly 2 second chucks, split at the relevant keyframes, and will output to the files
                            cam_out_h2640001.mp4, cam_out_h2640002.mp4, etc.







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Dec 15 '16 at 15:00









                            Jeff Schaller

                            39.5k1054126




                            39.5k1054126










                            answered Mar 22 '16 at 5:48









                            John AllardJohn Allard

                            553518




                            553518






























                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Unix & Linux Stack Exchange!


                                • 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%2funix.stackexchange.com%2fquestions%2f1670%2fhow-can-i-use-ffmpeg-to-split-mpeg-video-into-10-minute-chunks%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

                                Histoire des bourses de valeurs

                                Why is there Russian traffic in my log files?

                                Rename multiple files to decrement number in file name?