如何在 android 上使用 ffmpeg 循环播放视频?
how does one loop a video using ffmpeg on android?
我正在使用 hiteshsondhi88 的 "FFmpeg Android Java" 库,它可以很好地进行缩放、转码和叠加。但是,当我尝试循环播放视频时,我只会在输出中得到相同的未循环播放的视频。
我的代码:
String internalPath = getFilesDir().getPath(); //get internal directory
String command = "-y -f concat -i "+internalPath+"/myList.txt -c copy "+internalPath+"/final.mp4";
ffmpeg.execute(command, ffmpegResponseHandler);
"myList.txt" 中的文本是通过编程生成的,但看起来像这样:
file 'final_unlooped.mp4' file 'final_unlooped.mp4' file 'final_unlooped.mp4' file 'final_unlooped.mp4' file 'final_unlooped.mp4'
最后,日志:
ffmpeg version n2.4.2 Copyright (c) 2000-2014 the FFmpeg developers
built on Oct 7 2014 15:11:41 with gcc 4.8 (GCC)
configuration: --target-os=linux --cross-prefix=/home/sb/Source-Code/ffmpeg-android/toolchain-android/bin/i686-linux-android- --arch=x86 --cpu=i686 --enable-runtime-cpudetect --sysroot=/home/sb/Source-Code/ffmpeg-android/toolchain-android/sysroot --enable-pic --enable-libx264 --enable-libass --enable-libfreetype --enable-libfribidi --enable-fontconfig --enable-pthreads --disable-debug --disable-ffserver --enable-version3 --enable-hardcoded-tables --disable-ffplay --disable-ffprobe --enable-gpl --enable-yasm --disable-doc --disable-shared --enable-static --pkg-config=/home/sb/Source-Code/ffmpeg-android/ffmpeg-pkg-config --prefix=/home/sb/Source-Code/ffmpeg-android/build/x86 --extra-cflags='-I/home/sb/Source-Code/ffmpeg-android/toolchain-android/include -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all -march=i686' --extra-ldflags='-L/home/sb/Source-Code/ffmpeg-android/toolchain-android/lib -Wl,-z,relro -Wl,-z,now -pie' --extra-libs='-lpng -lexpat -lm' --extra-cxxflags=
libavutil 54. 7.100 / 54. 7.100
libavcodec 56. 1.100 / 56. 1.100
libavformat 56. 4.101 / 56. 4.101
libavdevice 56. 0.100 / 56. 0.100
libavfilter 5. 1.100 / 5. 1.100
libswscale 3. 0.100 / 3. 0.100
libswresample 1. 1.100 / 1. 1.100
libpostproc 53. 0.100 / 53. 0.100
Input #0, concat, from '/data/data/com.testApp/files/myList.txt':
Duration: N/A, start: 0.000000, bitrate: 744 kb/s
Stream #0:0: Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x640, 744 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc
Output #0, mp4, to '/data/data/com.testApp/files/final.mp4':
Metadata:
encoder : Lavf56.4.101
Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 640x640, q=2-31, 744 kb/s, 25 fps, 12800 tbn, 12800 tbc
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
frame= 115 fps=0.0 q=-1.0 Lsize= 420kB time=00:00:04.48 bitrate= 768.1kbits/s
video:418kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.509634%
响应处理程序中的 OnSuccess() 方法启动,指示执行成功但输出仍未循环。
此命令在 Windows 上运行良好,但由于某些原因在 Android 上无法运行。关于它可能是什么的任何想法,或者我做错了什么?
我找到了问题。
原来我必须在 "myList.txt" 中的每个文件名后添加一个额外的行“/n”,这样它看起来像这样:
file 'final_unlooped.mp4'
file 'final_unlooped.mp4'
file 'final_unlooped.mp4'
...
而不是这个:
file 'final_unlooped.mp4' file 'final_unlooped.mp4' file 'final_unlooped.mp4' ...
我希望有人觉得这有用。
我正在使用 hiteshsondhi88 的 "FFmpeg Android Java" 库,它可以很好地进行缩放、转码和叠加。但是,当我尝试循环播放视频时,我只会在输出中得到相同的未循环播放的视频。
我的代码:
String internalPath = getFilesDir().getPath(); //get internal directory
String command = "-y -f concat -i "+internalPath+"/myList.txt -c copy "+internalPath+"/final.mp4";
ffmpeg.execute(command, ffmpegResponseHandler);
"myList.txt" 中的文本是通过编程生成的,但看起来像这样:
file 'final_unlooped.mp4' file 'final_unlooped.mp4' file 'final_unlooped.mp4' file 'final_unlooped.mp4' file 'final_unlooped.mp4'
最后,日志:
ffmpeg version n2.4.2 Copyright (c) 2000-2014 the FFmpeg developers
built on Oct 7 2014 15:11:41 with gcc 4.8 (GCC)
configuration: --target-os=linux --cross-prefix=/home/sb/Source-Code/ffmpeg-android/toolchain-android/bin/i686-linux-android- --arch=x86 --cpu=i686 --enable-runtime-cpudetect --sysroot=/home/sb/Source-Code/ffmpeg-android/toolchain-android/sysroot --enable-pic --enable-libx264 --enable-libass --enable-libfreetype --enable-libfribidi --enable-fontconfig --enable-pthreads --disable-debug --disable-ffserver --enable-version3 --enable-hardcoded-tables --disable-ffplay --disable-ffprobe --enable-gpl --enable-yasm --disable-doc --disable-shared --enable-static --pkg-config=/home/sb/Source-Code/ffmpeg-android/ffmpeg-pkg-config --prefix=/home/sb/Source-Code/ffmpeg-android/build/x86 --extra-cflags='-I/home/sb/Source-Code/ffmpeg-android/toolchain-android/include -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all -march=i686' --extra-ldflags='-L/home/sb/Source-Code/ffmpeg-android/toolchain-android/lib -Wl,-z,relro -Wl,-z,now -pie' --extra-libs='-lpng -lexpat -lm' --extra-cxxflags=
libavutil 54. 7.100 / 54. 7.100
libavcodec 56. 1.100 / 56. 1.100
libavformat 56. 4.101 / 56. 4.101
libavdevice 56. 0.100 / 56. 0.100
libavfilter 5. 1.100 / 5. 1.100
libswscale 3. 0.100 / 3. 0.100
libswresample 1. 1.100 / 1. 1.100
libpostproc 53. 0.100 / 53. 0.100
Input #0, concat, from '/data/data/com.testApp/files/myList.txt':
Duration: N/A, start: 0.000000, bitrate: 744 kb/s
Stream #0:0: Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x640, 744 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc
Output #0, mp4, to '/data/data/com.testApp/files/final.mp4':
Metadata:
encoder : Lavf56.4.101
Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 640x640, q=2-31, 744 kb/s, 25 fps, 12800 tbn, 12800 tbc
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
frame= 115 fps=0.0 q=-1.0 Lsize= 420kB time=00:00:04.48 bitrate= 768.1kbits/s
video:418kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.509634%
响应处理程序中的 OnSuccess() 方法启动,指示执行成功但输出仍未循环。
此命令在 Windows 上运行良好,但由于某些原因在 Android 上无法运行。关于它可能是什么的任何想法,或者我做错了什么?
我找到了问题。
原来我必须在 "myList.txt" 中的每个文件名后添加一个额外的行“/n”,这样它看起来像这样:
file 'final_unlooped.mp4'
file 'final_unlooped.mp4'
file 'final_unlooped.mp4'
...
而不是这个:
file 'final_unlooped.mp4' file 'final_unlooped.mp4' file 'final_unlooped.mp4' ...
我希望有人觉得这有用。