I don't think I can use this script... I should have mentioned that I am working on a windows environment... But I did mention that my goal was to split a video in equally sized chunks (in bytes, not in seconds).
But thanks anyway :) This will surely be helpful for someone else :) On 8 June 2016 at 16:40, blubee blubeeme <[email protected]> wrote: > Here is the script > In this script chunk_size and default_chunk_size = 600 seconds so my chunks > were 10 minutes, change the chunk size to whatever you like. > > ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- > #!/bin/bash > DIR="path/to/your/videos/*" #notice the trailing /* > OUT_DIR="path/where/output/files/go" > OUTPUT_FILE="" > > file_duration_float=0 > file_duration_int=0 > working_file_duration=0 > default_chunk_size=600 #video length in seconds (10 minutes) > chunk_size=600 #video length in seconds (10 minutes) > chunk_start_time=0 > chunk_end_time=0 > iteration=0 > > #extract simple metadata from files > for f in $DIR > do > echo $f > file_duration_float=$(ffprobe -i "$f" -show_format -v quiet | sed -n > 's/duration=//p') > file_duration_int=$( echo "($file_duration_float+0.5)/1" | bc ) > working_file_duration_int=$file_duration_int > echo $file_duration_int > > #--------------------------------------------- > # determine the start and end time of each clip > #--------------------------------------------- > while [ $working_file_duration_int -gt -1 ] > do > filename=$(basename "$f") > input_file="$filename" > filename=${filename::-4}" " > file_extension=${f: -3} > input_file_dir=$(dirname "$f")"/" > > > if [ $iteration -eq 0 ] > then > if [ $file_duration_int -le $chunk_size ] > then > working_file_duration_int=$((file_duration_int)) > chunk_start_time=0 > chunk_end_time=$(($working_file_duration_int)) > echo "file is shorter than 10 minutes: > $working_file_duration_int breaking early! iteration $iteration start: > $chunk_start_time end: $working_file_duration_int duration: > $working_file_duration_int video length left $working_file_duration_int" > > OUTPUT_FILE="$OUT_DIR$filename$iteration.mkv" > $(ffmpeg -hide_banner -loglevel panic -i "$f" -ss $chunk_start_time -t > $chunk_end_time [your options here ] "$OUTPUT_FILE") > break > fi > > working_file_duration_int=$((file_duration_int - chunk_size)) > chunk_start_time=0 > chunk_end_time=$(($default_chunk_size)) > > echo "iteration $iteration start: $chunk_start_time end: $chunk_end_time > duration: $default_chunk_size video length left $working_file_duration_int" > > OUTPUT_FILE="$OUT_DIR$filename$iteration.mkv" > $(ffmpeg -hide_banner -loglevel panic -i "$f" -ss $chunk_start_time -t > $chunk_end_time [your options here ] "$OUTPUT_FILE") > iteration=$((iteration+1)) > fi > if [ $working_file_duration_int -le $chunk_size ] > then > chunk_size=$working_file_duration_int > working_file_duration_int=$((working_file_duration_int - chunk_size)) > chunk_start_time=$(($chunk_start_time+$chunk_end_time)) > chunk_end_time=$(($chunk_size)) > > echo "early chunk size: $chunk_size iteration $iteration start: > $chunk_start_time end: $((chunk_start_time+chunk_end_time)) duration: > $chunk_end_time video length left $working_file_duration_int " > > OUTPUT_FILE="$OUT_DIR$filename$iteration.mkv" > $(ffmpeg -hide_banner -loglevel panic -i "$f" -ss $chunk_start_time -t > $chunk_end_time [your options here ] "$OUTPUT_FILE") > iteration=0 > chunk_size=$default_chunk_size > break > else > chunk_start_time=$(($chunk_start_time+$chunk_end_time)) > chunk_end_time=$(($chunk_size)) > working_file_duration_int=$((working_file_duration_int - chunk_size)) > echo "iteration $iteration start: $chunk_start_time end: > $((chunk_start_time+chunk_end_time)) duration: $chunk_end_time video length > left $working_file_duration_int " > > OUTPUT_FILE="$OUT_DIR$filename$iteration.mkv" > $(ffmpeg -hide_banner -loglevel panic -i "$f" -ss $chunk_start_time -t > $chunk_end_time [your options here ] "$OUTPUT_FILE") > iteration=$((iteration+1)) > fi > done > echo "---------------- finished processing $f" > done > > ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- > > Let me know if you have any questions. > > On Wed, Jun 8, 2016 at 5:14 PM, Henk D. Schoneveld <[email protected]> > wrote: > > > > > On 08 Jun 2016, at 11:01, blubee blubeeme <[email protected]> wrote: > > > > > I wrote a script to do this exact same thing. I will post it to this > list > > > when I get back to my machine. > > It can be done by splitting an all i-frame/key-frame mpeg transport > stream > > file with the split command. An all i-frame/key-frame conversion isn’t > very > > efficient in conversion, but that is a side-effect. > > > > > > On Wed, Jun 8, 2016, 16:56 Henk D. Schoneveld <[email protected]> > > wrote: > > > > > >> > > >> On 08 Jun 2016, at 10:39, Celso Coutinho <[email protected]> wrote: > > >> > > >>> Dear all, > > >>> > > >>> I want to be able to split a file in chunks with the same (previously > > >>> defined) size (except the last chunk, of course). I have been trying > > >>> several commands but without much success. > > >> Out of curiosity, what is the reason for wanting same-sized chunks ? > > >> Same-time chunks is what mostly is used. > > >>> > > >>> When I look into the documentation, I understand the *-fs* flag > allows > > me > > >>> to define the maximum size of the chunk I am obtaining in each time I > > run > > >>> *ffmpeg,* but I don't know how to define the starting point of the > > >> chunk. I > > >>> tried *-ss*, but it seems that I can only use it with time, rather > than > > >>> file size. Can someone enlighten me on this matter? > > >>> > > >>> Moreover, I have been trying to use the following command: > > >>> > > >>> *ffmpeg **-i raper.3gp -fs 102400 -vcodec copy -acodec copy -movflags > > >>> faststart output1.avi* > > >>> > > >>> But the output video has no sound, plus the duration is always > > incorrect > > >>> (video has 4 to 5 seconds, and the duration shown in the video is > like > > >> one > > >>> minute). Which codecs should I choose? > > >>> > > >>> Thanks in advance! > > >>> > > >>> Celso > > >>> _______________________________________________ > > >>> ffmpeg-user mailing list > > >>> [email protected] > > >>> http://ffmpeg.org/mailman/listinfo/ffmpeg-user > > >>> > > >>> To unsubscribe, visit link above, or email > > >>> [email protected] with subject "unsubscribe". > > >> > > >> _______________________________________________ > > >> ffmpeg-user mailing list > > >> [email protected] > > >> http://ffmpeg.org/mailman/listinfo/ffmpeg-user > > >> > > >> To unsubscribe, visit link above, or email > > >> [email protected] with subject "unsubscribe". > > > _______________________________________________ > > > ffmpeg-user mailing list > > > [email protected] > > > http://ffmpeg.org/mailman/listinfo/ffmpeg-user > > > > > > To unsubscribe, visit link above, or email > > > [email protected] with subject "unsubscribe". > > > > _______________________________________________ > > ffmpeg-user mailing list > > [email protected] > > http://ffmpeg.org/mailman/listinfo/ffmpeg-user > > > > To unsubscribe, visit link above, or email > > [email protected] with subject "unsubscribe". > > > _______________________________________________ > ffmpeg-user mailing list > [email protected] > http://ffmpeg.org/mailman/listinfo/ffmpeg-user > > To unsubscribe, visit link above, or email > [email protected] with subject "unsubscribe". > _______________________________________________ ffmpeg-user mailing list [email protected] http://ffmpeg.org/mailman/listinfo/ffmpeg-user To unsubscribe, visit link above, or email [email protected] with subject "unsubscribe".
