Saturday, July 24, 2010

Canon 5D conversion for xiphmont's git

As Monty has been working hard to make Cinelerra more input friendly with his FFmpeg loader fixes, I've been trying to help out as a QA resource. One of my main concerns has been getting my Canon 5D video into Cinelerra. As documented in the IRC log, my custom Canon conversion (ffmpeg stream -> mpeg2enc (output: .m2v/.m2a) -> mplex (output MPEG-PS) -> ffmpeg (output MPEG-TS) was full of invalid timestamps.

In addition, with some recent security updates to my Fedora system just today, it looks like my previous Canon conversion script had broken. I get the dread error:
**ERROR: [mpeg2enc] display_horizontal_size must be in range 0...16383

So I was doubly screwed. Back to the drawing board..er, mailing list. Following up on mjpegtools' Bernhard Prachinger's advice here, I first try to play a test file using a pipe from ffmpeg, like so:
ffmpeg -i mvi_2655.mov -threads 7 -s 1920x1088 -f yuv4mpegpipe - | yuvplay

The video stream plays back with no visible errors, outside of a warning about the video stream frame rate differing from the container frame rate. Here are the top few lines of the output:
Seems stream 0 codec frame rate differs from container frame rate: 48000.00 (48000/1) -> 23.98 (24000/1001)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'mvi_2655.mov':
Duration: 00:00:06.92, start: 0.000000, bitrate: 45836 kb/s
Stream #0.0(eng): Video: h264, yuv420p, 1920x1088, 44296 kb/s, 23.98 tbr, 24k tbn, 48k tbc
Stream #0.1(eng): Audio: pcm_s16le, 48000 Hz, 2 channels, s16, 1536 kb/s
Metadata
major_brand : qt
minor_version : 537331968
compatible_brands: qt CAEP
Output #0, yuv4mpegpipe, to 'pipe:':
Stream #0.0(eng): Video: rawvideo, yuv420p, 920x108, q=2-31, 200 kb/s, 90k tbn, 23.98 tbc
Stream mapping:
Stream #0.0 -> #0.0
Press [q] to stop encoding

INFO: [yuvplay] Playing frame 0000 - 0:00:00.00
INFO: [yuvplay] Playing frame 0001 - 0:00:00.01
INFO: [yuvplay] Playing frame 0002 - 0:00:00.02
INFO: [yuvplay] Playing frame 0003 - 0:00:00.03
INFO: [yuvplay] Playing frame 0004 - 0:00:00.04
INFO: [yuvplay] Playing frame 0005 - 0:00:00.05
INFO: [yuvplay] Playing frame 0006 - 0:00:00.06
INFO: [yuvplay] Playing frame 0007 - 0:00:00.077 bitrate=752028.9kbits/s


So, streaming from FFmpeg to a y4m stream works. I then take that y4m stream and convert it to an mpeg2video for use in Cinelerra, again using Bernhard's simplified mpeg2enc pipe adjusted for aspect ratio and higher bitrate:
ffmpeg -i mvi_2655.mov -threads 7 -s 1920x1088 -f yuv4mpegpipe - | mpeg2enc --verbose 2 --format 3 --aspect 3 --video-bitrate 24000 --no-constraints --video-buffer 448 -o mvi_2655.m2v

Looking at the output (--verbose 2), there don't seem to be any major errors here:
Seems stream 0 codec frame rate differs from container frame rate: 48000.00 (48000/1) -> 23.98 (24000/1001)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'mvi_2655.mov':
Duration: 00:00:06.92, start: 0.000000, bitrate: 45836 kb/s
Stream #0.0(eng): Video: h264, yuv420p, 1920x1088, 44296 kb/s, 23.98 tbr, 24k tbn, 48k tbc
Stream #0.1(eng): Audio: pcm_s16le, 48000 Hz, 2 channels, s16, 1536 kb/s
Metadata
major_brand : qt
minor_version : 537331968
compatible_brands: qt CAEP
Output #0, yuv4mpegpipe, to 'pipe:':
Stream #0.0(eng): Video: rawvideo, yuv420p, 920x108, q=2-31, 200 kb/s, 90k tbn, 23.98 tbc
Stream mapping:
Stream #0.0 -> #0.0
Press [q] to stop encoding
INFO: [mpeg2enc] Selecting Generic MPEG2 output profile
INFO: [mpeg2enc] Assuming norm NTSC
INFO: [mpeg2enc] Progressive input - selecting progressive encoding.
INFO: [mpeg2enc] Encoding MPEG-2 video to mvi_2655.m2v
INFO: [mpeg2enc] Horizontal size: 920 pel
INFO: [mpeg2enc] Vertical size: 108 pel
INFO: [mpeg2enc] Aspect ratio code: 3 = 16:9 display
INFO: [mpeg2enc] Frame rate code: 1 = 24000.0/1001.0 (NTSC 3:2 pulldown converted FILM)
INFO: [mpeg2enc] Bitrate: 24000 KBit/s
INFO: [mpeg2enc] Quality factor: 8 (Quantisation = 9) (1=best, 31=worst)
INFO: [mpeg2enc] Field order for input: none/progressive
INFO: [mpeg2enc] Sequence unlimited length
INFO: [mpeg2enc] Search radius: 16
INFO: [mpeg2enc] DualPrime: no
INFO: [mpeg2enc] Using one-pass rate controller
INFO: [mpeg2enc] GOP SIZE RANGE 7 TO 15
INFO: [mpeg2enc] Setting colour/gamma parameters to "NTSC"
INFO: [mpeg2enc] Progressive format frames = 1
INFO: [mpeg2enc] Using default unmodified quantization matrices
INFO: [mpeg2enc] SETTING MMX and MMX for QUANTIZER!
--DEBUG: [mpeg2enc] PAR = 7



