Wednesday, November 6, 2013

convert MTS video files into DV for iMovie editing

After using my sony cam I discovered that MTS files are not imported into iMovie for editing which was needed for a quick project today. After a bit of google-ing to understand if the version was the problem or what else I decided to go use a workaround as simple as a 1 line shell ffmpeg command:


ls -R /path | awk '
/:$/&&f{s=$0;f=0}
/:$/&&!f{sub(/:$/,"");s=$0;f=1;next} 
NF&&f{ print s"/"$0 }'|grep *.MTS|while read i;
/do bitrate=`ffmpeg -i "$i" 2>&1 |grep bitrate|
/sed 's/.*bitrate: //' |sed 's/kb\/s/k/'`;ffmpeg -i "$i" -f avi -b $bitrate -ab 192k "$i".mov; done

It just collects all the MTS files into a certain dir and converts into mov ones.
The only small difficulty was to use the same bitrate as the original file to preserve quality 
(which is calculated every time from the ffmpeg -i "$i" 2>&1 |grep bitrate|sed 's/.*bitrate: //' |sed 's/kb\/s/k/' part) 

Just discovered that a simple replacement of the container is faster and as much effective as the prev:

ls -R /path | awk '
/:$/&&f{s=$0;f=0}
/:$/&&!f{sub(/:$/,"");s=$0;f=1;next} 
NF&&f{ print s"/"$0 }'|grep *.MTS|while read i;
do ffmpeg -i "$i" -vcodec copy -acodec copy "$i".mov; done

hope this will be helpful to someone (for sure it'll be for me so to paste the command each time needed :p)



Alex 

3 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. someone had problems with one line command due to the speed of ffmpeg.
    You can use the following to create a bash and then exec it

    ls -1 *.MTS|while read i;do bitrate=`ffmpeg -i "$i" 2>&1 |grep bitrate|sed 's/.*bitrate: //' |sed 's/kb\/s/k/`;echo 'ffmpeg -y -i "'$i'" -f avi -b' $bitrate' -ab 192k "'$i'.DV"' >>convert.sh; done

    ReplyDelete
  3. This comment has been removed by a blog administrator.

    ReplyDelete