VideoHelp Forum

Our website is made possible by displaying online advertisements to our visitors. Consider supporting us by disable your adblocker or Try ConvertXtoDVD and convert all your movies to DVD. Free trial ! :)
+ Reply to Thread
Results 1 to 5 of 5
Thread
  1. Hello
    I have used this code to extract h264 streams from mp4 file and split it but when i have joined splited parts but there was problems.
    Code:
    for %%a in ("*.mp4") do "C:\ffmpeg\bin\ffmpeg.exe" -i "%%a" -vcodec copy -bsf h264_mp4toannexb -an -f h264 -ss 00:00:00 -t 00:08:30 "%%~na-01.h264"
    for %%a in ("*.mp4") do "C:\ffmpeg\bin\ffmpeg.exe" -i "%%a" -vcodec copy -bsf h264_mp4toannexb -an -f h264 -ss 00:08:30 -t 00:10:30 "%%~na-02.h264"
    for %%a in ("*.mp4") do "C:\ffmpeg\bin\ffmpeg.exe" -i "%%a" -vcodec copy -bsf h264_mp4toannexb -an -f h264 -ss 00:10:30 -t 10800 "%%~na-03.h264"
    pause
    Original clip's duration is 1:20:18 but joined clip is 1:25:11!
    Last edited by ben45; 9th Oct 2016 at 15:40.
    Quote Quote  
  2. https://trac.ffmpeg.org/wiki/Seeking#Seekingwhiledoingacodeccopy

    You need cut on I frames...

    https://ffmpeg.org/ffmpeg-all.html#Main-options

    -ss position (input/output)

    When used as an input option (before -i), seeks in this input file to position. Note that in most formats it is not possible to seek exactly, so ffmpeg will seek to the closest seek point before position. When transcoding and -accurate_seek is enabled (the default), this extra segment between the seek point and position will be decoded and discarded. When doing stream copy or when -noaccurate_seek is used, it will be preserved.

    When used as an output option (before an output filename), decodes but discards input until the timestamps reach position.

    position must be a time duration specification, see (ffmpeg-utils)the Time duration section in the ffmpeg-utils(1) manual.
    Quote Quote  
  3. ffmpeg has the segment format that always cuts on GOP boundaries.
    Here's a little batch file that works for me. Offered as-is & without support.

    ffmpeg-split.bat
    Code:
    @echo off
    
    :: https://forum.videohelp.com/threads/380794?p=2462195#post2462195
    :: http://ffmpeg.org/ffmpeg-formats.html#segment_002c-stream_005fsegment_002c-ssegment
    
    :: CONFIG
    :: * select segment list type (default .m3u8 playlist) 
    :: * set -segment_time (default 10 sec)
    :: * set codecs etc
    :: * maybe set an output folder
    :: * uncomment one (and only one) OPTION below
    
    :: OPTION 1 - call with single file argument
    if not exist "%~dpnx1" goto :EOF
    cd "%~dp1" 
    call :M3U8_LIST "%~nx1" 
    
    :: OPTION 2 - process whole folder (caution)
    ::for %%f in (*.mp4) do call :M3U8_LIST "%%~nxf"
    
    goto :eof    
    
    
    :: generate 'name.ext' list in csv format: 
    ::     segment_filename,segment_start_time,segment_end_time
    :CSV_LIST
    @echo on
    ffmpeg -i "%~nx1" -codec copy ^
        -f segment -segment_time 10 -segment_start_number 1000 ^
        -segment_list_type "ext" -segment_list "%~n1.ext" ^
        "%~n1-seg%%d%~x1"
    @echo off
    if errorlevel 1 pause
    goto :eof
    
    
    :: generate 'name.concat' file in ffmpeg 'concat' format
    :CONCAT_LIST
    @echo on
    ffmpeg -i "%~nx1" -codec copy ^
        -f segment -segment_time 10 -segment_start_number 1000 ^
        -segment_list_type "ffconcat" -segment_list "%~n1.concat" ^
        "%~n1-seg%%d%~x1"
    @echo off
    if errorlevel 1 pause
    goto :eof
    
    
    :: generate 'name.m3u8' file, version 3, compliant with 
    ::    http://tools.ietf.org/id/draft-pantos-http-live-streaming
    :: and playable in MPC-HC
    :M3U8_LIST
    @echo on
    ffmpeg -i "%~nx1" -codec copy ^
        -f segment -segment_time 10 -segment_start_number 1000 ^
        -segment_list_type "m3u8" -segment_list "%~n1.m3u8" ^
        "%~n1-seg%%d%~x1"
    @echo off
    if errorlevel 1 pause
    goto :eof
    Quote Quote  
  4. Originally Posted by pandy View Post
    https://trac.ffmpeg.org/wiki/Seeking#Seekingwhiledoingacodeccopy

    You need cut on I frames...

    https://ffmpeg.org/ffmpeg-all.html#Main-options

    -ss position (input/output)

    When used as an input option (before -i), seeks in this input file to position. Note that in most formats it is not possible to seek exactly, so ffmpeg will seek to the closest seek point before position. When transcoding and -accurate_seek is enabled (the default), this extra segment between the seek point and position will be decoded and discarded. When doing stream copy or when -noaccurate_seek is used, it will be preserved.

    When used as an output option (before an output filename), decodes but discards input until the timestamps reach position.

    position must be a time duration specification, see (ffmpeg-utils)the Time duration section in the ffmpeg-utils(1) manual.
    Thanks for reply
    I'm not familiar with ffmpeg. coud you please correct my code?
    Code:
    for %%a in ("*.mp4") do "C:\ffmpeg\bin\ffmpeg.exe" -i "%%a" -vcodec copy -bsf h264_mp4toannexb -an -f h264 -ss 00:00:00 -t 00:08:30 "%%~na-01.h264"
    for %%a in ("*.mp4") do "C:\ffmpeg\bin\ffmpeg.exe" -i "%%a" -vcodec copy -bsf h264_mp4toannexb -an -f h264 -ss 00:08:30 -t 00:10:30 "%%~na-02.h264"
    for %%a in ("*.mp4") do "C:\ffmpeg\bin\ffmpeg.exe" -i "%%a" -vcodec copy -bsf h264_mp4toannexb -an -f h264 -ss 00:10:30 -t 10800 "%%~na-03.h264"
    pause
    Quote Quote  
  5. Originally Posted by ben45 View Post
    Thanks for reply
    I'm not familiar with ffmpeg. coud you please correct my code?
    Code:
    for %%a in ("*.mp4") do "C:\ffmpeg\bin\ffmpeg.exe" -i "%%a" -vcodec copy -bsf h264_mp4toannexb -an -f h264 -ss 00:00:00 -t 00:08:30 "%%~na-01.h264"
    for %%a in ("*.mp4") do "C:\ffmpeg\bin\ffmpeg.exe" -i "%%a" -vcodec copy -bsf h264_mp4toannexb -an -f h264 -ss 00:08:30 -t 00:10:30 "%%~na-02.h264"
    for %%a in ("*.mp4") do "C:\ffmpeg\bin\ffmpeg.exe" -i "%%a" -vcodec copy -bsf h264_mp4toannexb -an -f h264 -ss 00:10:30 -t 10800 "%%~na-03.h264"
    pause
    ffmpeg have limitations and this is not about improving script - try raffriff42 script and perhaps consider to modify your own with using https://ffmpeg.org/ffmpeg-all.html#segment_002c-stream_005fsegment_002c-ssegment .
    Quote Quote  



Similar Threads