3

以下のサイトを参考にlibvideokit.soを作成して使用しようと考えています。 http://qiita.com/hayabon/items/3a0817b4443bd0e4c5af

実行コマンドに指定するファイルが無かった場合にアプリが落ちます。 これをアプリ側で捕捉して、「エラーが発生しました」と表示することは可能でしょうか?

アドバイスをよろしくお願い致します。

01-08 14:26:01.490: I/Videokit(14692): Initializing AV codecs
01-08 14:26:01.500: I/Videokit(14692): Splitting the commandline.
01-08 14:26:01.500: I/Videokit(14692): Reading option '-y' ...
01-08 14:26:01.500: I/Videokit(14692):  matched as option 'y' (overwrite output files) with argument '1'.
01-08 14:26:01.500: I/Videokit(14692): Reading option '-f' ...
01-08 14:26:01.500: I/Videokit(14692):  matched as option 'f' (force format) with argument 'image2'.
01-08 14:26:01.500: I/Videokit(14692): Reading option '-loop' ...
01-08 14:26:01.500: I/Videokit(14692):  matched as AVOption 'loop' with argument '1'.
01-08 14:26:01.500: I/Videokit(14692): Reading option '-i' ...
01-08 14:26:01.500: I/Videokit(14692):  matched as input file with argument '/data/data/com.example.img2video/files/movie_0001.jpg'.
01-08 14:26:01.500: I/Videokit(14692): Reading option '-vcodec' ...
01-08 14:26:01.500: I/Videokit(14692):  matched as option 'vcodec' (force video codec ('copy' to copy stream)) with argument 'mpeg4'.
01-08 14:26:01.500: I/Videokit(14692): Reading option '-t' ...
01-08 14:26:01.500: I/Videokit(14692):  matched as option 't' (record or transcode "duration" seconds of audio/video) with argument '3'.
01-08 14:26:01.500: I/Videokit(14692): Reading option '-r' ...
01-08 14:26:01.500: I/Videokit(14692):  matched as option 'r' (set frame rate (Hz value, fraction or abbreviation)) with argument '1'.
01-08 14:26:01.500: I/Videokit(14692): Reading option '-s' ...
01-08 14:26:01.500: I/Videokit(14692):  matched as option 's' (set frame size (WxH or abbreviation)) with argument '640x360'.
01-08 14:26:01.500: I/Videokit(14692): Reading option '-preset' ...
01-08 14:26:01.500: I/Videokit(14692):  matched as AVOption 'preset' with argument 'ultrafast'.
01-08 14:26:01.500: I/Videokit(14692): Reading option '-tune' ...
01-08 14:26:01.500: I/Videokit(14692):  matched as AVOption 'tune' with argument 'stillimage'.
01-08 14:26:01.500: I/Videokit(14692): Reading option '/data/data/com.example.img2video/files/1.mp4' ...
01-08 14:26:01.500: I/Videokit(14692):  matched as output file.
01-08 14:26:01.500: I/Videokit(14692): Finished splitting the commandline.
01-08 14:26:01.500: I/Videokit(14692): Parsing a group of options: global .
01-08 14:26:01.500: I/Videokit(14692): Applying option y (overwrite output files) with argument 1.
01-08 14:26:01.500: I/Videokit(14692): Successfully parsed a group of options.
01-08 14:26:01.500: I/Videokit(14692): Parsing a group of options: input file /data/data/com.example.img2video/files/movie_0001.jpg.
01-08 14:26:01.500: I/Videokit(14692): Applying option f (force format) with argument image2.
01-08 14:26:01.500: I/Videokit(14692): Successfully parsed a group of options.
01-08 14:26:01.500: E/Videokit(14692): /data/data/com.example.img2video/files/movie_0001.jpg: No such file or directory
01-08 14:26:01.500: E/Videokit(14692): Option loop not found.
01-08 14:26:01.510: A/libc(14692): Fatal signal 11 (SIGSEGV) at 0x00000018 (code=1), thread 14692 (ample.img2video)

2 件の回答 2

1

Videokit の void run() を使う代わりに ProcessBuilder を利用して ffmpeg を実行してみてはいかがでしょうか。

// ffmpeg 実行用のコマンド文字列を入れる
ProcessBuilder ffmpeg = new ProcessBuilder("ffmpeg", ...);
Process ffmpeg_process = ffmpeg.start();
ffmpeg_process.waitFor();
int exit_status = ffmpeg_process.exitValue();
if ( exit_status != 0 ) {
  // エラー処理
}

ffmpeg コマンドが異常終了する場合には必ず 0 以外の exit status を返す事が前提となります。

1

自アプリ側でファイル存在チェックを予め行うのが無難かと思います。

参考記事によればm4fg/android-ffmpeg-x264を利用しているとのことですが、JavaレイヤのAPI:void run(String args)を見る限り、FFmpegコマンドラインツールのJNIラッパーという雰囲気であり、しかも戻り値(void)も例外宣言(throws節)もないため成否すら返してこないようです。

0

この質問に回答するには、ログインする必要があります。

求めていた回答ではありませんか? のタグが付いた他の質問を参照する。