1

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...

5
  • 2
    Your input-file and script don't match each other. The script expects three fields, while the file only provides two. Commented Apr 13, 2022 at 18:17
  • 2
    This explains -nostdin option : superuser.com/a/1492515/1127143 Commented Apr 13, 2022 at 18:30
  • @Philippe Thx for the hint. Though I don't fully understand what the problem is. How is ffmpeg aware of the fact that it is executed as part of a while loop? Commented Apr 14, 2022 at 6:36
  • Update: adding -nostdin does the trick! Commented Apr 14, 2022 at 6:42
  • 1
    ffmpeg reads standard input, which causes problem to read line. You can check by removing -nostdin option and adding ffmpeg ... < /dev/null, which should work as well. Commented Apr 14, 2022 at 8:11

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

4 Comments

sorry, that was mistake. I had an alternative version of the script with start and stop time, but it had similar issues. I fixed my question
Have you tried my script abyway?
I tried multiple versions, but only posted a minimal working example. Your answer seems to be missing the trick of adding the the -nostdin option as pointed out by Philippe
I just tested your solution. It still has the above mentioned bug. Please add the -nostdin option to your answer so I can accept it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.