2014年12月6日土曜日

RaspberryPiでMpeg2→Mpeg4へトランスコードする・続3

3回に渡って試行錯誤しながらやってきたが、
やり方がほぼ確立されたので今回で総集編となる。

Step1.準備
 $ git clone https://github.com/dickontoo/omxtx.git
 $ cd omxtx
 $ make
 $ sudo cp /usr/local/bin/ omxtx

Step2.トランスコード src.ts -> out.mp4(Mpeg2:1440x1080→Mpeg4:960x540)
 $ ffmpeg -y -i src.ts -acodec copy dst.aac -vcodec copy -an aaa.m2v
 $ omxtx -x -v -d -r 960x540 aaa.m2v dst.mp4
 $ ffmpeg -y -i dst.aac -i dst.mp4 -vcodec copy -acodec copy out.mp4

これで完成。
処理時間はほぼ録画時間と同じで終わるので非力なCPUなのにがんばってると思う。
でもハードウェアエンコード・デコード特有というのか、OpenMax側で異常データと判断すると
フレーム落ちして画像が乱れてしまう問題がある。
画像を縮小しなければフレーム落ちしないから、続2で見たアスペクト比の設定パラメータが影響してるのかもしれない。。
あとは16の倍数で割り切れる画面サイズでないといけない可能性のあるので、
画面サイズは、
 256x144 ◎エラーなし
 512x288 ×フリーズする 768x432
 1024x576
 1280x720

のいずれかになるようにする。



 出力例(最後の方にフレームエラーが多発している。。)
$ omxtx -x -v -d -r 960x540 tes.track_273.m2v aaa.mp4
[mpeg1video @ 0x1e1bfc0] mpeg_decode_postinit() failure
[mpeg1video @ 0x1e1bfc0] mpeg_decode_postinit() failure
[mpeg1video @ 0x1e1bfc0] mpeg_decode_postinit() failure
[mpeg1video @ 0x1e1bfc0] mpeg_decode_postinit() failure
[mpeg1video @ 0x1e1bfc0] mpeg_decode_postinit() failure
[mpeg1video @ 0x1e1bfc0] mpeg_decode_postinit() failure
[mpeg1video @ 0x1e1bfc0] mpeg_decode_postinit() failure
[mpeg1video @ 0x1e1bfc0] mpeg_decode_postinit() failure
[mpeg1video @ 0x1e1bfc0] mpeg_decode_postinit() failure
[mpeg1video @ 0x1e1bfc0] mpeg_decode_postinit() failure
[mpeg1video @ 0x1e1bfc0] mpeg_decode_postinit() failure
[mpeg1video @ 0x1e1bfc0] mpeg_decode_postinit() failure
[mpeg1video @ 0x1e1bfc0] mpeg_decode_postinit() failure
[mpeg1video @ 0x1e1bfc0] mpeg_decode_postinit() failure

[mpegvideo @ 0x1e1a0e0] Estimating duration from bitrate, this may be inaccurate
Input #0, mpegvideo, from 'tes.track_273.m2v':
  Duration: 00:00:06.16, bitrate: 24057 kb/s
    Stream #0.0: Video: mpeg2video (Main), yuv420p, 1440x1080 [PAR 4:3 DAR 16:9], 24000 kb/s, 25 fps, 25 tbr, 25 tbn, 59.94 tbc
Found a video at index 0
Frame size: 1440x1080
Found stream 0, context 0x1e1bfc0
OMX_Init() completed at 1399.
OMX_GetHandle(&dec, DECNAME, &ctx, &decevents) completed at 1400.
OMX_GetHandle(&enc, ENCNAME, &ctx, &encevents) completed at 1401.
OMX_GetHandle(&rsz, RSZNAME, &ctx, &rszevents) completed at 1402.
OMX_GetHandle(&dei, DEINAME, &ctx, &genevents) completed at 1403.
Obtained handles.  0x1e22638 decode, 0x1e1b920 encode
OMX_GetParameter(dec, OMX_IndexParamVideoInit, porttype) completed at 1412.
Found 2 ports, starting at 130 (82) on decoder
OMX_GetParameter(enc, OMX_IndexParamVideoInit, porttype) completed at 1417.
Found 2 ports, starting at 200 (c8) on encoder
OMX_GetParameter(rsz, OMX_IndexParamImageInit, porttype) completed at 1422.
Found 2 ports, starting at 60(3c) on resizer
OMX_SendCommand(dec, OMX_CommandPortDisable, PORT_DEC, NULL) completed at 1427.
OMX_SendCommand(dec, OMX_CommandPortDisable, PORT_DEC+1, NULL) completed at 1428.
OMX_SendCommand(enc, OMX_CommandPortDisable, PORT_ENC, NULL) completed at 1429.
OMX_SendCommand(enc, OMX_CommandPortDisable, PORT_ENC+1, NULL) completed at 1430.
OMX_SendCommand(rsz, OMX_CommandPortDisable, PORT_RSZ, NULL) completed at 1433.
OMX_SendCommand(rsz, OMX_CommandPortDisable, PORT_RSZ+1, NULL) completed at 1435.
OMX_GetParameter(dec, OMX_IndexParamPortDefinition, portdef) completed at 1439.
Mapping codec ID 2 (2)
Mapping codec 2 to 2
Mapping codec ID 2 (2)
OMX_SetParameter(dec, OMX_IndexParamPortDefinition, portdef) completed at 1450.
Codecs supported:
        Index:          0
        Codec:          0 (0)
        Colour:         0
        Framerate:      0 (0.000000)
