[lfs-chat] scripts for processing mov files into something for youtube

Ken Moffat zarniwhoop at ntlworld.com
Thu Jul 31 18:22:56 PDT 2014


On Wed, Jul 16, 2014 at 05:22:45PM +0100, Ken Moffat wrote:

 Moving to chat, it's probably a bit too far beyond BLFS to keep it
on support :)  So, I'll keep the whole of this for context.

> On Wed, Jun 25, 2014 at 01:05:50AM +0100, Ken Moffat wrote:
> > On Fri, Jun 20, 2014 at 02:12:41AM +0100, Ken Moffat wrote:
> > > 
> > >  After two days of intermittent banging my head against a keyboard /
> > > googling / cursing, I have now got a process of preparing the
> > > individual clips with ffmpeg to a position where it might be usable.
> > [...]
> > > 
> > >  What I have done for now is to keep the audio as .wav, and called
> > > it a .mkv file because it clearly isn't mp4.  Xine only plays the
> > > video from this.  The benefit of this is that the although even the
> > > video has now grown by 67ms, the audio has only grown by 69ms so the
> > > relative loss of sync is 2ms for this clip.
> > > 
> > >  Still need to do similar things to at least one other clip (but
> > > I think I now understand the process, and on a good day I can
> > > remember how the ffmpeg options fit together), and prepare at least a
> > > title image, then I will find out if I can successfully convert it
> > > all to mp4 and upload it to youtube : for the moment, I am sort-of
> > > expecting that to fail, in which case I will be in mega-sulk mode in
> > > a few days :-(
> > > 
> > 
> >  And now getting very close to mega-sulk mode, and I have not even
> > got as far as trying to upload to youtube.
> > 
> [ ... ]
> > 
> >  So, last night I did a quick test with the first two clips, using
> > -preset ultrafast for a single pass encoding.  That worked, although
> > the video quality on one clip was noticeably worse than with the
> > -preset veryslow two-pass encoding.
> > 
> [ ... ]
> >  I can almost remember how I felt the last time I eventually gave up
> > trying to edit my clips (that was apparently with ffmpeg-0.7.4).  I
> > hesitate to say "suggestions welcome" because some suggestions will
> > undoubtedly upset me, but has anyone here edited .mov video clips
> > into a single video using _recent_ ffmpeg ?
> > 
> At last, a *progress* report -
> 
>  Came back to this on Monday.  At last I have some success to
> report (but I also realise that I've got to review almost everything
> I've done along the way - the ffmpeg wiki
> https://trac.ffmpeg.org/wiki/Encode/H.264 suggests many of the
> settings I have used are suboptimal).
> 
>  Anyway, my example is now at
> https://www.youtube.com/watch?v=VmfYQKvmGSQ (views from a train on
> the Arosa line of the RhB in Switzerland).  I'm sure very few people
> here will find the subject interesting, but there we are.  Perhaps
> the captions at start and end might raise a smile.
> 
>  I am sort-of hoping to document how to do this in a hint (ffmpeg
> is a fast-moving target, I've only done this on 2.2.2 which is
> already "old"), but the process is somewhat tedious and involved [
> that maybe will not deter BLFS users ].  The worst part is putting
> the processed clips back together.  For example, the command to
> create this video from only 5 parts was like:
> 
> ffmpeg -i start-caption.mkv -i clip1.mkv -i clip2.mkv \
>  -i clip3.mkv -i end-caption.mkv \
>  -filter_complex '[0:0] [0:1] [1:0] [1:1] [2:0] [2:1] [3:0] [3:1] [4:0] [4:1] concat=5:v=1:a=1 [v]
> [a]' \
>  -map '[v]' -map '[a]' -s 1280x720 \
>  -vcodec libx264 -tune film -b:v 7000k \
>  -acodec libfdk_aac -cutoff 16000 -b:a 128k -y \
> outfile.mkv
> 
>  and those parameters for -filter_complex will get longer for each
> additional file :-(  Also, it re-encodes when doing this, which I
> had hoped to avoid - turns out only straight mp4 can be
> concatenated, but I took the opportunity to change the audio to aac
> ready for upload.
> 
>  I also tried mkvmerge from mkvtoolnix-7.0.0 but it did not work for
> me, so I guess I'll file a general bug and see if my use-case is
> valid. <sigh/>
> 
>  With luck, I might finish my film for that line (perhaps another 10
> clips / 7 minutes) sometime this year :)
> 
> ĸen

 So, I reworked what I was doing (changed to single-pass encodes, and
eventually to just playing with the crf value (I use x264 for
video).  What I had originally done in 2011 was to use two-pass,
play with presets, and change the size of the video buffer.  With
ffmpeg-2.2.2 and recent x264 I find that specifying a crf makes a
lot of difference to how long it takes, and how big the files are -
playing with the video buffer size makes a minimal difference to
those, but did reduce the quality, and playing with different
presets seemed unhelpful.

 The scripts are now at
https://github.com/zarniwhoop73/video-scripts and licensed under the
WTFPL - if I had written any significant code, I would have used
GPL, but this is 99% scraped from google's results.  The only part I
think is an interesting hack is that I change any spaces in text
(captions superimposed on the video) to non-break-space because I
can't get my head around the quoting of shell variables used to make
up video filter parameters in ffmpeg (double quotes, escaped or not,
break it, and spaces in the text also broke it).

 So, now it is out there, I won't be writing a hint.

 Examples of the results are in my youtube files (user zarnimovies),
e.g. Landwasser : http://youtu.be/FXcs9urpU5g for a short one
(actually just one clip, no captions), and along the Engadin
http://youtu.be/HVWBDRKFLXI for the most recent (27 files, including
'slide' captions and text overlays - I would not have fancied
typing the merge command for this one ;)  As with my manually
prepared version mentioned above, these are all trains/landscape,
and variable quality.  So probably not interesting to most people.
But I guess the scripts might be.  Mostly they use ffmpeg, with sox
to handle fading the audio.

 A summary of how to use them follows - I guess that almost everyone
who reads this far won't care, but this is -chat so here goes :

 My editing is now straightforward - list the clips, check duration
/ where to cut using vlc, cut with ffmpeg (i.e. copy the original
mov file to a new name, specifying start/time as appropriate - for
overlaid text I split a clip into before|text|after versions).

 Then, I use my video-summary script to confirm the length, and
number of frames, for each clip.  That script uses MediaInfo-CLI.
After that I can pass in values for video-fade-in/out (start frame
and number of frames), volume (255=unchanged), text, audio fade
(parms passed to sox, things like "h 2 0".  So simple, even I can
do it.

 For "slides" I either take a still photo, or extract a png from
the video, scrawl over it in the gimp, and use the slide script to
create an mkv file of a specified duration, with silence.

 Then I use the merge script, perhaps with a title (in fact,
youtube seems to ignore titles in the video itself), and see how
little quality (high crf setting) I think I can get away with : I've
got decent download speed from virginmedia, but the best upload is
about 2Mbps (about 10.5MB/minute in practice), so large uploads are
tedious.

ĸen
-- 
Nanny Ogg usually went to bed early. After all, she was an old lady.
Sometimes she went to bed as early as 6 a.m.


More information about the lfs-chat mailing list