VideoHelp Forum
+ Reply to Thread
Results 1 to 12 of 12
Thread
  1. Banned
    Join Date
    Apr 2017
    Location
    United States
    Search Comp PM
    I am very new to using ffmpeg and I am in desperate need of help. I have several videos that I am trying to split into one minute segments all at once, so that I can format them from mkv to mp4. I would like to split these videos using direct stream copy, but I am not very familiar with how to write out the correct code to do this and how I need to have my videos labeled. I do know that they all need to be in the same folder as ffmpeg. I would greatly appreciate any help, also can somebody please walk me through on how to make this a .bat file.
    Quote Quote  
  2. Member Budman1's Avatar
    Join Date
    Jul 2012
    Location
    NORTHWEST ILLINOIS, USA
    Search Comp PM
    This can, theoretically, be done but it has been a problem for many requesting this to get correct. Again. Basically, you have 3 types of frames or picture in a video. I, B, and P. I Frames are the only ones that are a complete picture or image. The others are the differences between the frame before, after, or both. FFMpeg likes to split at I-Frames and these are not typically at 1 minute intervals so you would be trying to cut at a B or a P frame image which is not a complete picture with nothing to reference to in preceding frames. Cutting with COPY is VERY difficult for this reason.

    It may or may not work depending on the format, codec involved, point at cut and a lot of other factors. What you will usually get is a non-playable segment, a segment that freeze frames for several seconds, a segment that is not the minute you want and other problems.

    If, as I understand your request, you have MKV videos and you wish to break into 1 minute MP4's, then letting it re-code the cut segments into an MP4 would make it easier to obtain what you wish. It is possible to repackage some MKV videos tp MP4 without re-coding but at 1 minute intervals may give undesirable results.

    If someone else here knows of a simple way to do this, I would also like to know this procedure. In the mean time you can try ffmpeg to extract , say, the second minute to see if it works:

    Code:
    FFMPEG -ss 00:01:00.000 -i <"video.mkv"> -t 01:00.000 -c copy <"Output_video.mp4">
    -ss 00:01:00.000 means seek to the 1 minute point. Using -ss before the -i option also resets the time of that frame to 000 so it becomes the first frame of your output.
    -i <video.mkv> means input the video you mean to cut. Do not use the < >. The simply mean replace with a video name of your choice such as "My Video.MKV"
    -t 01:00.000 means time to copy 1 minute.
    -c copy means copy both audio and video streams
    <"Output_video.mp4"> means replace with an output name of your choice such as "My Output Video.MKV"

    If it works change the -ss to 00:02:00.000 and try the next cut. Do not use the < >. If you have good luck (or not) let us know and someone can assist further or help with a batch file to accomplish wht you need..
    Quote Quote  
  3. Member Budman1's Avatar
    Join Date
    Jul 2012
    Location
    NORTHWEST ILLINOIS, USA
    Search Comp PM
    UPDATE:

    After testing a video cut from 2:30-3:30 and another cut at 3:30-4:30. I got 2 playable videos. However, they overlap by a frame or 2 since the frames do not start on an even time boundary since my test video is 29.970 FPS and each frame is 0.033367 seconds long. I have shown the results of the Open GOP video I used and the times of the frames that correspond on the output video to the first start time of 02:30.000 (150 seconds) and 03:30 (210 seconds). Notice the first video output is 1800 frames (0-1799). If you add 1799 to the frame number cut Point of the original video (Frame 4496) you get 6295 or the second frame of the second minute.

    If this is acceptable, it seems like it shouldn't be too hard to come up with a batch file that would do this for you by someone better at batch files than I am. What happens when you convert or repack them to an MP4 with no leading I-Frame, I do not know. I use Potplayer and these 2 videos play without an abnormalities that I can see. The durations are 1 minute 2 seconds and 1 minute 1 second.

    Image
    [Attachment 45565 - Click to enlarge]
    Quote Quote  
  4. Originally Posted by Budman1 View Post
    This can, theoretically, be done but it has been a problem for many requesting this to get correct. Again. Basically, you have 3 types of frames or picture in a video. I, B, and P. I Frames are the only ones that are a complete picture or image. The others are the differences between the frame before, after, or both. FFMpeg likes to split at I-Frames and these are not typically at 1 minute intervals so you would be trying to cut at a B or a P frame image which is not a complete picture with nothing to reference to in preceding frames. Cutting with COPY is VERY difficult for this reason.
    There is more frame types and sometimes cut is not possible even on I frame... sadly to say but life is more complicated.
    Quote Quote  
  5. Member Budman1's Avatar
    Join Date
    Jul 2012
    Location
    NORTHWEST ILLINOIS, USA
    Search Comp PM
    There is more frame types and sometimes cut is not possible even on I frame... sadly to say but life is more complicated.
    AFAIK... The other types of frames can be found by using AVISYNTH to check as the video is playing. I have not verified this because I don't seem to have any Videos with these Transition type of frames. I use:

    Code:
    FFmpegSource2("C:\Users\Bud\Desktop\FramesCuttingJoining\Beta Test\temp\CGOP.mp4", atrack=-1).Crop(0,0,-0,-2).LanczosResize(720,404)
    ScriptClip(Last, """Subtitle("[ "+Chr(FFPICT_TYPE)+" ]", size=(Height*56.0/720), align=2)""", after_frame=true)
    Subtitle("C:\Users\Bud\Desktop\FramesCuttingJoining\Beta Test\temp\CGOP.mp4", x=720, y=202, font="Arial", size=24, text_color=$ff0000, align=3)
    ShowFrameNumber(scroll=true, x=10, y=27, font="Arial", size=24, text_color=$ff0000)
    ShowTime(x=72, y=44, font="Arial", size=24, text_color=$ff0000)
    ShowSMPTE(fps=29.97, x=68, y=61, font="Arial", size=24, text_color=$ff0000)
    These are what is SUPPOSED to be shown:

    I: Intra
    P: Predicted
    B: Bi-dir predicted
    S: S(GMC)-VOP MPEG4
    i: Switching Intra
    p: Switching Predicted
    b: FF_BI_TYPE (no good explanation available)
    ?: Unknown
    Playing the AVS script gives something like below, but I have not verified this.

    Image
    [Attachment 45572 - Click to enlarge]
    Quote Quote  
  6. Mod Neophyte Super Moderator redwudz's Avatar
    Join Date
    Sep 2002
    Location
    USA
    Search Comp PM
    Wrong forum. Moving to Newbie/General Forum.

    Moderator redwudz
    Quote Quote  
  7. mkvmerge has a --split duration option , and mp4box has a -split time_sec option

    So in theory you can either batch remux to mp4 then batch split; or batch split, then batch remux to mp4

    But as mentioned above, splitting with direct stream copy is almost never accurate because of the way typical files are encoded. Splitting can only be done on IDR frames (or true keyframes). As a result you sometimes have overlapped/repeated segments. At the very best, the cuts won't be exactly 1 min
    Quote Quote  
  8. Banned
    Join Date
    Apr 2017
    Location
    United States
    Search Comp PM
    Thanks for the help poisondeathray. How do I use mkvmerge, because I am unfamiliar with that portion of mkvtoolnix?
    Quote Quote  
  9. Originally Posted by carlrandall72 View Post
    Thanks for the help poisondeathray. How do I use mkvmerge, because I am unfamiliar with that portion of mkvtoolnix?
    In mkvtoolnix, the output tab, look under splitting. You can use split mode : after output duration

    You can do this by command line too

    But there are batch mkvtoolnix helpers. e.g
    https://github.com/Serede/mkvtoolnix-batch

    You can create a json file , and there are step by step instructions included
    Quote Quote  
  10. You can also view the command line the mkvtoolnix gui uses -- a good way to learn the command line syntax. Multiplexer -> Show Command Line.
    Quote Quote  
  11. There also is a good documentation about mkvtoolnix command line options over at https://mkvtoolnix.download/doc/mkvmerge.html which might come handy.
    users currently on my ignore list: deadrats, Stears555
    Quote Quote  
  12. Hi, how can I find out the name of my device for the -init_hw_device parameter in FFmpeg?

    I want to activate Vulkan video filters. In the documentation (https://ffmpeg.org/ffmpeg-filters.html#Vulkan-Video-Filters ) it is written:
    Running Vulkan filters requires you to initialize a hardware device and to pass that device to all filters in any filter graph.

    -init_hw_device vulkan[=name][:device[,key=value...]]

    How do I find out the device name?

    I have a Gigabyte GTX 1070 8GB graphics card.
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!