Levels supported:
        Index:          0
        Profile:        1
        Level:          256
Levels supported:
        Index:          1
        Profile:        32768
        Level:          256
OMX_GetParameter(handle, OMX_IndexParamPortDefinition, portdef) completed at 215.
Port 130 is input, disabled
Wants 20 bufs, needs 1, size 81920, enabled: 0, pop: 0, aligned 16
Video type is currently:
        MIME:           (null)
        Native:         (nil)
        Width:          1440
        Height:         1080
        Stride:         0
        SliceHeight:    0
        Bitrate:        0
        Framerate:      0 (0); (0.000000)
        Error hiding:   0
        Codec:          2
        Colour:         0
OMX_GetParameter(handle, OMX_IndexParamPortDefinition, portdef) completed at 215.
Port 131 is output, disabled
Wants 1 bufs, needs 1, size 2350080, enabled: 0, pop: 0, aligned 16
Video type is currently:
        MIME:           (null)
        Native:         (nil)
        Width:          1440
        Height:         1080
        Stride:         1440
        SliceHeight:    1088
        Bitrate:        0
        Framerate:      0 (0); (0.000000)
        Error hiding:   0
        Codec:          0
        Colour:         20
OMX_GetParameter(handle, OMX_IndexParamPortDefinition, portdef) completed at 215.
Port 60 is input, disabled
Wants 1 bufs, needs 1, size 10240, enabled: 0, pop: 0, aligned 16
Image type is currently:
        MIME:           (null)
        Native:         (nil)
        Width:          160
        Height:         16
        Stride:         640
        SliceHeight:    16
        Error hiding:   0
        Codec:          0
        Colour:         2130706433
OMX_GetParameter(handle, OMX_IndexParamPortDefinition, portdef) completed at 215.
Port 61 is output, disabled
Wants 1 bufs, needs 1, size 10240, enabled: 0, pop: 0, aligned 16
Image type is currently:
        MIME:           (null)
        Native:         (nil)
        Width:          160
        Height:         16
        Stride:         640
        SliceHeight:    16
        Error hiding:   0
        Codec:          0
        Colour:         2130706433
OMX_GetParameter(handle, OMX_IndexParamPortDefinition, portdef) completed at 215.
Port 200 is input, disabled
Wants 1 bufs, needs 1, size 15360, enabled: 0, pop: 0, aligned 16
Video type is currently:
        MIME:           (null)
        Native:         (nil)
        Width:          160
        Height:         64
        Stride:         160
        SliceHeight:    64
        Bitrate:        0
        Framerate:      1966080 (1e0000); (30.000000)
        Error hiding:   0
        Codec:          0
        Colour:         20
OMX_GetParameter(handle, OMX_IndexParamPortDefinition, portdef) completed at 215.
Port 201 is output, disabled
Wants 1 bufs, needs 1, size 65536, enabled: 0, pop: 0, aligned 16
Video type is currently:
        MIME:           (null)
        Native:         (nil)
        Width:          160
        Height:         64
        Stride:         160
        SliceHeight:    64
        Bitrate:        0
        Framerate:      1966080 (1e0000); (30.000000)
        Error hiding:   0
        Codec:          4
        Colour:         0
