VideoHelp Forum
+ Reply to Thread
Results 1 to 13 of 13
Thread
  1. I'm very noob, sorry. I searched a lot and didn't find any solution. Is it possible to automatically cut a 1 hour video into 1 minute? But not have 60 1minute videos, I wish the software to automatically identify the video size and cut several 2 or 3 second scenes to form a 1 minute summary of the video 1 hour video. It is possible? Can some software do this?
    Quote Quote  
  2. Member Budman1's Avatar
    Join Date
    Jul 2012
    Location
    NORTHWEST ILLINOIS, USA
    Search Comp PM
    If you want to cut every so many seconds and you want a total number of scenes (say 15}in your clip:
    1. Find total number of second (example 1200)
    2. Divide Total seconds by 15 (number of requested scenes)=80 (1200/15)
    3. Decide how many seconds you wish in each new scene (example 2)
    3. Use the following script and adjust 80,2 according to your choices"

    Code:
    ffmpeg -i yosemite.mp4 -vf select='lt(mod(t,80,2)',setpts=N/FRAME_RATE/TB -af aselect='lt(mod(t,120),2)',asetpts=N/SR/TB  out17.mp4
    This will provide a 30 second video (15X2=30) with 2 seconds in each segment.

    ----------------------
    If you wish to cut on scene changes it is trickier but adapting one of my bat files, copy the code into a file called 'somethning.bat'
    Drag and drop a video on the bat file and it will create text files with scene change amounts and cut points. I have adjusted the vframes to 50 (25FPSx2 seconds)
    Adjust according to your wishes.
    Also adjust the scene,.x to higher for less detecting and lower for more detection. .4 will give most scene changes but I raised to .6 for less output segments

    Code:
    setlocal enabledelayedexpansion
    @echo off
    set /a count=0
    ::for %%a in (*.mp4,*.mpg,*.flv) Do (
    for %%a in ("%~nx1") Do (
    cd %%~dpa
    echo. > "%%~na_SceneInfo.txt"
    echo Scene NO. PTS TIME     FRAME TYPE > "%%~dpna_SceneList.txt"
    ffprobe -v quiet -show_frames -of compact=p=0 -f lavfi "movie='%%a',select=gt(scene\,.6)" >> "%%~na_SceneInfo.txt"
    for /F "tokens=5,14,15,18,19 delims=|" %%b in ('findstr /I "type=" "%%~na_SceneInfo.txt"') do (
    set "x=%%b"
    set "y=%%c"
    set "z=%%d"
    set "w=%%e"
    set "v=%%f"
    set "u=%%g"
    set sort=!x:~13,-7!
    echo !sort!
    if !sort! GEQ 0 if !sort! LEQ 14000 (
    @echo !count!         !x:~13!         !w!  >> "%%~dpna_SceneList.txt"
    ffmpeg -ss !x:~13! -i "%%a" -vframes 50 "%%~dpna_Thumb_!count!.mp4"
    )
    set /a count+=1"
    set /a ekko=count%%10"
    if !ekko!==0 echo Frame !count! processed
    )
    )
    ::pause
    Image
    [Attachment 60320 - Click to enlarge]

    Image
    [Attachment 60321 - Click to enlarge]


    You will have 15 videos:
    Image
    [Attachment 60322 - Click to enlarge]


    Uou will need to join them for a composite video with whatever you choose to use. There is probably a way to do the scene detect and join all at once but I use a GUI that runs 2 scripts consecutively.
    Last edited by Budman1; 16th Aug 2021 at 03:49. Reason: scene change amout expanation
    Quote Quote  
  3. Thanks for the answer. but unfortunately it didn't work for me. I tried the first code with a video of exactly 1200 seconds and with the correct name, but it generates an output file with 0 bytes, the file contains no information

    Image
    [Attachment 60335 - Click to enlarge]
    Quote Quote  
  4. Member Budman1's Avatar
    Join Date
    Jul 2012
    Location
    NORTHWEST ILLINOIS, USA
    Search Comp PM
    Try taking the double colons out of the bat file at the end where it says pause. That keep the cmd window open and show any errors.

    Send any error msg you get. Ill double check the script to make sure i didnt make any errors when i copied it.
    Quote Quote  
  5. AviSynth's SelectRangeEvery() filter can be used for this:

    Code:
    a = LWLibavAudioSource("filename.mp4") 
    v = LWLibavVideoSource("filename.mp4", cache=false, prefer_hw=2) 
    AudioDub(v,a)
    
    desired_clip_length = 60.0 # total time of desired preview clip, in seconds
    desired_segment_length = 2.0 # time of each segment, in seconds
    
    length = int(desired_segment_length * framerate)
    interval = int(framecount / (desired_clip_length / desired_segment_length))
    SelectRangeEvery(interval, length)
    Encode with whatever encoder you want.

    Of course, it's not content aware, it just cuts at the calculated intervals. It's not great as a preview. I don't thing an automated method that cuts only shot changes is much better. What you really want is a real human analyzing the content and selecting the shots.

    A sample you'll recognize:
    Image Attached Files
    Last edited by jagabo; 16th Aug 2021 at 23:32.
    Quote Quote  
  6. Member Budman1's Avatar
    Join Date
    Jul 2012
    Location
    NORTHWEST ILLINOIS, USA
    Search Comp PM
    Jagabo just beat me with a very good way to produce your results, as he always does.

    I just remembered that sometimes on some systems you have to escape special characters like commas. So anyone that reads this thread and wishes to try it can try both ways
    I tried my script both ways and it work both ways BUT... depending on your level of FFMpeg, Operating system and Dos level, You may have to escape the commas like:

    ffmpeg -i yosemite.mp4 -vf select='lt(mod(t\,4)\,2)',setpts=N/FRAME_RATE/TB -af aselect='lt(mod(t\,120)\,2)',asetpts=N/SR/TB out18.mp4
    Quote Quote  
  7. Thank you guys, you help a lot, thank you deeply. Budman1 this code "ffmpeg -i yosemite.mp4 -vf select='lt(mod(t\,4)\,2)',setpts=N/FRAME_RATE/TB -af aselect='lt(mod(t\,120)\,2)',asetpts=N/SR/TB out18.mp4" is exactly what I wanted, as I said above I don't understand much and this code saved me, it will save me a lot of work.

    jagabo, thanks too, but I didn't try your code, it's too advanced for me, sorry
    Quote Quote  
  8. Member
    Join Date
    Apr 2023
    Location
    Europe
    Search PM
    Originally Posted by Budman1 View Post

    Code:
    ffmpeg -i yosemite.mp4 -vf select='lt(mod(t,80,2)',setpts=N/FRAME_RATE/TB -af aselect='lt(mod(t,120),2)',asetpts=N/SR/TB  out17.mp4
    This will provide a 30 second video (15X2=30) with 2 seconds in each segment.
    Hello, I'm trying to run this code but I get:

    Code:
    [AVFilterGraph @ 0x600000b70420] No such filter: '120)'
    Error reinitializing filters!
    Failed to inject frame into filter network: Filter not found
    Error while processing the decoded data for stream #0:1
    Conversion failed!
    I realise this thread is a couple of years old, has something changed with the new version of FFMPEG?
    Quote Quote  
  9. You're missing a ) after the mod(t,80.
    Quote Quote  
  10. Member Budman1's Avatar
    Join Date
    Jul 2012
    Location
    NORTHWEST ILLINOIS, USA
    Search Comp PM
    Thanks Jagabo. Major brain check on my part.
    Quote Quote  
  11. Member
    Join Date
    Apr 2023
    Location
    Europe
    Search PM
    Thanks for the reply, I'm still getting the same error. Here's what I'm putting into the terminal

    Code:
    ffmpeg -i Screen-2023-04-28-103737.mp4 -vf select='lt(mod(t,408),2)',setpts=N/FRAME_RATE/TB -af aselect='lt(mod(t,120),2)',asetpts=N/SR/TB  out17.mp4
    Quote Quote  
  12. Your command line worked for me in a Windows command prompt. In PowerShell I had to put \ before the commas as in Budman1's command line in post #6.
    Code:
    ffmpeg -i Screen-2023-04-28-103737.mp4 -vf select='lt(mod(t\,408)\,2)',setpts=N/FRAME_RATE/TB -af aselect='lt(mod(t\,120)\,2)',asetpts=N/SR/TB  out17.mp4
    Quote Quote  
  13. Member
    Join Date
    Apr 2023
    Location
    Europe
    Search PM
    Originally Posted by jagabo View Post
    Your command line worked for me in a Windows command prompt. In PowerShell I had to put \ before the commas as in Budman1's command line in post #6.
    Code:
    ffmpeg -i Screen-2023-04-28-103737.mp4 -vf select='lt(mod(t\,408)\,2)',setpts=N/FRAME_RATE/TB -af aselect='lt(mod(t\,120)\,2)',asetpts=N/SR/TB  out17.mp4
    It worked! Thanks very much
    Quote Quote  



Similar Threads

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