Sony PXW-Z190, ffmpeg batch transcode to ProRes Quicktime: Explained

Specific guide on using ffmpeg to transcode Quicktime (ProRes) from the native MXF as recorded by Sony PXW-Z190 cameras. Also of interest to users of the PXW-Z280. For those of you desperate to cut and paste an incantation into Terminal – here you go:

 for i in *.MXF; do ffmpeg -i "$i"   -map 0:0 -map 0:1 -map 0:2 -map 0:3 -map 0:4 -c:v prores_ks -profile:v 1 -quant_mat:v 3 -qscale:v 13   "./output/${i%.*}.mov";done

Read on to understand what it does and why it works. If you’re not technical or used to Terminal – don’t worry we do it step by step.


So for the transcode we want to operate on the video stream particularly which is in h264, and transcode that to ProRes. We could do things to the audio stream but here we are just going to copy the four tracks of audio straight over.

Video transcode

Using ffprobe find the information about the zeroth stream which in this camera is the video…

Stream #0:0: Video: h264 (High), yuv420p(tv, bt709, progressive), 3840x2160 [SAR 1:1 DAR 16:9], 29.97 fps, 29.97 tbr, 29.97 tbn, 59.94 tbc    

So lets write a ffmpeg command to just make a QuickTime video file with no audio to illustrate what we are about.

ffmpeg -i INPUT.MXF -c:v prores_ks -profile:v 1 -quant_mat:v 3 -qscale 20  OUTPUT.MOV    

Exploding the command term by term

  • -c:v Selects the zeroth stream. If your video is somewhere else or there are n video streams then you need to map it / them formally
  • prores_ks selects the codec – This is one of number of ProRes options but is the one that I’ve had most luck with. Here’s a slightly despairing blog by one of the original authors: ProRes KS
  • -profile:v a preconfigured profile in prores_ks options are specified by an integer thus: -profile:v 3
    • 0 ‘proxy’
    • 1 ‘lt’ (suprisingly useful especially when output to web)
    • 2 ‘standard’
    • 3 ‘hq’
    • 4 ‘4444’
    • 5 ‘4444xq’
  • -quant_mat a preconfigured matrixes in prores_ks options are specified by an integer thus: -profile:v 3
    • 0‘auto’
    • 1‘default’
    • 2‘proxy’
    • 3‘lt’
    • 4 ‘standard’
    • 5 ‘hq’
  • -qscale Quantiser. Very broadly this is about the way the encoder picks the amount of compression per frame. Setting a fixed qscale speeds up the encode because a whole chunk of processing to get best quality is short-circuited.
  • bits_per_mb higher values will improve speed. I don’t recommend specifying both this and -qscaleat the same time because predicting the outcome gets tricky if you aren’t intimate with the maths

Audio copy

ffmpeg -i INPUT.MXF -map 0:1 -map 0:2 -map 0:3 -map 0:4 -c:a copy  OUTPUT.MOV    

Creating a straight copy over of the audio as PCM – i.e. without transcoding needs the use of the map command. There’s a better explanation of what’s going on here than I can give ffmpeg wiki some systems may struggle with the raw audio.

 Synthesising the command

ffmpeg -i INPUT.MXF -map 0:1 -map 0:2 -map 0:3 -map 0:4 -c:v prores_ks -profile:v 1  -quant_mat:v 3 -qscale:v 12  -c:a:0  pcm_alaw  -c:a:1  pcm_alaw -c:a:2 pcm_alaw -c:a:3 pcm_alaw OUTPUT.mov
    

Note that we now need to map the video channel explicitly.

Now some magic to make I process a directory of files.

This works in OSX and probably works in most Linux. I’m not going to explain because why ‘$I’ works isn’t straightforward…

The only requirement here is that you probably should pre-create a directory called /output in the active directory. So if you’re working dir is
$usr/video then $usr/video/output

 for i in *.MXF; do ffmpeg -i "$i"   -map 0:0 -map 0:1 -map 0:2 -map 0:3 -map 0:4 -c:v prores_ks -profile:v 1 -quant_mat:v 3 -qscale:v 13  -c:a:0  pcm_alaw  -c:a:1  pcm_alaw -c:a:2 pcm_alaw -c:a:3 pcm_alaw "./output/${i%.*}.mov";done

Use your friend ffprobe

use ffmpeg without a solid understanding of the file you are feeding it as an input is fairly futile for all but the most straightforward cases. So first steps is always to use ffprobe to examine the input.

The bits we need from the screed of the Metadata report are the stream definitions – since they help with specifying the right options for the transcode.

 Video definition

 Stream #0:0: Video: h264 (High), yuv420p(tv, bt709, progressive), 3840x2160 [SAR 1:1 DAR 16:9], 29.97 fps, 29.97 tbr, 29.97 tbn, 59.94 tbc    

The first stream is the video – h264 encoded, colour depth 4:2:0,

N audio streams

 Stream #0:1: Audio: pcm_s24le, 48000 Hz, 1 channels, s32 (24 bit), 1152 kb/s

Then we get to the audio streams of which there are at least four – two external microphones, and two internal mics. I haven’t been able to test the Sony special interface

Mysterious fifth stream

There is a data stream which it isn’t quite clear what it does – It’s timecode related but I don’t do enough TC specific stuff to have worked out what.

Childhood obesity in the Diocese of Winchester

Obesity correlates with issues related issues the bible talks about as matters of justice and mercy. Unofficially for Church of England leaders in Winchester Diocese I’ve mapped childhood obesity prevalence in a way which allows an estimate of the situation in their parish. Click the picture to link to a larger file better formatted for printing

Continue reading “Childhood obesity in the Diocese of Winchester”