OMX_SendCommand(dec, OMX_CommandStateSet, OMX_StateIdle, NULL) completed at 1514.
OMX_SendCommand(rsz, OMX_CommandStateSet, OMX_StateIdle, NULL) completed at 1517.
OMX_GetParameter(h, OMX_IndexParamPortDefinition, portdef) completed at 724.
OMX_SendCommand(h, OMX_CommandPortEnable, port, NULL) completed at 727.
Allocated a buffer of 81920 bytes
OMX_UseBuffer(h, end, port, NULL, portdef->nBufferSize, buf) completed at 737.
Allocated a buffer of 81920 bytes
OMX_UseBuffer(h, end, port, NULL, portdef->nBufferSize, buf) completed at 737.
Allocated a buffer of 81920 bytes
OMX_UseBuffer(h, end, port, NULL, portdef->nBufferSize, buf) completed at 737.
Allocated a buffer of 81920 bytes
OMX_UseBuffer(h, end, port, NULL, portdef->nBufferSize, buf) completed at 737.
Allocated a buffer of 81920 bytes
OMX_UseBuffer(h, end, port, NULL, portdef->nBufferSize, buf) completed at 737.
Allocated a buffer of 81920 bytes
OMX_UseBuffer(h, end, port, NULL, portdef->nBufferSize, buf) completed at 737.
Allocated a buffer of 81920 bytes
OMX_UseBuffer(h, end, port, NULL, portdef->nBufferSize, buf) completed at 737.
Allocated a buffer of 81920 bytes
OMX_UseBuffer(h, end, port, NULL, portdef->nBufferSize, buf) completed at 737.
Allocated a buffer of 81920 bytes
OMX_UseBuffer(h, end, port, NULL, portdef->nBufferSize, buf) completed at 737.
Allocated a buffer of 81920 bytes
OMX_UseBuffer(h, end, port, NULL, portdef->nBufferSize, buf) completed at 737.
Allocated a buffer of 81920 bytes
OMX_UseBuffer(h, end, port, NULL, portdef->nBufferSize, buf) completed at 737.
Allocated a buffer of 81920 bytes
OMX_UseBuffer(h, end, port, NULL, portdef->nBufferSize, buf) completed at 737.
Allocated a buffer of 81920 bytes
OMX_UseBuffer(h, end, port, NULL, portdef->nBufferSize, buf) completed at 737.
Allocated a buffer of 81920 bytes
OMX_UseBuffer(h, end, port, NULL, portdef->nBufferSize, buf) completed at 737.
Allocated a buffer of 81920 bytes
OMX_UseBuffer(h, end, port, NULL, portdef->nBufferSize, buf) completed at 737.
Allocated a buffer of 81920 bytes
OMX_UseBuffer(h, end, port, NULL, portdef->nBufferSize, buf) completed at 737.
Allocated a buffer of 81920 bytes
OMX_UseBuffer(h, end, port, NULL, portdef->nBufferSize, buf) completed at 737.
Allocated a buffer of 81920 bytes
OMX_UseBuffer(h, end, port, NULL, portdef->nBufferSize, buf) completed at 737.
Allocated a buffer of 81920 bytes
OMX_UseBuffer(h, end, port, NULL, portdef->nBufferSize, buf) completed at 737.
Allocated a buffer of 81920 bytes
OMX_UseBuffer(h, end, port, NULL, portdef->nBufferSize, buf) completed at 737.
OMX_SendCommand(dec, OMX_CommandStateSet, OMX_StateExecuting, NULL) completed at 1525.
Decoder 0x1e22638 port 131 settings changed.
OMX_GetParameter(handle, OMX_IndexParamPortDefinition, portdef) completed at 215.
Port 131 is output, disabled
Wants 1 bufs, needs 1, size 2350080, enabled: 0, pop: 0, aligned 16
Video type is currently:
        MIME:           (null)
        Native:         (nil)
        Width:          1440
        Height:         1080
        Stride:         1440
        SliceHeight:    1088
        Bitrate:        0
        Framerate:      1964115 (1df853); (29.970016)
        Error hiding:   0
        Codec:          0
        Colour:         20
