insert thumbnail into video

pull/166/head
xufulong 4 years ago
parent b72ffe65fc
commit 83f290f7d6
  1. 12
      app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.java
  2. 15
      app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java
  3. 7
      app/src/main/res/layout/activity_video_handle.xml
  4. 1
      app/src/main/res/values-en/strings.xml
  5. 1
      app/src/main/res/values/strings.xml

@ -132,7 +132,8 @@ public class VideoHandleActivity extends BaseActivity {
R.id.btn_pip,
R.id.btn_moov,
R.id.btn_speed,
R.id.btn_flv
R.id.btn_flv,
R.id.btn_thumbnail
);
}
@ -321,6 +322,15 @@ public class VideoHandleActivity extends BaseActivity {
String outputPath = PATH + File.separator + "frame_index.flv";
commandLine = FFmpegUtil.buildFlvIndex(srcFile, outputPath);
break;
case R.id.btn_thumbnail:// insert thumbnail into video
String thumbSuffix = FileUtil.getFileSuffix(srcFile);
if (thumbSuffix == null || thumbSuffix.isEmpty()) {
return;
}
String thumbnailPath = PATH + File.separator + "thumb.jpg";
String thumbVideoPath = PATH + File.separator + "thumbnailVideo" + thumbSuffix;
commandLine = FFmpegUtil.insertPicIntoVideo(srcFile, thumbnailPath, thumbVideoPath);
break;
default:
break;
}

@ -535,7 +535,7 @@ public class FFmpegUtil {
* Rebuild the keyframe index of FLV, make it seekable
* @param inputPath inputFile
* @param outputPath targetFile
* @return command of build flv index
* @return command of building flv index
*/
public static String[] buildFlvIndex(String inputPath, String outputPath) {
String buildIndex = "ffmpeg -i %s -flvflags add_keyframe_index %s";
@ -543,6 +543,19 @@ public class FFmpegUtil {
return buildIndex.split(" ");
}
/**
* Insert the picture into the header of video, which as a thumbnail
* @param inputPath inputFile
* @param picturePath the path of thumbnail
* @param outputPath targetFile
* @return command of inserting picture
*/
public static String[] insertPicIntoVideo(String inputPath, String picturePath, String outputPath) {
String buildIndex = "ffmpeg -i %s -i %s -map 0 -map 1 -c copy -c:v:1 png -disposition:v:1 attached_pic %s";
buildIndex = String.format(buildIndex, inputPath, picturePath, outputPath);
return buildIndex.split(" ");
}
/**
* Using one input file to push multi streams.
* After publish the streams, you could use VLC to play it

@ -135,6 +135,13 @@
android:layout_marginTop="4dp"
android:text="@string/video_flv"/>
<Button
android:id="@+id/btn_thumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:text="@string/video_thumbnail"/>
</LinearLayout>
</ScrollView>

@ -52,6 +52,7 @@
<string name="video_moov">MOOV move ahead</string>
<string name="video_speed">Playing speed</string>
<string name="video_flv">FLV index</string>
<string name="video_thumbnail">Insert thumbnail</string>
<string name="swap">Swap</string>
<string name="start">Start</string>

@ -52,6 +52,7 @@
<string name="video_moov">MOOV前移</string>
<string name="video_speed">播放倍率</string>
<string name="video_flv">FLV索引</string>
<string name="video_thumbnail">插入封面</string>
<string name="swap">切换</string>
<string name="start">开始</string>

Loading…
Cancel
Save