Batch Converter for MLV Raw Video to MP4 (for UNIX/Mac)

Started by harrywang, December 03, 2017, 06:38:48 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

harrywang

Hey everyone,

I've recently been tinkering around with RAW video on my 6D and I'd like to share a simple script I wrote to batch convert from MLV to MP4.

It is written in Bash for UNIX systems (Linux/Mac). You can find the Github repository, at https://github.com/perhapsmaybeharry/mlvtomp4

Feedback and other comments are gladly welcome!

Below is a copy of the documentation found at the Github page.

# mlvtomp4
Simple Batch Converter for Magic Lantern Raw Video (MLV) to MP4 for UNIX

---

### What is this?

The script mlvtomp4 is a Bash script for UNIX (Mac/Linux) systems that converts Magic Lantern Raw Video (MLV) to MP4 files for use in post-processing or review.

### How does it work?

The script works by unpacking the MLV file to reveal the contained DNGs, converting those DNGs into a PPM format, and sequencing them together at 24 frames per second into an MP4 file.

### Setting up the Environment

Before you can use `mlvtomp4`, there are a few dependencies you will need to install:
  - mlv_dump, from the Magic Lantern forums at https://www.magiclantern.fm/forum/index.php?topic=18975.0
  - dcraw, from brew/apt-get, or at https://www.cybercom.net/~dcoffin/dcraw/
  - ffmpeg, from brew/apt-get, or at https://www.ffmpeg.org/
 
`mlvtomp4` will warn you if any of the required dependencies are not present.

### How do I use it?

(assuming the script is saved to `~`)

*If you get a 'not permitted' error when attempting to run the script, try the following command: `~$ chmod +x mlvtomp4`*

Running the script is as simple as providing it the filenames of as many *.MLV files you would like to convert.

```
# Convert the MLV file M01_0001.MLV to MP4
~$ ./mlvtomp4 M01_0001.MLV

# Convert the MLV files M01_0001.MLV and M01_0002.MLV to MP4
~$ ./mlvtomp4 M01_0001.MLV M01_0002.MLV

# Convert all the MLV files in the current directory
~$ ./mlvtomp4 *.MLV
```

The associated MP4 files will be placed next to the existing MLV file after the conversion process has completed.

### User-defined Variables

`FRAMERATE`: The framerate at which the MP4 should play at. Default is 24.
`FRAMESIZE`: The framesize of the resulting MP4 video. Default is 1824x684. **It is recommended you change this to the appropriate size as recorded by the camera.**

### Advanced Users

If you have any specific mlv_dump, dcraw, or ffmpeg options, simply edit the script and its command invocations to include your options.

masc

5D3.113 | EOSM.202

Danne

Nice effort. As mentioned by masc Switch will be able to export to a variety of formats amongst them mp4. One quick tip is that you could use piping files straight from dcraw to ffmpeg so no need for ppm intermediate files.
Or why not simply use Mlv App and batch export straight from MLV format. Works great.

harrywang

Quote from: masc on December 03, 2017, 10:27:49 PM
Nice! But isn't that partially the same what also switch does? http://www.magiclantern.fm/forum/index.php?topic=15108.0
@masc Yeah, it's pretty much the same as Switch although much less full-featured and slightly simpler.

Quote from: Danne on December 04, 2017, 12:06:13 AM
Nice effort. As mentioned by masc Switch will be able to export to a variety of formats amongst them mp4. One quick tip is that you could use piping files straight from dcraw to ffmpeg so no need for ppm intermediate files.
Or why not simply use Mlv App and batch export straight from MLV format. Works great.
@danne Thanks for the tip! I'll look into it and write it in.

Danne

Piping looks like this in Switch:
find "$out""$out3""$name""$sl". -maxdepth 1 -iname '*.dng' -print0 | xargs -0 dcraw +M $h2 $o $S -c -6 -W $qual $gam $wb $pix $br | ffmpeg -loglevel warning $wav1 -f image2pipe -vcodec ppm -r $fps -i pipe:0 $sd $Pcodec -n -r $fps $tbl$cin$cin_01$cin_02$cin_03$cin_01b$cin_02b$cin_03b$scale$denoise$sharpen "$out""$out2""$date"_ProRes4444/"$name".$ext

Pretty much boils down to:
find . -maxdepth 1 -iname '*.dng' -print0 | xargs -0 dcraw +M -q 3 -c -6 -W  | ffmpeg -loglevel warning -i *.wav -f image2pipe -vcodec ppm -r 24 -i pipe:0 -c:v copy -c:a aac -vcodec prores_ks -pix_fmt yuv444p10 -n -r 24 Output.mov



harrywang

Quote from: Danne on December 04, 2017, 08:14:29 AM
Piping looks like this in Switch:
find "$out""$out3""$name""$sl". -maxdepth 1 -iname '*.dng' -print0 | xargs -0 dcraw +M $h2 $o $S -c -6 -W $qual $gam $wb $pix $br | ffmpeg -loglevel warning $wav1 -f image2pipe -vcodec ppm -r $fps -i pipe:0 $sd $Pcodec -n -r $fps $tbl$cin$cin_01$cin_02$cin_03$cin_01b$cin_02b$cin_03b$scale$denoise$sharpen "$out""$out2""$date"_ProRes4444/"$name".$ext

Pretty much boils down to:
find . -maxdepth 1 -iname '*.dng' -print0 | xargs -0 dcraw +M -q 3 -c -6 -W  | ffmpeg -loglevel warning -i *.wav -f image2pipe -vcodec ppm -r 24 -i pipe:0 -c:v copy -c:a aac -vcodec prores_ks -pix_fmt yuv444p10 -n -r 24 Output.mov


Thanks Danne, it's been implemented in the latest commit https://github.com/perhapsmaybeharry/mlvtomp4/commit/7a459b5f2394e1ae663ad54b172eaf3af7348a24