Decoder has changed settings.  Setting up encoder.
OMX_GetParameter(dec, OMX_IndexParamPortDefinition, portdef) completed at 861.
OMX_SendCommand(dei, OMX_CommandStateSet, OMX_StateIdle, NULL) completed at 866.
OMX_SendCommand(dei, OMX_CommandPortDisable, PORT_DEI, NULL) completed at 869.
OMX_SendCommand(dei, OMX_CommandPortDisable, PORT_DEI+1, NULL) completed at 871.
OMX_SetParameter(dei, OMX_IndexParamPortDefinition, portdef) completed at 873.
OMX_SetParameter(dei, OMX_IndexParamPortDefinition, portdef) completed at 876.
OMX_SetParameter(prev, OMX_IndexParamBrcmExtraBuffers, extra_buffers) completed at 882.
OMX_SetConfig(dei, OMX_IndexConfigCommonImageFilterParameters, image_filter) completed at 889.
OMX_GetParameter(dei, OMX_IndexParamPortDefinition, imgportdef) completed at 893.
OMX_GetParameter(handle, OMX_IndexParamPortDefinition, portdef) completed at 215.
Port 190 is input, disabled
Wants 1 bufs, needs 1, size 2350080, enabled: 0, pop: 0, aligned 16
Image type is currently:
        MIME:           (null)
        Native:         (nil)
        Width:          1440
        Height:         1080
        Stride:         1440
        SliceHeight:    1088
        Error hiding:   0
        Codec:          0
        Colour:         20
OMX_GetParameter(handle, OMX_IndexParamPortDefinition, portdef) completed at 215.
Port 191 is output, disabled
Wants 1 bufs, needs 1, size 2350080, enabled: 0, pop: 0, aligned 16
Image type is currently:
        MIME:           (null)
        Native:         (nil)
        Width:          1440
        Height:         1080
        Stride:         1440
        SliceHeight:    1088
        Error hiding:   0
        Codec:          0
        Colour:         20
OMX_SetupTunnel(prev, pp, dei, PORT_DEI) completed at 908.
OMX_GetParameter(rsz, OMX_IndexParamPortDefinition, imgportdef) completed at 916.
OMX_SetParameter(rsz, OMX_IndexParamPortDefinition, imgportdef) completed at 930.
Frame size: 960x544, scale factor 960
OMX_SetParameter(rsz, OMX_IndexParamPortDefinition, imgportdef) completed at 954.
OMX_GetParameter(rsz, OMX_IndexParamPortDefinition, imgportdef) completed at 957.
OMX_SetParameter(enc, OMX_IndexParamPortDefinition, portdef) completed at 971.
OMX_SetupTunnel(prev, pp, rsz, PORT_RSZ) completed at 997.
OMX_SendCommand(enc, OMX_CommandStateSet, OMX_StateIdle, NULL) completed at 1001.
OMX_GetParameter(handle, OMX_IndexParamPortDefinition, portdef) completed at 215.
Port 61 is output, disabled
Wants 1 bufs, needs 1, size 783360, enabled: 0, pop: 0, aligned 16
Image type is currently:
        MIME:           (null)
        Native:         (nil)
        Width:          960
        Height:         544
        Stride:         960
        SliceHeight:    544
        Error hiding:   0
        Codec:          0
        Colour:         20
OMX_GetParameter(handle, OMX_IndexParamPortDefinition, portdef) completed at 215.
Port 200 is input, disabled
Wants 1 bufs, needs 1, size 2350080, enabled: 0, pop: 0, aligned 16
Video type is currently:
        MIME:           (null)
        Native:         (nil)
        Width:          960
        Height:         544
        Stride:         960
        SliceHeight:    544
        Bitrate:        0
        Framerate:      1964115 (1df853); (29.970016)
        Error hiding:   0
        Codec:          0
        Colour:         20
OMX_SetupTunnel(prev, pp, enc, PORT_ENC) completed at 1004.
OMX_SetParameter(enc, OMX_IndexParamPortDefinition, portdef) completed at 1020.
OMX_SetParameter(enc, OMX_IndexParamVideoBitrate, bitrate) completed at 1026.
OMX_SetParameter(enc, OMX_IndexParamVideoPortFormat, pfmt) completed at 1048.
OMX_SetParameter(enc, OMX_IndexConfigVideoFramerate, framerate) completed at 1053.
OMX_GetParameter(enc, OMX_IndexParamVideoProfileLevelCurrent, level) completed at 1069.
Current level:          2048
Current profile:        8
OMX_SetParameter(enc, OMX_IndexParamVideoProfileLevelCurrent, level) completed at 1073.
OMX_GetParameter(h, OMX_IndexParamPortDefinition, portdef) completed at 724.
OMX_SendCommand(h, OMX_CommandPortEnable, port, NULL) completed at 727.
Allocated a buffer of 2350080 bytes
OMX_UseBuffer(h, end, port, NULL, portdef->nBufferSize, buf) completed at 737.
OMX_SendCommand(dec, OMX_CommandPortEnable, PORT_DEC+1, NULL) completed at 1076.
Resizer 0x1e1b9f0 port 61 settings changed.
OMX_GetParameter(handle, OMX_IndexParamPortDefinition, portdef) completed at 215.
Port 61 is output, disabled
Wants 1 bufs, needs 1, size 783360, enabled: 0, pop: 0, aligned 16
Image type is currently:
        MIME:           (null)
        Native:         (nil)
        Width:          960
        Height:         544
        Stride:         960
        SliceHeight:    544
        Error hiding:   0
        Codec:          0
        Colour:         20
OMX_SendCommand(rsz, OMX_CommandPortEnable, PORT_RSZ, NULL) completed at 1079.
OMX_SendCommand(rsz, OMX_CommandPortEnable, PORT_RSZ+1, NULL) completed at 1081.
OMX_SendCommand(enc, OMX_CommandPortEnable, PORT_ENC, NULL) completed at 1084.
Unknown! 0x1e1bac0 port 191 settings changed.
OMX_GetParameter(handle, OMX_IndexParamPortDefinition, portdef) completed at 215.
Port 191 is output, disabled
Wants 0 bufs, needs 0, size 2350080, enabled: 0, pop: 1, aligned 16
Image type is currently:
        MIME:           (null)
        Native:         (nil)
        Width:          1440
        Height:         1080
        Stride:         1440
        SliceHeight:    1088
        Error hiding:   0
        Codec:          0
        Colour:         20
OMX_SendCommand(dei, OMX_CommandPortEnable, PORT_DEI, NULL) completed at 1107.
OMX_SendCommand(dei, OMX_CommandPortEnable, PORT_DEI+1, NULL) completed at 1109.
OMX_GetParameter(handle, OMX_IndexParamPortDefinition, portdef) completed at 215.
Port 190 is input, enabled
Wants 0 bufs, needs 0, size 2350080, enabled: 1, pop: 1, aligned 16
Image type is currently:
        MIME:           (null)
        Native:         (nil)
        Width:          1440
        Height:         1080
        Stride:         1440
        SliceHeight:    1088
        Error hiding:   0
        Codec:          0
        Colour:         20
OMX_GetParameter(handle, OMX_IndexParamPortDefinition, portdef) completed at 215.
Port 191 is output, enabled
Wants 0 bufs, needs 0, size 2350080, enabled: 1, pop: 1, aligned 16
Image type is currently:
        MIME:           (null)
        Native:         (nil)
        Width:          1440
        Height:         1080
        Stride:         1440
        SliceHeight:    1088
        Error hiding:   0
        Codec:          0
        Colour:         20
OMX_SendCommand(dei, OMX_CommandStateSet, OMX_StateExecuting, NULL) completed at 1115.
OMX_SendCommand(rsz, OMX_CommandStateSet, OMX_StateExecuting, NULL) completed at 1120.
OMX_SendCommand(enc, OMX_CommandStateSet, OMX_StateExecuting, NULL) completed at 1122.
Encoder 0x1e1b920 port 201 settings changed.
OMX_GetParameter(handle, OMX_IndexParamPortDefinition, portdef) completed at 215.
Port 201 is output, enabled
Wants 1 bufs, needs 1, size 2350080, enabled: 1, pop: 1, aligned 16
Video type is currently:
        MIME:           (null)
        Native:         (nil)
        Width:          960
        Height:         544
        Stride:         0
        SliceHeight:    0
        Bitrate:        2097152
        Framerate:      1964115 (1df853); (29.970016)
        Error hiding:   0
        Codec:          7
        Colour:         0
OMX_FillThisBuffer(enc, encbufs) completed at 1124.
OMX_GetParameter(handle, OMX_IndexParamPortDefinition, portdef) completed at 215.
Port 130 is input, enabled
Wants 20 bufs, needs 1, size 81920, enabled: 1, pop: 1, aligned 16
Video type is currently:
        MIME:           (null)
        Native:         (nil)
        Width:          1440
        Height:         1080
        Stride:         0
        SliceHeight:    0
        Bitrate:        0
        Framerate:      0 (0); (0.000000)
        Error hiding:   0
        Codec:          2
        Colour:         0
OMX_GetParameter(handle, OMX_IndexParamPortDefinition, portdef) completed at 215.
Port 131 is output, enabled
Wants 0 bufs, needs 0, size 2350080, enabled: 1, pop: 1, aligned 16
Video type is currently:
        MIME:           (null)
        Native:         (nil)
        Width:          1440
        Height:         1080
        Stride:         1440
        SliceHeight:    1088
        Bitrate:        0
        Framerate:      1964115 (1df853); (29.970016)
        Error hiding:   0
        Codec:          0
        Colour:         20