I then take the output of the audio conversion:
ffmpeg -i mvi_2655.mov -acodec mp2 -ab 384k -ar 48000 -ac 2 test.m2a

Output:
Seems stream 0 codec frame rate differs from container frame rate: 48000.00 (48000/1) -> 23.98 (24000/1001)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'mvi_2655.mov':
Duration: 00:00:06.92, start: 0.000000, bitrate: 45836 kb/s
Stream #0.0(eng): Video: h264, yuv420p, 1920x1088, 44296 kb/s, 23.98 tbr, 24k tbn, 48k tbc
Stream #0.1(eng): Audio: pcm_s16le, 48000 Hz, 2 channels, s16, 1536 kb/s
Metadata
major_brand : qt
minor_version : 537331968
compatible_brands: qt CAEP
Output #0, mp2, to 'mvi_2655.m2a':
Stream #0.0(eng): Audio: mp2, 48000 Hz, 2 channels, s16, 384 kb/s
Stream mapping:
Stream #0.1 -> #0.0
Press [q] to stop encoding
size= 325kB time=6.94 bitrate= 384.0kbits/s
video:0kB audio:325kB global headers:0kB muxing overhead 0.000000%

and mux both the video and audio streams to an MPEG-PS in mplex:
mplex -f 3 -b 2000 mvi_2655.m2a mvi_2655.m2v -o mvi_2655.ps

Output:
INFO: [mplex] mplex version 1.9.0 (2.2.7 $Date: 2006/02/01 22:23:01 $)
INFO: [mplex] File mvi_2655.m2a looks like an MPEG Audio stream.
INFO: [mplex] File mvi_2655.m2v looks like an MPEG Video stream.
INFO: [mplex] Found 1 audio streams and 1 video streams
INFO: [mplex] Selecting generic MPEG2 output profile
INFO: [mplex] Multiplexing video program stream!
INFO: [mplex] Scanning for header info: Audio stream c0 (mvi_2655.m2a)
INFO: [mplex] MPEG AUDIO STREAM: c0
INFO: [mplex] Audio version : 1.0
INFO: [mplex] Layer : 2
INFO: [mplex] CRC checksums : no
INFO: [mplex] Bit rate : 49152 bytes/sec (384 kbit/sec)
INFO: [mplex] Frequency : 48000 Hz
INFO: [mplex] Mode : 0 stereo
INFO: [mplex] Mode extension : 0
INFO: [mplex] Copyright bit : 0 no copyright
INFO: [mplex] Original/Copy : 1 original
INFO: [mplex] Emphasis : 0 none
INFO: [mplex] Scanning for header info: Video stream e0 (mvi_2655.m2v)
INFO: [mplex] VIDEO STREAM: e0
INFO: [mplex] Frame width : 1920
INFO: [mplex] Frame height : 1088
INFO: [mplex] Aspect ratio : 16:9 display
INFO: [mplex] Picture rate : 23.976 frames/sec
INFO: [mplex] Bit rate : 24000000 bits/sec
INFO: [mplex] Vbv buffer size : 229376 bytes
INFO: [mplex] CSPF : 0
INFO: [mplex] SYSTEMS/PROGRAM stream:
INFO: [mplex] rough-guess multiplexed stream data rate : 24894496
INFO: [mplex] Setting best-guess data rate.
INFO: [mplex] Run-in delay = 30030 Video delay = 30030 Audio delay = 33783
INFO: [mplex] New sequence commences...
INFO: [mplex] Audio c0: buf= 0 frame=000000 sector=00000000
INFO: [mplex] Video e0: buf= 0 frame=000000 sector=00000000
INFO: [mplex] Scanned to end AU 165
INFO: [mplex] STREAM e0 completed
INFO: [mplex] STREAM c0 completed
INFO: [mplex] Multiplex completion at SCR=653806.
INFO: [mplex] Audio c0: completed
INFO: [mplex] Video e0: completed
INFO: [mplex] AUDIO_STATISTICS: c0
INFO: [mplex] Audio stream length 332928 bytes.
INFO: [mplex] Syncwords : 289
INFO: [mplex] Frames : 289 padded
INFO: [mplex] Frames : 0 unpadded
INFO: [mplex] BUFFERING min 189 Buf max 1162
INFO: [mplex] VIDEO_STATISTICS: e0
INFO: [mplex] Video Stream length: 13871991 bytes
INFO: [mplex] Sequence headers: 1
INFO: [mplex] Sequence ends : 1
INFO: [mplex] No. Pictures : 166
INFO: [mplex] No. Groups : 12
INFO: [mplex] No. I Frames : 12 avg. size162167 bytes
INFO: [mplex] No. P Frames : 154 avg. size 77441 bytes
INFO: [mplex] No. B Frames : 0 avg. size 0 bytes
INFO: [mplex] Average bit-rate : 16028800 bits/sec
INFO: [mplex] Peak bit-rate : 21470400 bits/sec
INFO: [mplex] BUFFERING min 85 Buf max 1944774
INFO: [mplex] MUX STATUS: no under-runs detected


This gives me a good program stream file that is suitable for editing in Cinelerra using Monty's changes. Update 2010/09/13: Florian Cramer advised me that the video render string does not give the highest quality output. I'm still working on improvements to the string that will render at a higher quality.

Moral of the story: never update your system.
;)
the mule

Reference
http://man-wiki.net/index.php/1:mplex
Minor headache with nvidia drivers after kernel upgrade resolved
Plus another pulseaudio fuck job.."pulseaudio module-alsa-card file not found"
- had to reinstall pulseaudio and then execute "alsamixer -c0" to fix

No comments: