Newest 'ffmpeg' Questions - Stack Overflow
Les articles publiés sur le site
-
how to uplaod video and generate thumbnail with ffmpeg in codeigniter
11 février 2020, par Danish Laeeqi need to upload video with FFMPEG in codeigniter and save value to mysql database. and after uploading how do i get the duration of video and generates thumbnail from video and insert thumbnail path to mysql database here is my code for uploading video ....
public function uploadvideo() { $config['upload_path'] = "./admin_assets/videos/"; $config['allowed_types'] = "3gp|mp4|mpeg4|avi|flv"; $this->load->library('upload',$config); $uploadedby = $this->input->post('uploadedby'); $video_title = $this->input->post('video_title'); $privacy = $this->input->post('privacy'); $description = $this->input->post('description'); $vid_one_name= $this->upload->do_upload('video').$this->upload->data('file_name'); $file_size = $this->upload->data('file_size'); $fs = $file_size." kbytes"; $vid_one_path= substr($vid_one_name,1); $insert_video = $this->db->insert('videos',['uploadedby'=>$uploadedby,'video'=>$vid_one_path,'description'=>$description,'privacy'=>$privacy,'video_title'=>$video_title,'uploadDate'=>date('M-d-Y'),'file_size'=>$fs]); if ($insert_video) { return true; } else { return false; } }
it is working but i want to upload video using ffmpeg so that i can generate thumbnail from it and get the duration and other data..
-
Saving a continuous stream of images from ffmpeg image2pipe
11 février 2020, par MinaI am trying to save a sequence/continuous images from ffmpeg image2pipe in go. The problem with the code below that it does only save the first image in the stream due to the blocking nature of io.Copy since it waits for the reader or the writer to close.
package main import ( "fmt" "io" "log" "os" "os/exec" "strconv" "time" ) //Trying to get png from stdout pipe func main() { fmt.Println("Running the camera stream") ffmpegCmd := exec.Command("ffmpeg", "-loglevel", "quiet", "-y", "-rtsp_transport", "tcp", "-i", "rtsp://admin:123456@192.168.1.41:554/h264Preview_01_main", "-r", "1", "-f", "image2pipe", "pipe:1") ffmpegOut, err := ffmpegCmd.StdoutPipe() if err != nil { return } err = ffmpegCmd.Start() if err != nil { log.Fatal(err) } count := 0 for { count++ t := time.Now() fmt.Println("writing image" + strconv.Itoa(count)) filepath := "image-" + strconv.Itoa(count) + "-" + t.Format("20060102150405.png") out, err := os.Create(filepath) if err != nil { log.Fatal(err) } defer out.Close() _, err = io.Copy(out, ffmpegOut) if err != nil { log.Fatalf("unable to copy to file: %s", err.Error()) } } if err := ffmpegCmd.Wait(); err != nil { log.Fatal("Error while waiting:", err) } }
I implemented my own save and copy function based on the io.Copy code https://golang.org/src/io/io.go
func copyAndSave(w io.Writer, r io.Reader) error { buf := make([]byte, 1024, 1024) for { n, err := r.Read(buf[:]) if n == 0 { } if n > 0 { d := buf[:n] _, err := w.Write(d) if err != nil { return err } } if err != nil { return err } } return nil }
then I updated the for loop in my main function to the below block but still I am only getting the first image in the sequence. due to
r.Read(buf[:])
is being a blocking call.for { count++ t := time.Now() fmt.Println("writing image" + strconv.Itoa(count)) filepath := "image-" + strconv.Itoa(count) + "-" + t.Format("20060102150405.png") out, err := os.Create(filepath) if err != nil { log.Fatal(err) } defer out.Close() err = copyAndSave(out, ffmpegOut) if err != nil { if err == io.EOF { break } log.Fatalf("unable to copy to file: %s", err.Error()) break } }
-
OpenCV RTP-Stream with FFMPEG
11 février 2020, par BixileinI use OpenCV with ffmpeg (api-preference CAP_FFMPEG) to receive a RTP-Stream and show the video.
When I send a short video, the video is played as expected. But when I try to send a second video, the second one is not shown at all.
My code:
#include
#include opencv.hpp> #include highgui/highgui.hpp> #include using namespace std; using namespace cv; int main(int argc, char** argv) { cout << "--- OpenCV Verson: " << CV_VERSION << " ---" << endl; char env[] = "OPENCV_FFMPEG_CAPTURE_OPTIONS=protocol_whitelist;file,rtp,udp"; int rc = putenv(env); if (rc != 0){ cout << "Could not set environment variables\n" << endl; } VideoCapture cap; char input[] = "path/to/saved_sdp_file.sdp"; cap.open(input, CAP_FFMPEG); if(!cap.isOpened()) { cout << "Could not open Stream" << endl; return 1; } string windowName = "Test"; namedWindow(windowName, cv::WindowFlags::WINDOW_NORMAL); Mat frame; while(1){ cap >> frame; if (frame.empty()){ cout << "Application closed due to empty frame" << endl; return 1; } imshow(windowName, frame); int c = waitKey(1); if (c == 27){ break; } } cap.release(); destroyAllWindows(); return 0; } My .sdp file:
SDP: v=0 o=- 0 0 IN IP4 127.0.0.1 s=No Name c=IN IP4 127.0.0.1 t=0 0 m=video 6005 RTP/AVP 96 b=AS:132 a=rtpmap:96 H264/90000 a=fmtp:96 packetization-mode=1; sprop-parameter-sets=Z2QADazZQUH7ARAAAAMAEAAAAwPA8UKZYA==,aOvjyyLA; profile-level-id=64000D
The command to start the stream:
ffmpeg -re -thread_queue_size 4 -i video_file.mp4 -strict -2 -vcodec copy -an -f rtp rtp://192.168.20.98:6005
I tested streaming with ffplay. I use the following command:
ffplay -protocol_whitelist "file,rtp,udp" -i saved_sdp_test.sdp -reorder_queue_size 0
Everything seems to work and I can send and receive multiple videos. But I do not know how I could pass the
-reorder_queue_size
option in OpenCV.I know this would also be possible with gstreamer instead of ffmpeg. But there is a memory leak issue with the gstreamer-api in OpenCV (https://github.com/opencv/opencv/issues/5715) which I could not resolve.
Question
How can I use OpenCV with ffmpeg to receive multiple videos (consecutively) via rtp?
-
Ffmpeg adding watermark with qsv hardware acceleration optimize performance
11 février 2020, par KsilonI add text watermark on video with ffmpeg but i'm new with ffmpeg and try to optimize performance for this.
My test setup has i5-7500 and Intel HD 630. I tried this code to add watermark on video. If I do not set
-hwaccel_output_format
toyuv420p
ornv12
, it gives error.ffmpeg -threads 4 -hwaccel qsv -hwaccel_output_format yuv420p -i "input.mp4" -vf "drawtext=text='TEST':x=(W-tw)/2:y=(H-th)/2:fontfile=arial.ttf:fontsize=250:fontcolor=white@0.4:shadowcolor=black@0.4:shadowx=2:shadowy=2" -c:v h264_qsv "output.mp4"
When I run this code, Cpu usage 53% / fps = 90-95 / gpu_load(GPU-Z) = 35-38%
When I changed-threads 1
, Cpu usage 35% / fps = 68-72 / gpu_load(GPU-Z) = 28-30%Find
-async_depth
keyword on the Internet and tried it with5
but nothing happens or I used it wrong.How can use more gpu and less cpu for this operation?
-
Converting milliseconds to frame number (at 25 frames per second)
11 février 2020, par dusaHow can I convert milliseconds to frame number using python? I know the frame rate of the video (25 seconds per frame)
2683480 2684448