The following text file ("myTextFile.txt") is used to cut a video into chunks
00:00:00.0 video_name_1.mp4
00:10:00.1 video_name_2.mp4
00:20:00.1 video_name_3.mp4
First columns are time stamps of cutting points [HH:MM:SS.millis].
I use the following command to read the txt file and cut a video called "input_video.mp4" into clips of 10 seconds each
while read line ; do
start_time=$(echo $line | cut -d' ' -f1);
output_name=$(echo $line | cut -d' ' -f2);
ffmpeg -ss $start_time -t 00:00:10.0 -i input_video.mp4 ${output_name};
done < myTextFile.txt
but it's not working. The output filenames are corrupt and I don't know why. I'm not using any special characters in the output filenames. Why is this happening?
My current work around is printing the last line ("ffmpeg ...") into the console and then paste all commands into the console command and thereby executing them...
CodePudding user response:
As commented, the number of fields do not match.
You are specifying the duration with the -t
option, without using
stop_time
in your ffmpeg command. Besides you will need to put -nostdin
option to disable the input via stdin. Then please try instead:
while read -r start_time output_name; do
ffmpeg -y -nostdin -ss "$start_time" -t 10 -i input_video.mp4 "$output_name"
done < myTextFile.txt