Fixed bitrate on VideoWriter
This commit is contained in:
parent
a5d84e72af
commit
ff24be3154
2 changed files with 5 additions and 10 deletions
4
video.go
4
video.go
|
@ -29,7 +29,7 @@ func NewVideo(filename string) *Video {
|
||||||
}
|
}
|
||||||
// Execute ffmpeg -i command to get video information.
|
// Execute ffmpeg -i command to get video information.
|
||||||
cmd := exec.Command("ffmpeg", "-i", filename, "-")
|
cmd := exec.Command("ffmpeg", "-i", filename, "-")
|
||||||
// FFMPEG output piped to Stderr.
|
// ffmpeg output piped to Stderr.
|
||||||
pipe, err := cmd.StderrPipe()
|
pipe, err := cmd.StderrPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -47,7 +47,7 @@ func NewVideo(filename string) *Video {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cmd.Wait()
|
cmd.Wait()
|
||||||
video := &Video{filename: filename, channels: 3, pipe: nil, framebuffer: nil}
|
video := &Video{filename: filename, channels: 3}
|
||||||
parseFFMPEGHeader(video, string(buffer))
|
parseFFMPEGHeader(video, string(buffer))
|
||||||
return video
|
return video
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,6 @@ type VideoWriter struct {
|
||||||
filename string
|
filename string
|
||||||
width int
|
width int
|
||||||
height int
|
height int
|
||||||
channels int
|
|
||||||
bitrate int
|
bitrate int
|
||||||
fps float64
|
fps float64
|
||||||
codec string
|
codec string
|
||||||
|
@ -26,9 +25,6 @@ func NewVideoWriter(filename string, video *Video) *VideoWriter {
|
||||||
if video.width == 0 || video.height == 0 {
|
if video.width == 0 || video.height == 0 {
|
||||||
panic("Video width and height must be set.")
|
panic("Video width and height must be set.")
|
||||||
}
|
}
|
||||||
if video.channels == 0 {
|
|
||||||
video.channels = 3 // Default to RGB frames.
|
|
||||||
}
|
|
||||||
if video.fps == 0 {
|
if video.fps == 0 {
|
||||||
video.fps = 25 // Default to 25 FPS.
|
video.fps = 25 // Default to 25 FPS.
|
||||||
}
|
}
|
||||||
|
@ -36,7 +32,6 @@ func NewVideoWriter(filename string, video *Video) *VideoWriter {
|
||||||
filename: filename,
|
filename: filename,
|
||||||
width: video.width,
|
width: video.width,
|
||||||
height: video.height,
|
height: video.height,
|
||||||
channels: video.channels,
|
|
||||||
bitrate: video.bitrate,
|
bitrate: video.bitrate,
|
||||||
fps: video.fps,
|
fps: video.fps,
|
||||||
codec: "mpeg4",
|
codec: "mpeg4",
|
||||||
|
@ -55,11 +50,11 @@ func (writer *VideoWriter) initVideoWriter() {
|
||||||
"-vcodec", "rawvideo",
|
"-vcodec", "rawvideo",
|
||||||
"-s", fmt.Sprintf("%dx%d", writer.width, writer.height), // frame w x h
|
"-s", fmt.Sprintf("%dx%d", writer.width, writer.height), // frame w x h
|
||||||
"-pix_fmt", writer.pix_fmt,
|
"-pix_fmt", writer.pix_fmt,
|
||||||
//"-b:v", fmt.Sprintf("%d", writer.bitrate), // bitrate
|
|
||||||
"-r", fmt.Sprintf("%f", writer.fps), // frames per second
|
"-r", fmt.Sprintf("%f", writer.fps), // frames per second
|
||||||
"-i", "-", // The imput comes from stdin
|
"-i", "-", // The imput comes from stdin
|
||||||
"-an", // Tells FFMPEG not to expect any audio
|
"-an", // Tells ffmpeg not to expect any audio
|
||||||
"-vcodec", writer.codec,
|
"-vcodec", writer.codec,
|
||||||
|
"-b:v", fmt.Sprintf("%dk", writer.bitrate), // bitrate
|
||||||
writer.filename,
|
writer.filename,
|
||||||
)
|
)
|
||||||
writer.cmd = cmd
|
writer.cmd = cmd
|
||||||
|
@ -83,7 +78,7 @@ func (writer *VideoWriter) Write(frame []byte) {
|
||||||
for total < len(frame) {
|
for total < len(frame) {
|
||||||
n, err := (*writer.pipe).Write(frame[total:])
|
n, err := (*writer.pipe).Write(frame[total:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Likely cause is invalid parameters to FFMPEG.")
|
defer fmt.Println("Likely cause is invalid parameters to ffmpeg.")
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
total += n
|
total += n
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue