
Estoy atascado al intentar convertir una serie de archivos .pgm de 16 bits en un video usando ffmepg. Los archivos en sí son todos archivos pgm válidos y se denominan
0.pgm 1.pgm 2.pgm ...
Las fotografías se tomaron a una velocidad de cuadros de ~1 fps y quiero que el video resultante sea en tiempo real (un cuadro = 1 segundo).
he usadoffmpeg -r 1 -i %d.pgm -pix_fmt yuv420p output.mp4
Se crea el archivo de salida, pero el vídeo solo muestra píxeles negros (excepto algunos grises en la esquina superior derecha). Tanto en Windows Media Player como usando ffplay
.
Aquí está el resultado completo de la consola que recibo:
File 'output.mp4' already exists. Overwrite ? [y/N] y
Stream mapping:
Stream #0:0 -> #0:0 (pgm (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[libx264 @ 0000027f39775c80] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0000027f39775c80] profile High, level 2.2
[libx264 @ 0000027f39775c80] 264 - core 155 r2901 7d0ff22 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=15 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=1 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'output.mp4':
Metadata:
encoder : Lavf58.10.100
Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 640x480, q=-1--1, 1 fps, 16384 tbn, 1 tbc
Metadata:
encoder : Lavc58.13.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
frame= 549 fps=109 q=-1.0 Lsize= 503kB time=00:09:06.00 bitrate= 7.6kbits/s speed= 109x
video:496kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.459769%
[libx264 @ 0000027f39775c80] frame I:3 Avg QP: 2.81 size: 34676
[libx264 @ 0000027f39775c80] frame P:139 Avg QP: 4.47 size: 1849
[libx264 @ 0000027f39775c80] frame B:407 Avg QP:14.75 size: 359
[libx264 @ 0000027f39775c80] consecutive B-frames: 1.1% 0.0% 0.5% 98.4%
[libx264 @ 0000027f39775c80] mb I I16..4: 20.2% 79.1% 0.6%
[libx264 @ 0000027f39775c80] mb P I16..4: 0.0% 1.3% 0.0% P16..4: 19.2% 0.7% 1.6% 0.0% 0.0% skip:77.1%
[libx264 @ 0000027f39775c80] mb B I16..4: 0.0% 0.0% 0.0% B16..8: 10.2% 0.5% 0.3% direct: 0.3% skip:88.7% L0:34.6% L1:64.1% BI: 1.2%
[libx264 @ 0000027f39775c80] 8x8 transform intra:85.7% inter:66.0%
[libx264 @ 0000027f39775c80] coded y,uvDC,uvAC intra: 83.8% 89.0% 88.8% inter: 2.1% 0.3% 0.2%
[libx264 @ 0000027f39775c80] i16 v,h,dc,p: 54% 20% 24% 2%
[libx264 @ 0000027f39775c80] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 23% 16% 59% 1% 0% 0% 0% 0% 0%
[libx264 @ 0000027f39775c80] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 9% 23% 35% 4% 9% 4% 9% 2% 6%
[libx264 @ 0000027f39775c80] i8c dc,h,v,p: 43% 29% 27% 2%
[libx264 @ 0000027f39775c80] Weighted P-Frames: Y:2.9% UV:0.0%
[libx264 @ 0000027f39775c80] ref P L0: 84.0% 0.1% 9.8% 6.0% 0.1%
[libx264 @ 0000027f39775c80] ref B L0: 73.4% 22.6% 4.0%
[libx264 @ 0000027f39775c80] ref B L1: 85.3% 14.7%
[libx264 @ 0000027f39775c80] kb/s:7.39
Toda ayuda es apreciada y gracias de antemano.
Saludos
Respuesta1
Perdón por una respuesta tardía.
No he respondido a los comentarios porque la respuesta la encontré yo mismo. El error radica en las convenciones del encabezado del archivo pgm. Aparentemente, ffmpeg solo maneja correctamente archivos P5 (aquellos que tienen una codificación binaria para píxeles). Sin embargo, mis archivos eran P2, los que tienen codificación ASCII.
La solución más sencilla que encontré fue convertir las imágenes a formato png y luego usar ffmpg en ellas.
Gracias por tu ayuda y saludos.
León