OMX_GetParameter(handle, OMX_IndexParamPortDefinition, portdef) completed at 215.
Port 60 is input, enabled
Wants 0 bufs, needs 0, size 2350080, enabled: 1, pop: 1, aligned 16
Image type is currently:
        MIME:           (null)
        Native:         (nil)
        Width:          1440
        Height:         1080
        Stride:         1440
        SliceHeight:    1088
        Error hiding:   0
        Codec:          0
        Colour:         20
OMX_GetParameter(handle, OMX_IndexParamPortDefinition, portdef) completed at 215.
Port 61 is output, enabled
Wants 1 bufs, needs 1, size 783360, enabled: 1, pop: 1, aligned 16
Image type is currently:
        MIME:           (null)
        Native:         (nil)
        Width:          960
        Height:         544
        Stride:         960
        SliceHeight:    544
        Error hiding:   0
        Codec:          0
        Colour:         20
OMX_GetParameter(handle, OMX_IndexParamPortDefinition, portdef) completed at 215.
Port 200 is input, enabled
Wants 1 bufs, needs 1, size 783360, enabled: 1, pop: 1, aligned 16
Video type is currently:
        MIME:           (null)
        Native:         (nil)
        Width:          960
        Height:         544
        Stride:         960
        SliceHeight:    544
        Bitrate:        0
        Framerate:      0 (0); (0.000000)
        Error hiding:   0
        Codec:          0
        Colour:         20
OMX_GetParameter(handle, OMX_IndexParamPortDefinition, portdef) completed at 215.
Port 201 is output, enabled
Wants 1 bufs, needs 1, size 2350080, enabled: 1, pop: 1, aligned 16
Video type is currently:
        MIME:           (null)
        Native:         (nil)
        Width:          960
        Height:         544
        Stride:         0
        SliceHeight:    0
        Bitrate:        2097152
        Framerate:      1964115 (1df853); (29.970016)
        Error hiding:   0
        Codec:          7
        Colour:         0
Found a codec at 0xb68b5ffc
Defaults: output stream: 1/90000, input stream: 1/25, input codec: 1001/60000, output codec: 0/1, output framerate: 0/0, input framerate: 25/1, ticks: 1; 2 -9223372036854775808/0
Defaults: output stream: 1/90000, input stream: 1/25, input codec: 1001/60000, output codec: 1001/60000, output framerate: 25/1, input framerate: 25/1
Time base: 1/90000, fps 25/1



Input:
Input #0, mpegvideo, from 'tes.track_273.m2v':
  Duration: 00:00:06.16, bitrate: 24057 kb/s
    Stream #0.0: Video: mpeg2video (Main), yuv420p, 1440x1080 [PAR 4:3 DAR 16:9], 24000 kb/s, 25 fps, 25 tbr, 25 tbn, 59.94 tbc



Output:
Output #0, mp4, to 'aaa.mp4':
    Stream #0.0: Video: libx264, 960x544, q=-1--1, 2097 kb/s, 25 fps, 25 tbr, 90k tbn, 59.94 tbc
New SPS, length 18
New PPS, length 9
Writing initial frame buffer contents out... ...done.  Wrote 0 frames.

[mp4 @ 0x1e21a80] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 76800 >= 76800
Failed to write a video frame: Invalid argument (78802, 133d2; 1313367 0) 410.
[mp4 @ 0x1e21a80] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 78802 >= 78802
Failed to write a video frame: Invalid argument (79803, 137bb; 1330050 0) 410.
[mp4 @ 0x1e21a80] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 86002 >= 86002
Failed to write a video frame: Invalid argument (87003, 153db; 1450050 0) 410.
[mp4 @ 0x1e21a80] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 90006 >= 90006
Failed to write a video frame: Invalid argument (91007, 1637f; 1516784 0) 410.
[mp4 @ 0x1e21a80] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 100016 >= 100016
Failed to write a video frame: Invalid argument (101017, 18a99; 1683619 0) 410.
[mp4 @ 0x1e21a80] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 119035 >= 119035
Failed to write a video frame: Invalid argument (120036, 1d4e4; 2000606 0) 410.
[mp4 @ 0x1e21a80] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 183401 >= 183401
Failed to write a video frame: Invalid argument (184800, 2d1e0; 3080000 0) 410.
[mp4 @ 0x1e21a80] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 219401 >= 219401
Failed to write a video frame: Invalid argument (220800, 35e80; 3680000 0) 410.
[mp4 @ 0x1e21a80] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 267003 >= 267003
Failed to write a video frame: Invalid argument (268800, 41a00; 4480000 0) 410.
[mp4 @ 0x1e21a80] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 337423 >= 337423
Failed to write a video frame: Invalid argument (338424, 529f8; 5640404 0) 410.
[mp4 @ 0x1e21a80] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 418505 >= 418505
Failed to write a video frame: Invalid argument (419506, 666b2; 6991767 0) 410.
[mp4 @ 0x1e21a80] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 664800 >= 664800
Failed to write a video frame: Invalid argument (667200, a2e40; 11120000 0) 410.
[mp4 @ 0x1e21a80] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 667200 >= 667200
Failed to write a video frame: Invalid argument (668201, a3229; 11136683 0) 410.
[mp4 @ 0x1e21a80] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 676402 >= 676402
Failed to write a video frame: Invalid argument (677403, a561b; 11290050 0) 410.
Processed 327 frames in 12 seconds; 27f/s




