Android audio and video goes deep into 21 FFmpeg video cutting, androidffmpeg

Source: Internet
Author: User

Android audio and video goes deep into 21 FFmpeg video cutting, androidffmpeg

Video cutting I accidentally found that the code of the last video compression can run the FFmpeg video cutting command, but it cannot be used to merge videos, because you cannot read txt files that record the paths of several videos.

Here I will talk about the video cutting process, not the code, but the log. After all, I don't know where the code runs.

The last project address in the region
Https://github.com/979451341/FFmpegCompress

First, we need to modify the project code and change the parameters passed in by the runCommand function to the following:

                    int ret = FFmpegNativeBridge.runCommand(new String[]{"ffmpeg",                            "-ss", "00:00:00",                            "-t","00:00:10",                            "-i", et_input.getText().toString(),                            "-vcodec", "copy",                            "-acodec", "copy",                            et_output.getText().toString()});

The parsing command starts.

The start time of reading, that is, "00:00:00" after-ss. You can also write it as 0


03-10 14:19:55. 430 21706-22256/org. voiddog. ffmpeg D/TAG: Splitting the commandline.
03-10 14:19:55. 430 21706-22256/org. voiddog. ffmpeg D/TAG: Reading option '-ss '...
03-10 14:19:55. 431 21706-22256/org. voiddog. ffmpeg D/TAG: matched as option 'ss' (set the start time offset) with argument '00: 00: 00 '.

Read end time, that is, the time after-t. You can also write it as 10

03-10 14:19:55. 431 21706-22256/org. voiddog. ffmpeg D/TAG: Reading option '-t '...
03-10 14:19:55. 431 21706-22256/org. voiddog. ffmpeg D/TAG: matched as option 'T' (record or transcode "duration" seconds of audio/video) with argument '00: 00: 10 '.

Set the input video file to form a new video 10 seconds before the video file is cut.

03-10 14:19:55. 431 21706-22256/org. voiddog. ffmpeg D/TAG: Reading option '-I '...
03-10 14:19:55. 431 21706-22256/org. voiddog. ffmpeg D/TAG: matched as input url with argument '/storage/emulated/0/pauseRecordDemo/video/video.mp4 '.

Copy video streams

