This forum has been archived. All content is frozen. Please use KDE Discuss instead.

A bash script for transcoding AVCHD clips to DNxHD

Tags: None
(comma "," separated)
Jonathan Haug
Registered Member
Posts
18
Karma
0
Dear Forum,

in this post I'm describing the bash script I'm using in my workflow with kdenlive, described in another post: http://kdenlive.org/forum/my-workflow-kdenlive .

#!/bin/bash

# define two directories: source and target
sourcePath="/home/username/videofiles/"
targetPath="/home/username/encodedfiles/"


# do a loop through all *.MTS files in the given source directory
for i in $sourcePath*.MTS ; do


# check if the file has already been transcoded
if [ ! -f $targetPath${i##*/}.mov ]
then


# cut off the last frames of every clip
# (This is due to some white frames, which would appear for some reasons at the end of every clip.)

duration=( $(ffmpeg -i "$i" 2>&1 | sed -n "s/.* Duration: \([^,]*\), start: .*/\1/p") )
hours=( $(echo $duration | cut -d":" -f1) )
minutes=( $(echo $duration | cut -d":" -f2) )
seconds=( $(echo $duration | cut -d":" -f3) )
duration=$(echo "$hours*3600+$minutes*60+$seconds-0.12" | bc)


# transcode!
ffmpeg -i $i -s 1280x720 -deinterlace -r 25 -t $duration -b 60M -threads 8 -vcodec dnxhd -acodec pcm_s16le -ar 48000 -ac 2 $targetPath${i##*/}.mov

fi

done

That's all.
As a side note: I experienced some strange effects when there was a nautilus window open while transcoding, showing the transcoded files.
To avoid this and to be sure that ffmpeg is not "disturbed" in any way from anything, I'm going to console when using the above script:
1) sudo service gdm stop
2) Alt+F2
3) Start the script
4) sudo service gdm start

A huge problem was audio sync in the resulting media. These problems are mostly solved for me in the current svn snapshot of ffmpeg.
I still have issues when using the PreRec function of my camcorder. I've opened a bug report for that:
http://roundup.ffmpeg.org/issue2319

Any suggestions to the script are appreciated!

Jonathan
eriksl
Registered Member
Posts
32
Karma
0
The issue you see with nautilus really shouldn't occur, I guess it's a bug in nautilus, I guess it can't handle the continuous file updates. The workaround is far more easy than you describe, simply close the nautilus window that shows the working directory or point it to another directory while transcoding.

If audio and video are out of sync, that mostly means that there is a video/audio skew in the resulting file, "corrected" by the "pointers" in the container. This tends to not work well for editing because audio and video get separated and the container is lost. If you add -vsync 1 to the ffmpeg command line, it forces ffmpeg to insert and drop frames video frames in order to get the audio and video exactly "besides" each other in the file, without skew. The main disadvantage of this is that the file may grow due to duplicated frames.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]