In exit handler, after 327 frames:
OMX_GetParameter(handle, OMX_IndexParamPortDefinition, portdef) completed at 215.
Port 130 is input, enabled
Wants 20 bufs, needs 1, size 81920, enabled: 1, pop: 1, aligned 16
Video type is currently:
        MIME:           (null)
        Native:         (nil)
        Width:          1440
        Height:         1080
        Stride:         0
        SliceHeight:    0
        Bitrate:        0
        Framerate:      0 (0); (0.000000)
        Error hiding:   0
        Codec:          2
        Colour:         0
OMX_GetParameter(handle, OMX_IndexParamPortDefinition, portdef) completed at 215.
Port 131 is output, enabled
Wants 0 bufs, needs 0, size 2350080, enabled: 1, pop: 1, aligned 16
Video type is currently:
        MIME:           (null)
        Native:         (nil)
        Width:          1440
        Height:         1080
        Stride:         1440
        SliceHeight:    1088
        Bitrate:        0
        Framerate:      1964115 (1df853); (29.970016)
        Error hiding:   0
        Codec:          0
        Colour:         20
OMX_GetParameter(handle, OMX_IndexParamPortDefinition, portdef) completed at 215.
Port 200 is input, enabled
Wants 1 bufs, needs 1, size 783360, enabled: 1, pop: 1, aligned 16
Video type is currently:
        MIME:           (null)
        Native:         (nil)
        Width:          960
        Height:         544
        Stride:         960
        SliceHeight:    544
        Bitrate:        0
        Framerate:      0 (0); (0.000000)
        Error hiding:   0
        Codec:          0
        Colour:         20
OMX_GetParameter(handle, OMX_IndexParamPortDefinition, portdef) completed at 215.
Port 201 is output, enabled
Wants 1 bufs, needs 1, size 2350080, enabled: 1, pop: 1, aligned 16
Video type is currently:
        MIME:           (null)
        Native:         (nil)
        Width:          960
        Height:         544
        Stride:         0
        SliceHeight:    0
        Bitrate:        2097152
        Framerate:      1964115 (1df853); (29.970016)
        Error hiding:   0
        Codec:          7
        Colour:         0
Decoder state: 3
Encoder state: 3

何か進展があれば、書き足していく予定です。

2014年12月5日金曜日

RaspberryPiでMpeg2→Mpeg4へトランスコードする・続2


前回の続き、
http://ivis-mynikki.blogspot.jp/2014/11/rasberry-pimpeg2mpeg4.html

omxtxをmakeするとき、ライブラリが足りないものはaptitudeで調べて ***-devをインストール。
リンカエラーが出たら LIBS=-lavcodec など追加していくとビルドが通る。

テストデータをMP4化してみてchromebookで再生できるかと思ったら再生できなかったが、
出来上がったMP4動画ファイルに音声ファイルを結合すると再生できた。
でも画質が悪い。一昔のVHS映像並。なんでだろう。


ビットレートの設定が反映されてないような気がするので
ソースを見てみる。

まずはMain関数から。
引数を展開して、Init処理から始まる。
 
動画ファイルをオープンして、
 vidindex = av_find_best_stream(ic, AVMEDIA_TYPE_VIDEO, -1, -1,
                NULL, 0);


Mpeg2デコード、Mpeg4エンコード、リサイズ設定して、、
        bcm_host_init();
        OERR(OMX_Init(), ctx.verbose);
        OERR(OMX_GetHandle(&m2, DECNAME, &ctx, &decevents), ctx.verbose);
        OERR(OMX_GetHandle(&m4, ENCNAME, &ctx, &encevents), ctx.verbose);
        OERR(OMX_GetHandle(&resize, RESIZENAME, &ctx, &resizeevents), ctx.verbose);


OpenMAXにパラメータ送信して、
         OERR(OMX_GetParameter(m2, OMX_IndexParamVideoInit, porttype), ctx.verbose);
        if (ctx.verbose) printf("Found %d ports, starting at %d (%x) on decoder\n",
                porttype->nPorts, porttype->nStartPortNumber,
                porttype->nStartPortNumber);
        ctx.decportidx = decportidx = porttype->nStartPortNumber;

        OERR(OMX_GetParameter(resize, OMX_IndexParamImageInit, porttype), ctx.verbose);
        if (ctx.verbose) printf("Found %d ports, starting at %d (%x) on resizer\n",
                porttype->nPorts, porttype->nStartPortNumber,
                porttype->nStartPortNumber);
        ctx.resizeportidx = resizeportidx = porttype->nStartPortNumber;

        OERR(OMX_GetParameter(m4, OMX_IndexParamVideoInit, porttype), ctx.verbose);
        if (ctx.verbose) printf("Found %d ports, starting at %d (%x) on encoder\n",
                porttype->nPorts, porttype->nStartPortNumber,
                porttype->nStartPortNumber);
        ctx.encportidx = encportidx = porttype->nStartPortNumber;
        free(porttype);

        OERR(OMX_SendCommand(m2, OMX_CommandPortDisable, decportidx, NULL), ctx.verbose);
        OERR(OMX_SendCommand(m2, OMX_CommandPortDisable, decportidx+1, NULL), ctx.verbose);
        OERR(OMX_SendCommand(resize, OMX_CommandPortDisable, resizeportidx, NULL), ctx.verbose);
        OERR(OMX_SendCommand(resize, OMX_CommandPortDisable, resizeportidx+1, NULL), ctx.verbose);
        OERR(OMX_SendCommand(m4, OMX_CommandPortDisable, encportidx, NULL), ctx.verbose);
        OERR(OMX_SendCommand(m4, OMX_CommandPortDisable, encportidx+1, NULL), ctx.verbose);


処理開始。
    OERR(OMX_SendCommand(m2, OMX_CommandStateSet, OMX_StateExecuting, NULL), ctx.verbose);

ビットレートの設定が無いなって思ったら、実行処理の中にある
DECTUNNELSETUP内のconfigure関数で行っているようだった。

これであってるのか分からないが。。
1つ気づいたのはデインターレース処理が入ってないなって思ったので、
対応したomxtxが調べてみたらありました。

Dickon hood氏が2013年に対応してくださっていたようだ。
 * (c) 2012, 2013 Dickon Hood
 * Timing fixups by Adam Charrett
 *
 * A trivial OpenMAX transcoder for the Pi.
 *
 * Very much a work-in-progress, and as such is noisy, doesn't produce
 * particularly pretty output, and is probably buggier than a swamp in
 * summer.  Beware of memory leaks.
 *
 * Usage: ./omxtx [-b bitrate] [-r size] [-x] [-d] [-m] input.foo output.mp4


でも今ビルドしたものはArjen氏が改造したもの。
 * (c) 2012 Dickon Hood
 * modified dec 2012 by Arjen V
 * Added resizer functionality
 * Added pixelaspectratio (hardware)
 *
 * A trivial OpenMAX transcoder for the Pi.
 *
 * Very much a work-in-progress, and as such is noisy, doesn't produce
 * particularly pretty output, and is probably buggier than a swamp in
 * summer.  Beware of memory leaks.
 *
 * Usage: ./omxtx [-v] [-b bitrate] [-s WxH] input.foo output.m4v


追加内容を見ると、
<Deckon氏>
    pixaspect->nPortIndex = PORT_ENC+1;
    pixaspect->nX = 64;
    pixaspect->nY = 45;
//    OERR(OMX_SetParameter(dec, OMX_IndexParamBrcmPixelAspectRatio, pixaspect));


 <Arien氏>
       pixaspect->nPortIndex = encportidx+1;
        pixaspect->nX = 118;
        pixaspect->nY = 81;
        OERR(OMX_SetConfig(m4, OMX_IndexParamBrcmPixelAspectRatio, pixaspect), ctx->verbose);
        free(pixaspect);


 少し設定値が違うようだけど、Deckon氏の早く気づいておけばよかった。。

今日はここまで。


次回は最新版のomxtxでビットレートの設定が正しくなっているか、

またはデコード・エンコードの仕方を見直し?を行う。




Androider