将视频从 jpg 转换为 Android 设备后无法播放

将视频从 jpg 转换为 Android 设备后无法播放

我想将照片 ( .jpg) 转换为电影 ( .mp4)。持续时间为 6 秒。没有任何声音。

作为我正在使用的依赖项

https://github.com/bravobit/FFmpeg-Android

测试于

三星 Note 8(Android 9)

命令:

ffmpeg -i <INPUT> -vf scale=1920:-2:force_original_aspect_ratio=decrease,format=yuv420p -c:v libx264 -r 1/6 -t 6 <OUTPUT>

我也尝试添加:

  • -movflags faststart
  • -preset slow
  • -vprofile baseline
  • -profile:v high

但效果是一样的。

结果

  • 视频已创建(具有适当的尺寸、比例和持续时间)。

  • 我可以不是在手机上播放(使用原生播放器和 VLC)。只需眨眼并关闭即可。

  • 当我分享视频到 Instagram 等平台时,它可以正常工作。

  • 当我将它传输到计算机(macOS)时,它可以正常工作。

屏幕记录

https://i.imgur.com/LFqvpAA.mp4

完整控制台日志

ffmpeg version n4.0-39-gda39990 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 4.9.x (GCC) 20150123 (prerelease)
configuration: --target-os=linux --cross-prefix=/root/bravobit/ffmpeg-android/toolchain-android/bin/arm-linux-androideabi- --arch=arm --cpu=cortex-a8 --enable-runtime-cpudetect --sysroot=/root/bravobit/ffmpeg-android/toolchain-android/sysroot --enable-pic --enable-libx264 --enable-ffprobe --enable-libopus --enable-libvorbis --enable-libfdk-aac --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-fontconfig --enable-libvpx --enable-libass --enable-yasm --enable-pthreads --disable-debug --enable-version3 --enable-hardcoded-tables --disable-ffplay --disable-linux-perf --disable-doc --disable-shared --enable-static --enable-runtime-cpudetect --enable-nonfree --enable-network --enable-avresample --enable-avformat --enable-avcodec --enable-indev=lavfi --enable-hwaccels --enable-ffmpeg --enable-zlib --enable-gpl --enable-small --enable-nonfree --pkg-config=pkg-config --pkg-config-flags=--static --prefix=/root/bravobit/ffmpeg-android/build/armeabi-v7a --extra-cflags='-I/root/bravobit/ffmpeg-android/toolchain-android/include -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all' --extra-ldflags='-L/root/bravobit/ffmpeg-android/toolchain-android/lib -Wl,-z,relro -Wl,-z,now -pie' --extra-cxxflags=
libavutil      56. 14.100 / 56. 14.100
libavcodec     58. 18.100 / 58. 18.100
libavformat    58. 12.100 / 58. 12.100
libavdevice    58.  3.100 / 58.  3.100
libavfilter     7. 16.100 /  7. 16.100
libavresample   4.  0.  0 /  4.  0.  0
libswscale      5.  1.100 /  5.  1.100
libswresample   3.  1.100 /  3.  1.100
libpostproc    55.  1.100 / 55.  1.100
Splitting the commandline.
Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument 'debug'.
Reading option '-i' ... matched as input url with argument '<FILE_URI>'.
Reading option '-vf' ... matched as option 'vf' (set video filters) with argument 'scale=1920:-2:force_original_aspect_ratio=decrease,format=yuv420p'.
Reading option '-c:v' ... matched as option 'c' (codec name) with argument 'libx264'.
Reading option '-r' ... matched as option 'r' (set frame rate (Hz value, fraction or abbreviation)) with argument '1/6'.
Reading option '-t' ... matched as option 't' (record or transcode "duration" seconds of audio/video) with argument '6'.
Reading option '<FILE_URI>' ... matched as output url.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option loglevel (set logging level) with argument debug.
Successfully parsed a group of options.
Parsing a group of options: input url <FILE_URI>
Successfully parsed a group of options.
Opening an input file: <FILE_URI>.
[NULL @ 0xe9827000] Opening '<FILE_URI>' for reading
[file @ 0xe9837000] Setting default whitelist 'file,crypto'
[image2 @ 0xe9827000] Format image2 probed with size=2048 and score=50
[image2 @ 0xe9827000] Before avformat_find_stream_info() pos: 0 bytes read:32768 seeks:0 nb_streams:1
[mjpeg @ 0xe9863380] marker=d8 avail_size_in_buf=562289
[mjpeg @ 0xe9863380] marker parser used 0 bytes (0 bits)
[mjpeg @ 0xe9863380] marker=e0 avail_size_in_buf=562287
[mjpeg @ 0xe9863380] marker parser used 16 bytes (128 bits)
[mjpeg @ 0xe9863380] marker=db avail_size_in_buf=562269
[mjpeg @ 0xe9863380] index=0
[mjpeg @ 0xe9863380] qscale[0]: 1
[mjpeg @ 0xe9863380] marker parser used 67 bytes (536 bits)
[mjpeg @ 0xe9863380] marker=db avail_size_in_buf=562200
[mjpeg @ 0xe9863380] index=1
[mjpeg @ 0xe9863380] qscale[1]: 2
[mjpeg @ 0xe9863380] marker parser used 67 bytes (536 bits)
[mjpeg @ 0xe9863380] marker=c0 avail_size_in_buf=562131
[mjpeg @ 0xe9863380] Changing bps from 0 to 8
[mjpeg @ 0xe9863380] sof0: picture: 1429x2160
[mjpeg @ 0xe9863380] component 0 2:2 id: 0 quant:0
[mjpeg @ 0xe9863380] component 1 1:1 id: 1 quant:1
[mjpeg @ 0xe9863380] component 2 1:1 id: 2 quant:1
[mjpeg @ 0xe9863380] pix fmt id 22111100
[mjpeg @ 0xe9863380] Format yuvj420p chosen by get_format().
[mjpeg @ 0xe9863380] marker parser used 17 bytes (136 bits)
[mjpeg @ 0xe9863380] marker=c4 avail_size_in_buf=562112
[mjpeg @ 0xe9863380] marker parser used 0 bytes (0 bits)
[mjpeg @ 0xe9863380] marker=c4 avail_size_in_buf=562080
[mjpeg @ 0xe9863380] marker parser used 0 bytes (0 bits)
[mjpeg @ 0xe9863380] marker=c4 avail_size_in_buf=561991
[mjpeg @ 0xe9863380] marker parser used 0 bytes (0 bits)
[mjpeg @ 0xe9863380] marker=c4 avail_size_in_buf=561961
[mjpeg @ 0xe9863380] marker parser used 0 bytes (0 bits)
[mjpeg @ 0xe9863380] escaping removed 2053 bytes
[mjpeg @ 0xe9863380] marker=da avail_size_in_buf=561893
[mjpeg @ 0xe9863380] marker parser used 559840 bytes (4478720 bits)
[mjpeg @ 0xe9863380] marker=d9 avail_size_in_buf=0
[mjpeg @ 0xe9863380] decode frame unused 0 bytes
[image2 @ 0xe9827000] After avformat_find_stream_info() pos: 562291 bytes read:562291 seeks:0 frames:1
Input #0, image2, from '<FILE_URI>':
Duration: 00:00:00.04, start: 0.000000, bitrate: 112458 kb/s
Stream #0:0, 1, 1/25: Video: mjpeg, 1 reference frame, yuvj420p(pc, bt470bg/unknown/unknown, center), 1429x2160 [SAR 1:1 DAR 1429:2160], 0/1, 25 tbr, 25 tbn, 25 tbc
Successfully opened the file.
Parsing a group of options: output url <FILE_URI>.
Applying option vf (set video filters) with argument scale=1920:-2:force_original_aspect_ratio=decrease,format=yuv420p.
Applying option c:v (codec name) with argument libx264.
Applying option r (set frame rate (Hz value, fraction or abbreviation)) with argument 1/6.
Applying option t (record or transcode "duration" seconds of audio/video) with argument 6.
Successfully parsed a group of options.
Opening an output file: <FILE_URI>.
[file @ 0xe9813080] Setting default whitelist 'file,crypto'
Successfully opened the file.
Stream mapping:
Stream #0:0 -> #0:0 (mjpeg (native) -> h264 (libx264))
Press [q] to stop, [?] for help
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
[mjpeg @ 0xe9863700] marker=d8 avail_size_in_buf=562289
[mjpeg @ 0xe9863700] marker parser used 0 bytes (0 bits)
[mjpeg @ 0xe9863700] marker=e0 avail_size_in_buf=562287
[mjpeg @ 0xe9863700] marker parser used 16 bytes (128 bits)
[mjpeg @ 0xe9863700] marker=db avail_size_in_buf=562269
[mjpeg @ 0xe9863700] index=0
[mjpeg @ 0xe9863700] qscale[0]: 1
[mjpeg @ 0xe9863700] marker parser used 67 bytes (536 bits)
[mjpeg @ 0xe9863700] marker=db avail_size_in_buf=562200
[mjpeg @ 0xe9863700] index=1
[mjpeg @ 0xe9863700] qscale[1]: 2
[mjpeg @ 0xe9863700] marker parser used 67 bytes (536 bits)
[mjpeg @ 0xe9863700] marker=c0 avail_size_in_buf=562131
[mjpeg @ 0xe9863700] sof0: picture: 1429x2160
[mjpeg @ 0xe9863700] component 0 2:2 id: 0 quant:0
[mjpeg @ 0xe9863700] component 1 1:1 id: 1 quant:1
[mjpeg @ 0xe9863700] component 2 1:1 id: 2 quant:1
[mjpeg @ 0xe9863700] pix fmt id 22111100
[mjpeg @ 0xe9863700] Format yuvj420p chosen by get_format().
[mjpeg @ 0xe9863700] marker parser used 17 bytes (136 bits)
[mjpeg @ 0xe9863700] marker=c4 avail_size_in_buf=562112
[mjpeg @ 0xe9863700] class=0 index=0 nb_codes=11
[mjpeg @ 0xe9863700] marker parser used 30 bytes (240 bits)
[mjpeg @ 0xe9863700] marker=c4 avail_size_in_buf=562080
[mjpeg @ 0xe9863700] class=1 index=0 nb_codes=242
[mjpeg @ 0xe9863700] marker parser used 87 bytes (696 bits)
[mjpeg @ 0xe9863700] marker=c4 avail_size_in_buf=561991
[mjpeg @ 0xe9863700] class=0 index=1 nb_codes=9
[mjpeg @ 0xe9863700] marker parser used 28 bytes (224 bits)
[mjpeg @ 0xe9863700] marker=c4 avail_size_in_buf=561961
[mjpeg @ 0xe9863700] class=1 index=1 nb_codes=242
[mjpeg @ 0xe9863700] marker parser used 66 bytes (528 bits)
[mjpeg @ 0xe9863700] escaping removed 2053 bytes
[mjpeg @ 0xe9863700] marker=da avail_size_in_buf=561893
[mjpeg @ 0xe9863700] component: 0
[mjpeg @ 0xe9863700] component: 1
[mjpeg @ 0xe9863700] component: 2
[mjpeg @ 0xe9863700] marker parser used 559839 bytes (4478705 bits)
[mjpeg @ 0xe9863700] marker=d9 avail_size_in_buf=0
[mjpeg @ 0xe9863700] decode frame unused 0 bytes
detected 8 logical cores
[Parsed_scale_0 @ 0xe9834120] Setting 'w' to value '1920'
[Parsed_scale_0 @ 0xe9834120] Setting 'h' to value '-2'
[Parsed_scale_0 @ 0xe9834120] Setting 'force_original_aspect_ratio' to value 'decrease'
[Parsed_scale_0 @ 0xe9834120] Setting 'flags' to value 'bicubic'
[Parsed_scale_0 @ 0xe9834120] w:1920 h:-2 flags:'bicubic' interl:0
[Parsed_format_1 @ 0xe9834180] Setting 'pix_fmts' to value 'yuv420p'
[graph 0 input from stream 0:0 @ 0xe98341e0] Setting 'video_size' to value '1429x2160'
[graph 0 input from stream 0:0 @ 0xe98341e0] Setting 'pix_fmt' to value '12'
[graph 0 input from stream 0:0 @ 0xe98341e0] Setting 'time_base' to value '1/25'
[graph 0 input from stream 0:0 @ 0xe98341e0] Setting 'pixel_aspect' to value '1/1'
[graph 0 input from stream 0:0 @ 0xe98341e0] Setting 'sws_param' to value 'flags=2'
[graph 0 input from stream 0:0 @ 0xe98341e0] Setting 'frame_rate' to value '25/1'
[graph 0 input from stream 0:0 @ 0xe98341e0] w:1429 h:2160 pixfmt:yuvj420p tb:1/25 fr:25/1 sar:1/1 sws_param:flags=2
[format @ 0xe9834300] Setting 'pix_fmts' to value 'yuv420p|yuvj420p|yuv422p|yuvj422p|yuv444p|yuvj444p|nv12|nv16|nv21'
[AVFilterGraph @ 0xe9877140] query_formats: 6 queried, 5 merged, 0 already done, 0 delayed
[swscaler @ 0xe9557000] deprecated pixel format used, make sure you did set range correctly
[Parsed_scale_0 @ 0xe9834120] w:1429 h:2160 fmt:yuvj420p sar:1/1 -> w:1920 h:2902 fmt:yuv420p sar:2073479/2073600 flags:0x4
[libx264 @ 0xe9864180] using mv_range_thread = 120
[libx264 @ 0xe9864180] using SAR=1/1
[libx264 @ 0xe9864180] using cpu capabilities: ARMv6 NEON
[libx264 @ 0xe9864180] profile High, level 5.0
[libx264 @ 0xe9864180] 264 - core 152 r2851M ba24899 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - 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=12 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 '<FILE_URI>':
Metadata:
encoder         : Lavf58.12.100
Stream #0:0, 0, 1/16384: Video: h264 (libx264), 1 reference frame (avc1 / 0x31637661), yuv420p(center), 1920x2902 [SAR 2073479:2073600 DAR 1429:2160], 0/1, q=-1--1, 0.17 fps, 16384 tbn, 0.17 tbc
Metadata:
encoder         : Lavc58.18.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
Clipping frame in rate conversion by 0.000008
[libx264 @ 0xe9864180] using SAR=16199/16200
[libx264 @ 0xe9864180] using mv_range_thread = 120
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
Last message repeated 1 times
[out_0_0 @ 0xe98342a0] EOF on sink link out_0_0:default.
No more output streams to write to, finishing.
[libx264 @ 0xe9864180] using SAR=16199/16200
[libx264 @ 0xe9864180] using mv_range_thread = 120
[libx264 @ 0xe9864180] frame=   0 QP=14.07 NAL=3 Slice:I Poc:0   I:21840 P:0    SKIP:0    size=848649 bytes
frame=    1 fps=0.7 q=17.0 Lsize=     830kB time=00:00:00.00 bitrate=111496000.0kbits/s speed=4.35e-05x
video:829kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.096310%
Input file #0 (<FILE_URI>):
Input stream #0:0 (video): 1 packets read (562291 bytes); 1 frames decoded;
Total: 1 packets (562291 bytes) demuxed
Output file #0 (<FILE_URI>):
Output stream #0:0 (video): 1 frames encoded; 1 packets muxed (849339 bytes);
Total: 1 packets (849339 bytes) muxed
1 frames successfully decoded, 0 decoding errors
[AVIOContext @ 0xe9845180] Statistics: 2 seeks, 7 writeouts
[libx264 @ 0xe9864180] frame I:1     Avg QP:14.07  size:848649
[libx264 @ 0xe9864180] mb I  I16..4:  1.2% 85.6% 13.2%
[libx264 @ 0xe9864180] 8x8 transform intra:85.6%
[libx264 @ 0xe9864180] coded y,uvDC,uvAC intra: 99.4% 79.9% 64.7%
[libx264 @ 0xe9864180] i16 v,h,dc,p:  2%  2% 80% 16%
[libx264 @ 0xe9864180] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 11% 12% 31%  7%  9%  6%  7%  7%  9%
[libx264 @ 0xe9864180] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 20% 12% 11%  9% 12%  9%  9%  8%  9%
[libx264 @ 0xe9864180] i8c dc,h,v,p: 42% 33% 17%  8%
[libx264 @ 0xe9864180] kb/s:1131.53
[AVIOContext @ 0xe9845000] Statistics: 562291 bytes read, 0 seeks
Final video duration:    6000

答案1

旧版本的 VLC 无法处理低帧率 (< 6 fps) 视频。原生播放器可能也存在同样的问题。

使用

ffmpeg -loop 1 -framerate 6 -i <INPUT> -vf scale=1920:-2:force_original_aspect_ratio=decrease,format=yuv420p -c:v libx264 -t 6 <OUTPUT>

这将生成 6 fps 的视频,但由于时间压缩,文件大小可能会稍微小一些。

相关内容