03-10 14:19:55. 431 21706-22256/org. voiddog. ffmpeg D/TAG: Reading option '-vcodec '...
03-10 14:19:55. 431 21706-22256/org. voiddog. ffmpeg D/TAG: matched as option 'vcodec' (force video codec ('copy' to copy stream) with argument 'copy '.

Copy audio streams

03-10 14:19:55. 431 21706-22256/org. voiddog. ffmpeg D/TAG: Reading option '-acodec '...
03-10 14:19:55. 431 21706-22256/org. voiddog. ffmpeg D/TAG: matched as option 'acodec' (force audio codec ('copy' to copy stream) with argument 'copy '.

Finally, select the output video file path.

03-10 14:19:55. 431 21706-22256/org. voiddog. ffmpeg D/TAG: Reading option '/storage/emulated/0/pauseRecordDemo/video/compress6.mp4 '...
03-10 14:19:55. 431 21706-22256/org. voiddog. ffmpeg D/TAG: matched as output url.
03-10 14:19:55. 431 21706-22256/org. voiddog. ffmpeg D/TAG: Finished splitting the commandline.
03-10 14:19:55. 431 21706-22256/org. voiddog. ffmpeg D/TAG: Parsing a group of options: global.
03-10 14:19:55. 431 21706-22256/org. voiddog. ffmpeg D/TAG: Successfully parsed a group of options.

Start creating and configuring output video files

03-10 14:19:55. 431 21706-22256/org. voiddog. ffmpeg D/TAG: Parsing a group of options: input url/storage/emulated/0/pauseRecordDemo/video/video.mp4.
03-10 14:19:55. 431 21706-22256/org. voiddog. ffmpeg D/TAG: Applying option ss (set the start time offset) with argument 00:00:00.
03-10 14:19:55. 431 21706-22256/org. voiddog. ffmpeg D/TAG: Applying option t (record or transcode "duration" seconds of audio/video) with argument 00:00:10.
03-10 14:19:55. 431 21706-22256/org. voiddog. ffmpeg D/TAG: Successfully parsed a group of options.

Open it

03-10 14:19:55. 431 21706-22256/org. voiddog. ffmpeg D/TAG: Opening an input file:/storage/emulated/0/pauseRecordDemo/video/video.mp4.
03-10 14:19:55. 431 21706-22256/org. voiddog. ffmpeg D/TAG: Opening '/storage/emulated/0/pauseRecordDemo/video/video.mp4' for reading
03-10 14:19:55. 431 21706-22256/org. voiddog. ffmpeg D/TAG: Setting default whitelist 'file, crypto'
03-10 14:19:55. 434 21706-22256/org. voiddog. ffmpeg D/TAG: Format mov, mp4, m4a, 3gp, 3g2, mj2 probed with size = 2048 and score = 100
03-10 14:19:55. 434 21706-22256/org. voiddog. ffmpeg D/TAG: ISO: File Type Major Brand: mp42

Parse the header of the output video file. I don't know what to use.

03-10 14:19:55. 441 21706-22256/org. voiddog. ffmpeg D/TAG: stts: 0 ctts: 7507, ctts_index: 0, ctts_count: 699
03-10 14:19:55. 441 21706-22256/org. voiddog. ffmpeg D/TAG: stts: 3753 ctts: 7507, ctts_index: 0, ctts_count: 699
03-10 14:19:55. 441 21706-22256/org. voiddog. ffmpeg D/TAG: stts: 7507 ctts: 7507, ctts_index: 0, ctts_count: 699
03-10 14:19:55. 441 21706-22256/org. voiddog. ffmpeg D/TAG: stts: 11260 ctts: 15015, ctts_index: 1, ctts_count: 699
03-10 14:19:55. 441 21706-22256/org. voiddog. ffmpeg D/TAG: stts: 15014 ctts: 7508, ctts_index: 2, ctts_count: 699







Obtains the encoder and the media format information of the input video file.

03-10 14:19:55. 600 21706-22256/org. voiddog. ffmpeg D/TAG: Parsing MediaFormat {image-data = java. nio. heapByteBuffer [pos = 0 lim = 104 cap = 104], mime = video/raw, crop-top = 0, crop-right = 1279, slice-height = 720, color-format = 21, height = 720, width = 1280, crop-bottom = 719, crop-left = 0, stride = 1280}
03-10 14:19:55. 601 21706-22256/org. voiddog. ffmpeg I/TAG: Output crop parameters top = 0 bottom = 719 left = 0 right = 1279, resulting dimensions width = 1280 height = 720
03-10 14:19:55. 601 21706-22256/org. voiddog. ffmpeg D/TAG: MediaCodec 0xe4998b40 started successfully
03-10 14:19:55. 601 21706-22256/org. voiddog. ffmpeg I/TAG: MediaCodec started successfully, ret = 0



Obtain the data of the input video file.


03-10 14:19:55. 643 21706-22256/org. voiddog. ffmpeg D/TAG: After avformat_find_stream_info () pos: 1343 bytes read: 93574 seeks: 2 frames: 4
03-10 14:19:55. 643 21706-22256/org. voiddog. ffmpeg I/TAG: Input #0, mov, mp4, m4a, 3gp, 3g2, mj2, from '/storage/emulated/0/pauseRecordDemo/video/video.mp4 ':
03-10 14:19:55. 643 21706-22256/org. voiddog. ffmpeg I/TAG: Metadata:
03-10 14:19:55. 643 21706-22256/org. voiddog. ffmpeg I/TAG: major_brand:
03-10 14:19:55. 643 21706-22256/org. voiddog. ffmpeg I/TAG: mp42
03-10 14:19:55. 644 21706-22256/org. voiddog. ffmpeg I/TAG: minor_version:
03-10 14:19:55. 644 21706-22256/org. voiddog. ffmpeg I/TAG: 512
03-10 14:19:55. 644 21706-22256/org. voiddog. ffmpeg I/TAG: compatible_brands:
03-10 14:19:55. 644 21706-22256/org. voiddog. ffmpeg I/TAG: isomiso2avc1mp41
03-10 14:19:55. 644 21706-22256/org. voiddog. ffmpeg I/TAG: encoder:
03-10 14:19:55. 644 21706-22256/org. voiddog. ffmpeg I/TAG: HandBrake 0.10.0 2014112200
03-10 14:19:55. 644 21706-22256/org. voiddog. ffmpeg I/TAG: Duration:
03-10 14:19:55. 644 21706-22256/org. voiddog. ffmpeg I/TAG: 00:00:31. 81
03-10 14:19:55. 644 21706-22256/org. voiddog. ffmpeg I/TAG:, start:
03-10 14:19:55. 644 21706-22256/org. voiddog. ffmpeg I/TAG: 0.083000
03-10 14:19:55. 644 21706-22256/org. voiddog. ffmpeg I/TAG:, bitrate:
03-10 14:19:55. 644 21706-22256/org. voiddog. ffmpeg I/TAG: 1878 kb/s
03-10 14:19:55. 644 21706-22256/org. voiddog. ffmpeg I/TAG: Stream #0: 0
03-10 14:19:55. 644 21706-22256/org. voiddog. ffmpeg I/TAG: (und)
03-10 14:19:55. 644 21706-22256/org. voiddog. ffmpeg D/TAG:, 3, 1/90000
03-10 14:19:55. 644 21706-22256/org. voiddog. ffmpeg I/TAG: Video: h264 (avc1/0x31637661), nv12, 1280x720,172 8 kb/s
03-10 14:19:55. 644 21706-22256/org. voiddog. ffmpeg I/TAG :,
03-10 14:19:55. 644 21706-22256/org. voiddog. ffmpeg I/TAG: 23.98 fps,
03-10 14:19:55. 644 21706-22256/org. voiddog. ffmpeg I/TAG: 23.98 tbr,
03-10 14:19:55. 644 21706-22256/org. voiddog. ffmpeg I/TAG: 90 k tbn,
03-10 14:19:55. 644 21706-22256/org. voiddog. ffmpeg I/TAG: 90 k tbc
03-10 14:19:55. 644 21706-22256/org. voiddog. ffmpeg I/TAG: (default)
03-10 14:19:55. 644 21706-22256/org. voiddog. ffmpeg I/TAG: Metadata:
03-10 14:19:55. 644 21706-22256/org. voiddog. ffmpeg I/TAG: handler_name:
03-10 14:19:55. 644 21706-22256/org. voiddog. ffmpeg I/TAG: VideoHandler
03-10 14:19:55. 644 21706-22256/org. voiddog. ffmpeg I/TAG: Stream #
03-10 14:19:55. 644 21706-22256/org. voiddog. ffmpeg I/TAG: (und)
03-10 14:19:55. 644 21706-22256/org. voiddog. ffmpeg D/TAG:, 1, 1/48000
03-10 14:19:55. 644 21706-22256/org. voiddog. ffmpeg I/TAG: Audio: aac (mp4a/0x6134706D), 48000Hz, stereo, fltp, 146 kb/s
03-10 14:19:55. 644 21706-22256/org. voiddog. ffmpeg I/TAG: (default)
03-10 14:19:55. 644 21706-22256/org. voiddog. ffmpeg I/TAG: Metadata:
03-10 14:19:55. 644 21706-22256/org. voiddog. ffmpeg I/TAG: handler_name:
03-10 14:19:55. 644 21706-22256/org. voiddog. ffmpeg I/TAG: Stereo
03-10 14:19:55. 644 21706-22256/org. voiddog. ffmpeg D/TAG: Successfully opened the file.



Configure the data of the output video file



03-10 14:19:55. 644 21706-22256/org. voiddog. ffmpeg D/TAG: Parsing a group of options: output url/storage/emulated/0/pauseRecordDemo/video/compress6.mp4.
03-10 14:19:55. 644 21706-22256/org. voiddog. ffmpeg D/TAG: Applying option vcodec (force video codec ('copy' to copy stream) with argument copy.
03-10 14:19:55. 644 21706-22256/org. voiddog. ffmpeg D/TAG: Applying option acodec (force audio codec ('copy' to copy stream) with argument copy.
03-10 14:19:55. 644 21706-22256/org. voiddog. ffmpeg D/TAG: Successfully parsed a group of options.
03-10 14:19:55. 644 21706-22256/org. voiddog. ffmpeg D/TAG: Opening an output file:/storage/emulated/0/pauseRecordDemo/video/compress6.mp4.
03-10 14:19:55. 648 21706-22256/org. voiddog. ffmpeg D/TAG: Setting default whitelist 'file, crypto'
03-10 14:19:55. 649 21706-22256/org. voiddog. ffmpeg D/TAG: Successfully opened the file.
03-10 14:19:55. 650 21706-22256/org. voiddog. ffmpeg I/TAG: Output #0, mp4, to '/storage/emulated/0/pauseRecordDemo/video/compress6.mp4 ':
03-10 14:19:55. 650 21706-22256/org. voiddog. ffmpeg I/TAG: Metadata:
03-10 14:19:55. 650 21706-22256/org. voiddog. ffmpeg I/TAG: major_brand:
03-10 14:19:55. 650 21706-22256/org. voiddog. ffmpeg I/TAG: mp42
03-10 14:19:55. 650 21706-22256/org. voiddog. ffmpeg I/TAG: minor_version:
03-10 14:19:55. 650 21706-22256/org. voiddog. ffmpeg I/TAG: 512
03-10 14:19:55. 650 21706-22256/org. voiddog. ffmpeg I/TAG: compatible_brands:
03-10 14:19:55. 650 21706-22256/org. voiddog. ffmpeg I/TAG: isomiso2avc1mp41
03-10 14:19:55. 650 21706-22256/org. voiddog. ffmpeg I/TAG: encoder:
03-10 14:19:55. 650 21706-22256/org. voiddog. ffmpeg I/TAG: Lavf57.73.100
03-10 14:19:55. 650 21706-22256/org. voiddog. ffmpeg I/TAG: Stream #0: 0
03-10 14:19:55. 650 21706-22256/org. voiddog. ffmpeg I/TAG: (und)
03-10 14:19:55. 650 21706-22256/org. voiddog. ffmpeg D/TAG:, 0, 1/90000
03-10 14:19:55. 650 21706-22256/org. voiddog. ffmpeg I/TAG: Video: h264 ([33] [0] [0] [0]/0x0021), nv12, 1280x720, q = 2-31,172 8 kb/s
03-10 14:19:55. 650 21706-22256/org. voiddog. ffmpeg I/TAG :,
03-10 14:19:55. 650 21706-22256/org. voiddog. ffmpeg I/TAG: 23.98 fps,
03-10 14:19:55. 650 21706-22256/org. voiddog. ffmpeg I/TAG: 23.98 tbr,
03-10 14:19:55. 650 21706-22256/org. voiddog. ffmpeg I/TAG: 90 k tbn,
03-10 14:19:55. 650 21706-22256/org. voiddog. ffmpeg I/TAG: 90 k tbc
03-10 14:19:55. 650 21706-22256/org. voiddog. ffmpeg I/TAG: (default)
03-10 14:19:55. 650 21706-22256/org. voiddog. ffmpeg I/TAG: Metadata:
03-10 14:19:55. 650 21706-22256/org. voiddog. ffmpeg I/TAG: handler_name:
03-10 14:19:55. 650 21706-22256/org. voiddog. ffmpeg I/TAG: VideoHandler
03-10 14:19:55. 650 21706-22256/org. voiddog. ffmpeg I/TAG: Stream #
03-10 14:19:55. 650 21706-22256/org. voiddog. ffmpeg I/TAG: (und)
03-10 14:19:55. 650 21706-22256/org. voiddog. ffmpeg D/TAG:, 0, 1/48000
03-10 14:19:55. 650 21706-22256/org. voiddog. ffmpeg I/TAG: Audio: aac ([64] [0] [0] [0]/0x0040), 48000Hz, stereo, fltp, 146 kb/s
03-10 14:19:55. 650 21706-22256/org. voiddog. ffmpeg I/TAG: (default)
03-10 14:19:55. 650 21706-22256/org. voiddog. ffmpeg I/TAG: Metadata:
03-10 14:19:55. 650 21706-22256/org. voiddog. ffmpeg I/TAG: handler_name:
03-10 14:19:55. 650 21706-22256/org. voiddog. ffmpeg I/TAG: Stereo



Copy the first 10 seconds of the audio/video stream of the input video file to the output video file.
It is clearly the most important part, but only this log


03-10 14:19:55. 650 21706-22256/org. voiddog. ffmpeg I/TAG: Stream mapping:
03-10 14:19:55. 650 21706-22256/org. voiddog. ffmpeg I/TAG: Stream #0: 0-> #0: 0
03-10 14:19:55. 650 21706-22256/org. voiddog. ffmpeg I/TAG: (copy)
03-10 14:19:55. 650 21706-22256/org. voiddog. ffmpeg I/TAG: Stream #-> #
03-10 14:19:55. 650 21706-22256/org. voiddog. ffmpeg I/TAG: (copy)
03-10 14:19:55. 650 21706-22256/org. voiddog. ffmpeg I/TAG: Press [q] to stop, [?] For help


Count the packages of the previously copied data


03-10 14:19:55. 725 21706-22256/org. voiddog. ffmpeg I/TAG: frame = 244 fps = 0.0 q =-1.0 Lsize = 2522kB time = 00:00:10. 06 bitrate = 2052.0 kbits/s speed = 136x
03-10 14:19:55. 725 21706-22256/org. voiddog. ffmpeg I/TAG: video: 2280kB audio: 233kB subtitle: 0kB other streams: 0kB global headers: 0kB muxing overhead:
03-10 14:19:55. 725 21706-22256/org. voiddog. ffmpeg I/TAG: 0.355927%
03-10 14:19:55. 725 21706-22256/org. voiddog. ffmpeg V/TAG: Input file #0 (/storage/emulated/0/pauseRecordDemo/video/video.mp4 ):
03-10 14:19:55. 725 21706-22256/org. voiddog. ffmpeg V/TAG: Input stream # (video ):
03-10 14:19:55. 725 21706-22256/org. voiddog. ffmpeg V/TAG: 245 packets read (2343932 bytes );
03-10 14:19:55. 725 21706-22256/org. voiddog. ffmpeg V/TAG: Input stream # (audio ):
03-10 14:19:55. 725 21706-22256/org. voiddog. ffmpeg V/TAG: 474 packets read (238991 bytes );
03-10 14:19:55. 725 21706-22256/org. voiddog. ffmpeg V/TAG: Total: 719 packets (2582923 bytes) demuxed
03-10 14:19:55. 725 21706-22256/org. voiddog. ffmpeg V/TAG: Output file #0 (/storage/emulated/0/pauseRecordDemo/video/compress6.mp4 ):
03-10 14:19:55. 725 21706-22256/org. voiddog. ffmpeg V/TAG: Output stream # (video ):
03-10 14:19:55. 725 21706-22256/org. voiddog. ffmpeg V/TAG: 244 packets muxed (2335158 bytes );
03-10 14:19:55. 725 21706-22256/org. voiddog. ffmpeg V/TAG: Output stream # (audio ):
03-10 14:19:55. 725 21706-22256/org. voiddog. ffmpeg V/TAG: 473 packets muxed (238407 bytes );
03-10 14:19:55. 725 21706-22256/org. voiddog. ffmpeg V/TAG: Total: 717 packets (2573565 bytes) muxed
03-10 14:19:55. 725 21706-22256/org. voiddog. ffmpeg D/TAG: 0 frames successfully decoded, 0 decoding errors
03-10 14:19:55. 725 21706-22256/org. voiddog. ffmpeg D/TAG: Statistics: 60 seeks, 764 writeouts
03-10 14:19:55. 725 21706-22256/org. voiddog. ffmpeg D/TAG: Statistics: 2662503 bytes read, 2 seeks


Effect


This compress6.mp4 is cut from video.mp4. video.mp4is 31 seconds, compress6.mp4 is 10 seconds, and their volume size is consistent with the time ratio.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.