Use QT and FFMPEG software to create video cropping tools

Source: Internet
Author: User

0 What is FFMPEG?

Libav(Old Name:FFmpegIs a free software that can run audio and video recording, transfer, and stream functions in multiple formats.[1], including libavcodec
-This is a decoder library for audio and video in multiple projects, and libavformat-a conversion library for audio and video formats.

In the old term "FFMPEG" of libav, "FF" indicates "Fast forward"[2]. Some new users wrote to the project owner of "FFMPEG" and asked if FF represents "fast ".
"Free" or "Fast Fourier", the project leader of "FFMPEG" replied, "just for the record, the original meaning of "FF" in FFmpeg is "Fast Forward "..."

Http://zh.wikipedia.org/wiki/Libav

 

 1. Download FFMPEG

Http://ffmpeg.zeranoe.com/

Http://ffmpeg.zeranoe.com/builds/ access

Download the FFMPEG windows release Edition

FFmpeg
Git-f514695 32-bit shared (latest)

 

2. Learn how to use FFMPEG in the command line

CD to go to the bin directory under the FFMPEG decompression directory

Ffmpeg.exe-I d:/source. Avi-vcodec copy-y-R 25-SS 8-T 971 D:/demo.mp4> D: \ clip_info.txt 2> & 1

 

Here-The vcodec copy parameter must be added, so that the video encoding mode will not be changed during cropping and the cropping speed will be very fast.

 

Overview of FFMPEG Parameters

Hyper fast Audio and Video Encoder

Usage: FFMPEG [Options] [[infile options]-I infile]... {[OUTFILE options] OUTFILE }...

Main options:
-L show license
-H Show Help
-? Show Help
-Help Show Help
-- Help show help
-Version show version
-Formats show available formats
-Codecs show available codecs
-BSFs show available bit stream Filters
-Protocols show available protocols
-Filters show available filters
-Pix_fmts show available pixel formats
-Sample_fmts show available audio sample formats
-Loglevel set libav * logging level
-V loglevel set libav * logging level
-Debug flags set debug flags
-Report generate a report
-Max_alloc bytes set maximum size of a single allocated Block
-F fmt force format
-I filename input file name
-Y overwrite output files
-N do not overwrite output files
-C codec name
-Codec name
-Pre preset name
-Map_metadata OUTFILE [, metadata]: infile [, metadata] Set metadata information of OUTFILE from infile
-T duration record or transcode "duration" seconds of audio/video
-Fs limit_size set the limit file size in bytes
-SS time_off set the Start Time Offset
-Itsoffset time_off set the input ts offset
-Itsscale scale set the input ts Scale
-Timestamp time set the recording timestamp ('now 'to set the current time)
-Metadata string = string add metadata
-Dframes number set the number of data frames to record
-Timelimit Limit Set max runtime in seconds
-Target type Specify target file type ("VCD", "SVCD", "DVD", "DV", "dv50", "Pal-VCD ", "NTSC-SVCD ",...)
-Xerror exit on Error
-Frames number set the number of frames to record
-Tag fourcc/Tag force codec tag/fourcc
-Filter filter_list set stream filterchain
-Stats print Progress Report During encoding
-Attach filename add an attachment to the output file
-Dump_attachment filename extract an attachment into a file
-BSF bitstream_filters a comma-separated list of bitstream Filters
-Dcodec codec Force Data codec ('copy' to copy Stream)

Advanced options:
-Map [-] input_file_id [: stream_specifier] [, sync_file_id [: stream_s set input stream Mapping
-Map_channel file. Stream. Channel [: syncfile. syncstream] map an audio channel from one stream to another
-Map_chapters input_file_index set chapters Mapping
-Benchmark add timings for benchmarking
-Dump each input Packet
-Hex when dumping packets, also dump the payload
-Re read input at native Frame Rate
-Loop_input deprecated, use-Loop
-Loop_output deprecated, use-Loop
-Vsync video sync Method
-Async audio Sync method
-Adrift_threshold threshold audio drift threshold
-Copyts copy timestamps
-Copytb source copy input stream time base when stream copying
-Shortest finish encoding within shortest Input
-Dts_delta_threshold threshold timestamp discontinuity Delta threshold
-Copyinkf copy initial non-keyframes
-Q use fixed quality scale (VBR)
-Qscale Q use fixed quality scale (VBR)
-Streamid streamindex: value set the value of an OUTFILE streamid
-Muxdelay seconds set the maximum Demux-Decode Delay
-Muxpreload seconds set the initial Demux-Decode Delay
-Fpre filename set options from indicated preset File

Video options:
-Vframes number set the number of video frames to record
-R rate set frame rate (HZ value, fraction or abbreviation)
-S size set frame size (WXH or abbreviation)
-Aspect set aspect ratio (, or 1.3333, 1.7777)
-Bits_per_raw_sample number set the number of bits per raw sample
-Croptop size removed, use the crop filter instead
-Cropbottom size removed, use the crop filter instead
-Cropleft size removed, use the crop filter instead
-Cropright size removed, use the crop filter instead
-Padtop size removed, use the pad filter instead
-Padbottom size removed, use the pad filter instead
-Padleft size removed, use the pad filter instead
-Padright size removed, use the pad filter instead
-Padcolor color removed, use the pad filter instead
-VN disable video
-Vcodec codec force video codec ('copy' to copy Stream)
-Sameq Use same quantizer as source (implies VBR)
-Same_quant Use same quantizer as source (implies VBR)
-Pass n select the pass number (1 or 2)
-Passlogfile prefix select two pass log file name prefix
-VF Filter list video Filters
-B bitrate video bitrate (Please use-B: V)
-DN disable data

 

3. Use qt4 as a simple graphical interface tool

 

 

Here we mainly use the qprocess class to call external programs.

Key code:

 

Qstring program = "D: \ maxview_video_demo \ FFMPEG \ ffmpeg-git-985e768-win64-static \ bin \ ffmpeg.exe ";
Qstring inputpath = UI-> videopathlineedit-> text ();
Qfile sourcefile (inputpath );
If (! Sourcefile. exists ()){
Qmessagebox: Information (this, qstring: fromutf8 ("prompt"), qstring: fromutf8 ("source file not found "));
Return;
}

Qstring outputpath = qfileinfo (sourcefile). absolutepath () + "/clip.mp4 ";

Qfile destfile (outputpath );
If (destfile. exists ()){
Destfile. Remove ();
}

Qstring starttime = UI-> videostarttimeedit-> time (). tostring ("HH: mm: SS ");
Qstring Len = UI-> videolengthtimeedit-> time (). tostring ("HH: mm: SS ");
Qstringlist arguments;
Arguments <"-I" <inputpath <"-R" <"25" <"-SS ";
Arguments <starttime <"-T" <Len <outputpath;

Qprocess * clipprocess = new qprocess (this );
Connect (clipprocess, signal (finished (INT), this, slot (clipvideofinished (INT )));

Clipprocess-> Start (Program, arguments );

 

After the video is intercepted, the process returns a finished (INT) signal and is captured by qprocess.

Clipvideofinished function to notify the program that video cropping is complete.

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.