Quantcast

ffmpeg mangling heredoc lines in bash

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

ffmpeg mangling heredoc lines in bash

Samuel Rakitničan
Dear list,

I am trying to split a mp3 file into multiple tracks with a bash script
using ffmpeg. Somehow I can't achieve the desired effect due to some weird
behavior when ffmpeg is included. So the script is going line by line and
splitting one big mp3 file into multiple files (tracks) based on input from
heredoc data.

#!/bin/bash

if [ ! -f "$1" ]; then
  echo "Invalid input file"
  exit 1
fi

if [ ! -d "$2" ]; then
  mkdir $2 || exit 1
fi

_count=0
while read -r _line; do
  ((_count++))
#  printf "   %s\n" $_line
  echo $_line
  _end=$(echo "$_line" | cut -f1)
  _title=$(echo "$_line" | cut -f2)
  _trackno=$(printf "%02d\n" $_count)
  echo "Writting -ss "${_start-00:00:00}" -to "${_end}" $_trackno -
$_title.mp3"
#  ffmpeg -y -i "$1" -vn -acodec copy -ss "${_start-00:00:00}" -to "$_end" \
#         "$2/$_trackno - $_title.mp3" &> /dev/null
  _start="${_end}"
  sleep 1
done<<'TrackList'
00:01:56 Track 1
00:07:12 Track 2
00:12:15 Track 3
00:16:44 Track 4
TrackList

Script like this produces desired output:
Writting -ss 00:00:00 -to 00:01:56 01 - Track 1.mp3
00:07:12 Track 2
Writting -ss 00:01:56 -to 00:07:12 02 - Track 2.mp3
00:12:15 Track 3
Writting -ss 00:07:12 -to 00:12:15 03 - Track 3.mp3
00:16:44 Track 4
Writting -ss 00:12:15 -to 00:16:44 04 - Track 4.mp3

As soon as I uncomment ffmpeg line, output gets mangled:

00:01:56 Track 1
Writting -ss 00:00:00 -to 00:01:56 01 - Track 1.mp3
0:07:12 Track 2
Writting -ss 00:01:56 -to 0:07:12 02 - Track 2.mp3
:12:15 Track 3
Writting -ss 0:07:12 -to :12:15 03 - Track 3.mp3
00:16:44 Track 4
Writting -ss :12:15 -to 00:16:44 04 - Track 4.mp3

Anyone have an idea of what is happening?


P.S. I managed to achieve what I wanted with another loop, first loop
processes heredoc input into array, and then I process array into input for
ffmpeg.
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Loading...